At the last meeting we covered a few vim commands so people can expand their vim repertoire. Here are some quick notes from that presentation.
Simple Commands
- J - join lines
- o/O - insert line (before/After current line) and go into insert mode
- w/b - for next word/prev word
- dw - delete word
- d25w - delete 25 words
- :syntax on - turns on syntax highlighting (on some distros this is on by default)
Advanced: Recording
- qa - start recording to register 'a' (you can use any of a-z, must be a single letter)
- <type a bunch of commands>
- q - stop recording to register
- @a - repeat commands in register 'a' one time
- 10@a - repeat commands in register 'a' 10 times
Advanced: Find and Replace
:%s/badwrod/goodword/g
where:
- % is the range (% means entire file)
- / is the delimiter
- s is the replace command
- badwrod is a regular expression to match
- goodword is the replacement expression
- g is a modifier, telling vim to apply the replacement to all occurrences, not just one per line
More basic commands: Vim Cheat Sheet
More on macros: in vim type :help recording
More on find and replace: in vim type :help substitute
Cheers!
Darren