Vim

Notes about my editor of choice.

Sphinx ftplugin

I am very proud of my first vim plugin: sphinx.vim

For now, only creating and changing headings is mapped on the F1-F6 keys.

Wrapping a Python Function in a Vim function

Normally the following snippet would suffice:

fun! Vimfun()
    python pyfun()
endfun

But if you want to pass parameters, you’ll need something like this (please correct me if I’m wrong).

fun! Vimfun(x)
	python import vim
	python f(vim.eval(str('a:x')))
endfun

python << EOF
def f(x):
	print x
EOF

" run it
call Vimfun('Hello!')

Ugly Whitespace

To show all whitespace at line end:

:match Error /\s\+$/

To remove it:

:%s/\s\+$//

Folding

See also: :help usr_28. Set folding for XML (in .vimrc):

" XML syntax folding
let g:xml_syntax_folding=1
au FileType xml setlocal foldmethod=syntax

Shortcuts (from nion’s blog on 2009-03-23):

zf create folder
zd delete folder under cursor
zD delete folder recursive
zE delete all folders in file
zo open folder under curso
zO open folder recursive
zc close folder under cursor
zC same as zc recursive
za open folder if closed, close folder if opened

Templates

Want easy templates? See http://www.vim.org/scripts/script.php?script_id=2540!

Write Buffer to Stdout

w !some_command

File Explorer

NERDTree is the answer. Wanted it on the right, so I added a one-liner to my .vimrc:

let g:NERDTreeWinPos="right"

Beautiful.