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 |
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.
SnippetManager#
:UltiSnipsEdit
Recording Macros#
It’s so easy, that it it is useful for even three lines in the same document. Suppose you are editing the following README file:
# entry 1
some text here
# entry 2
more text here
# entry 3
more text here
You want to change the format from entry 1
to Entry(id=1)
. Here’s what
I did:
navigate cursor to “entry”, then hit
*
(all highlighted, because of'hlsearch'
.)cwEntry(<ESC>n.n.
does the first part of the substitution, but we are missing the closing brackets- record
qq$a)<ESC>nq
record
q
to register q (simple to type, also valid would beqx
to record to register x)go to end of line, append the bracket, go back to normal mode and jump to next occurence
$a)<ESC>n
end recording
q
- record
- and play
@q@@
apply macro in register q
@q
repeat last macro
@@
- and play
Registers#
To yank a word to register a
type "ayw
.
Show all registers with :reg
and the register a
with :reg a
.
Paste register a
in command mode (:
) by hitting Control-r a.
https://vi.stackexchange.com/a/15038