I love vim. It’s not for everyone, but vim is heaven for people who do a lot of text manipulation. I love introducing people to vim and spitting out shortcuts that save a keystroke here and there. For a while, the cognitive cycles needed definitely outweigh the keystroke saved but over time, you’ll find your fingers moving without thinking.
The following are some vim tips I find useful that I’d like to share, assuming you have the basics down: h, j, k, l, w, e, b, 0, $, %, g, G, i, I, a, A, o, O, v, y, d, c, r, p, P, and so on.
Use f to move to a specific place in a line
To move to the second ‘w’ in this line (with your cursor at the start of the line), type fwfw
[vimdoc] moving to a character
Use tabs and splits
As important as learning to create splits and tabs is getting comfortable navigating between them.
[vimdoc] splitting windows
[vimdoc] tabpage
Mark your place
Let’s say you are working on one place of a long file and need to navigate to another place in the file, but eventually need to come back to the current location. Mark the current location by typing mm (m followed by any character) and move around the file at will. Once you’ve done your thing, type ‘m (replace m here with the character you chose before) to move your cursor back to where you marked before. This saves a lot of time as well as cognitive cycles.
[vimdoc] using marks
Get rid of the suck by recording commands
Ever find yourself repeating the same keystrokes over and over? Type qq. Do your keystrokes. Type q. Move to where you want the keystrokes repeated and type @q. Go ahead and try 10@q or even 100@q. If you choose your keystrokes carefully, your recorded commands can be quite adaptive.
[vimdoc] record and playback commands
:mksession
If you like gvim but get frustrated that screen doesn’t play nice, :mksession is your answer! Also, :mksession is great for reloading all the files you have open.
[vimdoc] sessions
Move the view with z
If you find your cursor at the top or bottom of the screen, just type zz or zt to scroll so that your cursor is at the middle and top of the screen respectively. This is useful when you search for a function name but the function ends up at the bottom of your viewport.
[vimdoc] scrolling around
Complete your word with ctrl-p
While in insert mode, press ctrl-p to complete a word that already appears in your open files. If there are multiple possibilities, vim lets you select the correct one from a dropdown.
[vimdoc] completing keywords from different sources
Pingback: What are some favorite Vim commands? - Quora