VIM
2018-06-27 - psic4t
GENERAL
- . repeats last command.
- select paragraph: vi} will select everything inside {}, vip will select a paragraph
- Prepend/apend on multiple lines: -:norm-
- gv re-select the previous region
- Delete to the next blank line: d}
OPEN FILES
- :bro[wse] ol[dfiles][!] - List file names as with :oldfiles, and then prompt for a number. When the number is valid that file from the list is edited. Use ! to abandon a modified buffer.
REGISTER
- "ayy copies line to register a
- "ap pastes register a
- :reg shows all registers
INDENT
- 5>> indents 5 lines
- 5% on curly braces indents text inside
- If you’re copying blocks of text around and need to align the indent of a block in its new location, use ]p instead of just p. This aligns the pasted block with the surrounding text.
- Indent whole file: gg, then =G
FIND/REPLACE
- Use / to find, cw to delete and insert new, n for next ocurrence, . to repeat.
- 10dk deletes 10 lines upwards, 10dj 10 lines downwards
- comment out lines quickly: First, CtrlV for visual block mode, select lines (or use 10j for 10 lines), I (capital i), add one #, ESC ESC, all lines are hashed.
- or use norm. Mark lines with v, :norm i#
- remove hash: Mark, :norm x
- fa to find the next occurrence of a, ; to repeat. ta to jump right before the next occurrence of a.
- jump to the corresponding tag (like { -> } ): %
MACROS
Press q then a character of your choice and it will start recording a
macro both in normal and insert mode so it's particularly useful for
doing repetitive stuff. Stop recording when finished by pressing q
again. I now cannot live without it. You call it with @
JUMPLIST
:g/
In its longer form:
:global/regular-expression/print
You can leave out the pattern/regex and Vim will re-use the previous search term.
Trivia: The grep tool was named after this command sequence.
PLUGINS
None. You don't need any.
COLORS
I'm using the great vim-railscasts theme