Friday, 1 February 2008

Vim stuff

Vim is great, but quite hard to master. My experience is that there usually is a lot of "how did you do that?" when working with another vimmer. There goes a random list of some useful commands I taught (or learned) recently:

^rX in command and insert mode.
Puts the content of X register. Typical use case: select something with * and then :%s/^r//new stuff/g

punctuation: ; and ,
repeats last tTfF motion, like everyone's favourite dot repeats last command

rectangle visual mode
^v or quadruple1 click. Often easier and faster, than macros

macros
q. Everyone know them :help q

^o
Jumps intro normal mode for one command. Typical usecase: editing middle of the line ^oo.

^v any_key in insert and command mode
Puts the Vim representation for that key. Useful for editing .vimrc

J in normal mode
joins current line and next line

^a ^x in normal mode
increment/decrement a number

& and \1, \2...
in to part of substitution

"*
X11 clipboard

^p ^n and ^xlot_of_keys like ^xf
completions

autocmds in your .vimrc
see .vimrc examples below

not a command: Wombat
My text is brilliant
My vim is pure.
I saw a Wombat.
Of that I'm sure.
[...]

You're beautiful. You're beautiful.
You're beautiful, it's true.




Some macros from my .vimrc that I found very useful:

" done with current line
inoremap <c-cr> <c-o&ht;o

"XML, HTML, JSP
autocmd FileType xml,html,xhtml,jsp,htmldjango inoremap <C-b> <Esc>"tciw<<C-o>"tp><CR></<C-o>"tp><Esc>O
autocmd FileType xml,html,xhtml,jsp,htmldjango inoremap <C-a> <Esc>"tciw<></><Esc>"tPF>"tPla
autocmd FileType xml,html,xhtml,jsp,htmldjango inoremap <C-s> <ESC>"tciw</><ESC>h"tPa<Space><Space><Left>


Side note: python syntaxfile file (at least in vim 7.0 in my SuSE) seems to be a little outdated:
autocmd FileType python syn keyword Constant True False None
autocmd FileType python syn keyword Keyword with


Meta tip:
type :help one_or_two_random_keys from time to time. prefix with i_ for insert mode stuff.


1 - yes. QUAD-ruple. Click, click, click, click. Four clicks in a row %-| . Open Office does have quadruple click too. Who uses mouse, anyway...

2 comments:

Konrad said...
This comment has been removed by the author.
Konrad said...

Didn't realize this earlier, but I also use <Esc>o for the same thing as ^oo :)