Vim#
Notes about my editor of choice (including neovim).
Write Buffer to Stdout#
w !some_command
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!')
Fixing 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):
shortcut |
description |
---|---|
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 |
.. _nion’s blog: http://nion.modprobe.de/blog/archives/448-Folding-in-VIM.html
ftplugin vs. after/ftplugin#
All ftplugin
s are loaded when a buffer for the filetype is opened. Thus, it’s
lazy by default.
So here’s the order of writes. The last one wins:
$VIMRUNTIME/ftplugin/fortran.vim
~/.vim/ftplugin/fortran.vim
~/.vim/after/ftplugin/fortran.vim