Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Becoming better at Vim [closed]

Tags:

vim

People also ask

How long does it take to get comfortable with vim?

You can learn to use vim in 30 minutes You won't be fast yet, no; but you'll be competent. And even after those 30 minutes, you're going to start grasping the ideas that make vim so amazing: the brilliant design decision that is modal editing, the composability of commands, the clever mnemonic naming of commands.

What countries are getting stuck in Vim?

It looks like developers in Ukraine, Turkey and Indonesia are getting stuck in Vim quite a bit: it makes up a larger portion of their Vim questions than in any other country. In contrast, in China, Korea and Japan the fraction going to this question is one-tenth as much.

How do I exit vim stack overflow?

If you find yourself trapped in Vim, you can usually exit by doing the following: press escape to enter “Master” mode. then type : to enter “Last Line” mode. then type q and hit enter.


"Why, oh WHY, do those #?@! nutheads use vi?" is a nice introduction to "the Vim way", especially about text objects which are one of the most defining features of Vim.


Here are some awesome screencasts that should give you an idea of what to learn next. There are also videos for intermediate and advanced topics, but the novice ones are in fact the most important.

Also, when I felt that I was stagnating and not really learning "the Vim way", I chose to disable arrow keys in both normal and insert mode. This forces you to use ESC to get somewhere, and makes you think more Vim-like. Ultimately, I enabled arrow keys again in insert mode, but I hardly ever use them. There is, most often, better ways to get around.

map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>

And especially

imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>

  1. type vimtutor on the command line
  2. go into vim, type :help or <F1>
  3. subscribe to mailing list
  4. official vim docs

Two more tips:

  • Use Vim for editing everything (email, web forms, code, ...). When something feels slow, there is probably a quicker way to do it. :helpgrep is your friend.

  • Head over to http://vimgolf.com/ and compete. I've learned many tips and tricks that way. [Disclaimer: No responsibility is accepted for the long periods of time that "go missing" while competing at VimGolf].


An interesting article by Bram Moolenaar himself: Seven habits of effective text editing.


This is how I've learned Vim (and a bunch of other things). It's pretty easy.

Browse the help documents and find a command for something you do all the time. Delete a whole word for example. Make it a point to remember this.

Now, the next time you find yourself hitting 'xxxxx' to delete a word, stop, put it back and use the new command. Look it up if you have to. So instead of hitting 'xxxxxx' you go back and hit 'dw'.

Do this over and over, it'll be slow at first but eventually it will stick.

Once you have that command down start at the top. Find another command for an action you do all the time...

You would be surprised how fast you can pick up new commands and techniques this way.


Remapping/disabling the arrow keys as has been suggested is a great way to force yourself not to use them.

Another thing to consider: if hitting Esc on your keyboard is at all uncomfortable you might wish to remap Caps Lock to Esc in your OS. For me this was a hugely helpful step, as Esc is an awkward reach on my KB and that was another obstacle that kept me in Insert mode (as it was hard to get out). Having Esc on Caps Lock makes it a tiny reach and jumping in and out of Insert mode is very fast.

For learning advanced stuff in Vim the best resource is the :help, but for getting the basics down you just need to do it; it's muscle memory more than anything. You say you know search. Consciously use it as a navigation tool. The searches [/, ?] and the inline char based searches [f, F, t, T] are some of the key Vim nav tools. Just use them; comboed with the disabled cursor keys you'll be navigating on muscle memory alone in no time.

Text Objects. Easily one of the best features of the editor. This is the other thing to immediately consciously practice. Things like 'yiw', 'dit', etc. are so powerful and fast; learning and making use of them alone will make you feel like a Vim user.

Once you've got text objects and basic navigation down, then it's time to move on to reading and learning from the :help regularly and scouring the web for awesome plugins. Seriously, you can use Vim for years and have an "ah ha!" moment accidentally stumbling on some obscure tidbit in the :help you'd never known.