
Best of Vim Tips - henrik_w
http://zzapper.co.uk/vimtips.html
======
cies
Let me add one Vim tip that recently got me:

[http://www.emacswiki.org/emacs/Evil](http://www.emacswiki.org/emacs/Evil)

Seriously, to me it solved all my issues with Vim. Now I have several
processes attached to my "Evil", heaps of plugins installed, yet everything
blazing fast. And the configuring in elisp started as a little awkward, but
now it feels so much more sensible then vim-script (especially knowing that
development on Emacs started ding the 70s).

With Evil I can say that --for me-- the Vim/Emacs fight is over:

Emacs now has a great editor...

...and Vim a proper "operating system".

:)

~~~
laichzeit0
Evil still lacks q: and q/ for command and search history editing. Really
pains me that they haven't implemented this yet. There's also nothing that
100% replaces the CtrlP plugin for Vim on Emacs.

~~~
leorocky
Yeah setting up fuzzy finding on emacs is a huge pain. It's not a hard problem
to solve, so maybe if I end up making more use of evil I'll try and write
something although elisp is not fun. I currently use helm, ido and projectile
and it only kind of works as good as cntrlP or command+T on textmate or
sublime text.

~~~
oahziur
I use Evil with emacs prelude now. Has more than enough features I need.

------
saosebastiao
I can't wait for neovim. The promise of a better scripting language, better
remote editing experience, better native GUI support on non-linux platforms,
and better IDE integration has me itching to try it out.

~~~
bla2
Vim has seen active development for over 20 years and is available almost
anywhere due to this. Reimplementations are announced every now and then but
usually fizzle out after a few years. We'll see how long neovim stays around.

(And the MacVim native Mac UI is pretty nice imho.)

~~~
doorhammer
I'm really stoked about neovim. I hadn't really thought about it, but it'd be
interesting to really go through all the substantial efforts to
fork/clone/refactor vim and compare/contrast their primary goals and vision
with neovim.

Might be fun to do some light reading on it tonight

------
hpvic03
Though I always like to learn more about Vim, there are way too many commands
in this list to call it a "Best of", and it seems that many of them are not
actually that useful.

~~~
jaredmcateer
Don't let this list intimidate you, Vim allows you to learn at your own pace,
I was mashing h,j,k, and l for years before I learned the beauty of grouping
movements (e.g., 12j instead of j 12 times). I try to learn one new thing a
week so I can commit it to muscle memory.

~~~
zachrose
It seems like so much of power vim use is about jumping 3 characters ahead or
12 lines down.

Is this for real? Do you count the number of lines or characters before you
move? Do you look at line numbers and do the arithmetic in your head? This
can't be right, right?

~~~
Cakez0r
It's more about "semantic editing" than memorizing arcane keybinds. With Vim,
you describe what you want to do with actions and motions. Motions move the
cursor from a starting point to an end point and then actions do something
with everything between the start and the end.

For example, if you want to delete 3 words, there is an action to delete (d)
and a motion to move forward one word (w): 3dw (read (3) times, (d)elete
(w)ord)

If you want to delete everything up to a closing bracket, there's a motion to
move to the next occurrence of a character (t): dt) (read (d)elete (t)o ')')

It becomes much more productive when you're thinking in terms of composing
actions and motions to achieve a goal rather than memorizing situational key
combos. The hardest part is getting over the hump of memorising the actions
and motions.

Relative line numbers aren't even too important, given that there is a motion
to jump to a line number. If you have a function that you can see starts at
line 6 and ends at line 14 and I want to move it to the top of the file. You
want to go to line 6 (6G), delete (d), go to line 14 (14G - thus applying the
delete action to the motion of moving from line 6 to line 14) then go to line
1 (1G) and paste (P).

~~~
jsbgir
> For example, if you want to delete 3 words, there is an action to delete (d)
> and a motion to move forward one word (w): 3dw (read (3) times, (d)elete
> (w)ord)

I prefer to use d3w since it feels more like English. It's also more
compatible with other combinations like ci" ('change inside quotes', e.g. to
change a string), ca" ('change around quotes', e.g. to replace a string with a
constant), or yt{ ('yank to brace').

------
pcsanwald
I love pages like this because this is how the internet used to be. weirder.

~~~
5h
s/used/should/

It's nice to not "read more after the jump" or "below the fold", no over-
pagination, no 100% width 400px deep semi-relevant banner image, no pull
quotes in 30px ultra-bold fonts floated over to the sides, no "you may also be
interested in" and no asinine comments, .. oh, wait!

~~~
w0ts0n
I disagree. This is way to much information for me to digest. I think a happy
medium is nice. Enough information on the screen to get the point across but
not too little that I have to click everything to find out what I need.

~~~
5h
Of course I'm exaggerating, and I agree this page isn't particularly friendly
but nor is it intended to be, its a reference to be searched rather than a
piece of prose to be read.

A lot of pages I find frustrating are often trying to spin a narrative around
what amounts to reference material, or vice-versa & results are often framed
with the tropes I mentioned above.

~~~
dllthomas
It seems like those could even be two different views into the same material,
potentially.

------
stonemetal
_: 'a,'bg/fred/s/dick/joe/igc : VERY USEFUL_

Wow, thanks for the tip, any ideas on what it does?

A lot of these seem to be learn to use regular expressions and not really vim
related other than vim supports regular expressions. I.E. the 4 or 5 different
ways to find an exactly 4 digit number that mostly seem to boil down to '/'
does search by regular expressions and here is a regular expression that finds
4 digit numbers.

~~~
achal
> 'a,'b

Between mark `a' and `b'

> g/fred

If the line contains the pattern Fred, execute the following command
(s/dick/joe/igc)

> s/dick/joe/

Replace dick with joe

> /igc

i: Case insensitive

g: Replace multiple occurrences on the same line

c: Ask for confirmation on each substitution

I may be wrong about some detail, but I believe that's it.

------
snarfy
If you use Vim with C#, you should check out the Omnisharp plugin:

[https://github.com/nosami/Omnisharp](https://github.com/nosami/Omnisharp)

It provides intellisense, find-usages, and other features.

~~~
mikewhy
Also YouCompleteMe[0], which uses Omnisharp for C# and Jedi for Python. It has
recently been refactored into a standalone server that talks to the editor
plugin, so we may see this in other editors.

[0]:
[https://github.com/Valloric/YouCompleteMe](https://github.com/Valloric/YouCompleteMe)

~~~
Yuioup
No official Windows support :-(

------
arjunrc
I've been using vim for the last 2 years, and I love HN for posts like these,
with all a-ha's in one page. Considerably reduces time necessary to become a
vi master.

------
daniel-levin
These sort of tips are only useful in highly specific cases. It's probably not
worth learning them off by heart because of how infrequently you'll end up
using them. BUT, understanding how the author(s) came up with these is
incredibly powerful. The combinatorial explosion of the composition of Vim
features means that it's practically impossible to learn all of the commands.

That said, it's really beneficial to learn how to form these commands
yourself. For instance, if you know regexes, a good chunk of the commands
presented would be relatively easy to come up with yourself. Is it worth
learning regexes, Vim shortcuts (basically a lot of arcane things)? Maybe,
maybe not. If you spend (or plan on spending) a huge amount of time
manipulating text files it's probably worthwhile. For me at least, it's much
more satisfying to do most text manipulations (e.g. remove trailing
whitespace) by running a concise command, than doing it manually.

For what it's worth, it's even _fun_ to sit and think of how you can avoid
doing some manual task. Vim shortcuts + regexes are a really good way of
avoiding silly work.

------
andrey-p
Some useful tricks in there.

Also, this:

    
    
      ggVGg?                          : rot13 whole file (toggles)
    

So g?<motion> applies ROT13 to text. But... why?

Edit: Make that "a couple of useful tricks in there". These are the ones I can
actually see myself using:

    
    
      @@     last recording
      @:     last command-mode command

~~~
skymt
At a guess: the old-fashioned Unix way of composing mail and Usenet messages
is to have your client call your editor. Rot13 was (is?) common in Usenet
discussions of fiction to avoid posting spoilers where anyone can accidentally
read them. It's not something you would use when editing source code.

~~~
dllthomas
_" old-fashioned Unix way of composing mail and Usenet messages is to have
your client call your editor"_

Some of us still do that. I <3 nmh.

~~~
voltagex_
What's nmh?

I must admit to setting $EDITOR to nano for mutt.

~~~
dllthomas
nmh is a mail client that is decomposed into a bunch of shell utilities,
storing state and messages in files. It's a bit awkward trying to use it
directly, but easy to wrap things you do commonly in aliases/functions.
Editing of messages, of course, takes place in your $EDITOR, but listing of
messages, selecting of messages, &c, doesn't leave your shell like it does
with mutt (so you can use the pieces as part of arbitrary pipelines, as is
good and proper).

------
drikerf
For me, just using NERDTree and ctrl-p combined with basic skills from the
tutorial made me love vim :)

------
dave1010uk
I love Vim but never use it. 99% of the time I'm editing code in an IDE that
knows about the language semanticly and knows how to refactor
(extract/move/rename) code. It would be incredible if Vim/Neovim had a plugin
that could do the same refactorings as IntelliJ.

At the moment the ease and frictionlessness of refactoring like this (instead
of manually moving text objects around) beats Vim's productivity gains. It's a
shame because I still often think in terms like "ci(" when using an IDE.

I've tried Vim emulators in IDEs (not recently, mind) but they're not the
same.

Anyone have any suggestions to get the best of both worlds?

~~~
danielbarla
I'm a relatively happy user of Vim emulators in IDEs (mostly in VS / IntelliJ
/ Eclipse); e.g. I might do a cw / ciw / ct[first letter of next word in
variable name] and then hit the IDE's shortcut for rename refactoring. Simple
macros for tedious repetitive tasks. For this, I find emulators sufficient, a
kind of "best of both worlds".

I suspect my usage of Vim itself is fairly basic, making this workable. What
issues did you find with this approach?

------
bfwi
I really like vim and use it every day, but I'm honestly never going to commit
all this to memory.

~~~
beachstartup
in unix, you memorize by doing, not by studying

~~~
saganus
I would actually venture to say that it does not apply only to Unix but for
life itself, no?

------
buster
Sort of let's me wonder, why anybody would want to learn all those. I use vim
regularly, but to be honest, for 90% of tasks i would be just as efficient
with pico or mcedit.

I guess i am using vim only because it is most often available on 3rd party
systems and because of the occasional need for those last 10%.

And to be honest, i used to use vim on the desktop for some time, but now we
have this variety of options.. from fast loading textadept, gedit, sublime
text3 to full-blown IntelliJ.. Why vim? Because it's "cool"? Feels more like
ancient and antiquated.

Nice list though, it's bookmarked for those 10%! :)

~~~
zecho
It's useful to see how others apply vim's grammar in interesting ways. To me,
it's like seeing a new design pattern. Not necessarily immediately useful, but
a maybe a new way to think about something I may not already know.

~~~
pasbesoin
That's the way I approach some lists like this one. Specific examples can help
one to in turn better learn and generalize certain abilities/behaviours.

I'll also add: So, one person puts up a long-ish page of examples. Is there
anything inherently _wrong_ with this? Presumably, it's useful to them and
perhaps to some others. Doesn't that suffice -- it's the Internet!

Not every page needs to be carefully curated for global karma-whoring.

------
wunderlust
I hope I never have to use (most of) those.

------
blacktulip
As a VIM user I am overwhelmed by this tips webpage which, despite in small
font, requires 16 page downs to reach the end. "Just use Sublime Text"[0]

[0]: [http://delvarworld.github.io/blog/2013/03/16/just-use-
sublim...](http://delvarworld.github.io/blog/2013/03/16/just-use-sublime-
text/)

~~~
edwintorok
I don't get it why someone would use a closed source tool to create open-
source programs. Or why you'd use a closed-source tool for something as
fundamental as editing a file.

~~~
akerl_
While I enjoy using open source software on principle, in practice I care way
more about usability and feature set. I understand that some people make a
conscious choice to only use free and/or opensource software, but it's flawed
to claim closed-source software is somehow unfit to operate, especially based
on the "fundamental"ness of the desired action.

~~~
doorhammer
I agree.

As far as a business case goes, there's no real "vendor lock in" with a
plaintext editor like this. You can always switch to something else and your
files will be fine/the same. You're investing (potentially non trivial) time
to learn using it, but it didn't take me long to learn ST2 to a depth that
made it really handy.

I will say I'd buy a lot more into that argument for people who develop
plugins.

That said I can respect the "open source" only mindset. I'm just not sure I'm
that concerned about it in this particular case.

~~~
edwintorok
I don't know whats the lifetime of these "trendy" closed-source tools since I
was never a fan of them, I'd be worried that you loose more time by having to
switch to a new tool each month. Exploring alternatives is nice, but you can't
be doing that all the time.

For example there was a time when I switched a Linux distribution each month,
then at some point I realized that it is getting me nowhere: I didn't know
either of them in-depth or how to deal with their specific problems. So then I
made a choice: I'll use only Debian, and actually _learn_ about how to deal
with problems when I encounter them, instead of jumping ship to another
distro.

Its the same with text editors, I eventually settled on Vim (for a long time
without any plugins), then started using plugins as well.

Sure every now and then I check what new alternatives are out there (for
example there are some interesting ideas in
[http://leoeditor.com/](http://leoeditor.com/) but not really comparable to
Vim), but closed-source tools are never on my list. I only ever heard about
Sublime Text here on HN, and even then for a long time I thought its a Mac
only tool.

But with closed-source tools I just wouldn't have been motivated to stick with
any of them: if there were problems with it then I wouldn't know how to work
them around, or implement missing functionality, not to mention I wouldn't
trust them to begin with etc.

~~~
doorhammer
ST has been out for six years. That's not going to be comparable to emacs (mid
1970's - now) or vi/vim (1976/1991 respectively). I haven't jumped on Atom, or
any of the other brand new editors because I want to know they'll have some
staying power, but I don't think 5+ years is short enough for me to be
concerned. I'm certainly not changing editors every month. I also do most of
my editor exploration in my free time, and it's fun for me, so it's not really
a waste of time (again, for me, in that context).

I should say that I can't really settle on VIM right now because I'm doing
full time .net work at this point. I still use it reasonably often when I'm
mucking about in C at home, and I used it as my primary editor for at least
five years prior to that, but my use-case was me trying to get a decent
haskell environment up and running on a fresh linux VM as quickly as I could.
ST2 worked really well for that.

