====== VIM ======
===== Compilar VIM =====
Descargar de [[http://www.vim.org/download.php|Download]]
Descomprimir
./configure --with-features=huge --enable-multibyte --prefix=$HOME/local
make install
Eliminar luego directorio de fuentes
===== MAPPING =====
launching Win IE
nmap ,f :update
MAKE IT EASY TO UPDATE/RELOAD .vimrc
nmap ,s :source $VIM/.vimrc
nmap ,v :e $VIM/.vimrc
Pull word under cursor into LHS of a substitute
nmap
send output of previous global command to a new window
nmap
Pull word under cursor into LHS of a substitute
nmap
nmap ,t :s/.*/\L&/
Following 4 maps enable text transfer between VIM sessions
:map
allow use of F10 for mapping (win32)
set wak=no " :h winaltkeys
For use in Maps
type table,,, to get
imap ,,, bdwa<pa>pa>kA
list current mappings of all your function keys
:for i in range(1, 12) | execute("map ") | endfor [N]
get the original vim command on a mapped key [N]
unmap =
list current mappings of all your function keys
:for i in range(1, 12) | execute("map ") | endfor
Pull Visually Highlighted text into LHS of a substitute
:vmap z :%s/\<*\>/
insert date eg 31Jan11 [N]
:inoremap \zd =strftime("%d%b%y")
Titlise Visually Selected Text (map for .vimrc)
vmap ,c :s/\<\(.\)\(\k*\)\>/\u\1\L\2/g
Title Case A Line Or Selection (better)
vnoremap :s/\%V\<\(\w\)\(\w*\)\>/\u\1\L\2/ge [N]
titlise a line
nmap ,t :s/.*/\L&/:s/\<./\u&/g [N]
Pressing F5 lists all buffer, just type number
:map :ls:e #
Quick jumping between splits
map j_
map k_
running file thru an external program (eg php)
map :update:!c:/php/php.exe %
map :update:!perl -c %
visual shifting (builtin-repeat)
:vnoremap < >gv
Swap word with next word
nmap gw "_yiw:s/\(\%#\w\+\)\(\_W\+\)\(\w\+\)/\3\2\1/ [N]
pull full path name into paste buffer for attachment to email etc
nnoremap :let @*=expand("%:p") :unix
nnoremap :let @*=substitute(expand("%:p"), "/", "\\", "g") :win32
reproduce previous line word by word
imap ] @@@hhkyWjl?@@@P/@@@3s
nmap ] i@@@hhkyWjl?@@@P/@@@3s
Programming keys depending on file type
:autocmd bufenter *.tex map :!latex %
:autocmd bufenter *.tex map :!xdvi -hush %<.dvi&
macro to comment out a block of code using #if 0
vmap out "zdmzO#if 0"zp'zi#endif
visual searching
:vmap // y/" " search for visually highlighted text
with spec chars
:vmap
vimdiff /path/to/file scp://remotehost//path/to/file
vim -d file1 file2 " vimdiff (compare differences)
dp " "put" difference under cursor to other file
do " "get" difference under cursor from other file
[c " jump backwards to change
]c " jump forwards to change
:set diffopt+=icase " switch case sensitivity on and off
complex diff parts of same file [N]
:1,2yank a | 7,8yank b
===== Sorting =====
==== Sorting with internal sort ====
[range]sort - sort the lines in the [range], or all lines if [range] is not
given. e.g. '':'<,'>sort'' - sort the current visual selection
:'a,'b!sort -u " use an external program to filter content
!1} sort -u " sorts paragraph (note normal mode!!)
:sort /.*\%2v/ " sort all lines on second column [N]
==== Sorting with external sort ====
:%!sort -u " use an external program to filter content
:'a,'b!sort -u " use an external program to filter content
!1} sort -u " sorts paragraph (note normal mode!!)
:g/^$/;/^$/-1!sort " Sort each block (note the crucial ;)
:let @s=":%!sort -u "
:g/^$/;/^$/-1!sort " Sort each block (note the crucial ;)
===== Searching =====
==== searching over multiple lines \_ means including newline ====
/begin\_.*end " search over possible multiple lines
/ " search for multiple line comments
/fred\_s*joe/ " any whitespace including newline [C]
===== How to search for a URL without backslashing =====
?joe " (first) search BACKWARDS!!! clever huh!
/joe/e " cursor set to End of match
3/joe/e+1 " find 3rd joe cursor set to End of match plus 1 [C]
/joe/s-2 " cursor set to Start of match minus 2
/joe/+3 " find joe move cursor 3 lines down
/.*fred\&.*joe " Search for FRED AND JOE in any ORDER!
/\/ " search for fred but not alfred or frederick [C]
/\(^str.*\n\)\{2} " find 2 successive lines starting with str
[I " show lines matching word under cursor (super)
===== multiple file search =====
:bufdo /searchstr/ " use :rewind to recommence search
:bufdo %s/searchstr/&/gic " say n and then a to stop
===== Specify what you are NOT searching for (vowels) =====
/\c\v([^aeiou]&\a){4} " search for 4 consecutive consonants
/\%>20l\%<30lgoat " Search for goat between lines 20 and 30 [N]
/^.\{-}home.\{-}\zshome/e " match only the 2nd occurence in a line of "home" [N]
:%s/home.\{-}\zshome/alone " Substitute only the 2nd occurrence of home in any line [U]
===== find str but not on lines containing tongue =====
^\(.*tongue.*\)\@!.*nose.*$
\v^((tongue)@!.)*nose((tongue)@!.)*$
.*nose.*\&^\%(\%(tongue\)\@!.\)*$
:v/tongue/s/nose/&/gic
===== Substitute =====
==== Substitute range and search conditional ====
:'a,'bg/fred/s/dick/joe/igc " VERY USEFUL
==== substitute using a register ====
:s/fred/
:%s/^\n\{3}// " delete blocks of 3 empty lines
:%s/^\n\+/\r/ " compressing empty lines
:%s#<[^>]\+>##g " delete html tags, leave text (non-greedy)
:%s#<\_.\{-1,}>##g " delete html tags possibly multi-line (non-greedy)
:%s#.*\(\d\+hours\).*#\1# " Delete all but memorised string (\1) [N]
===== Deleting non-ascii characters (some invisible) =====
:%s/[\x00-\x1f\x80-\xff]/ /g " type this as you see it
:%s/[128-255]//gi " where you have to type the Control-V
:%s/[€-ÿ]//gi " Should see a black square & a dotted y
:%s/[128-25501-31]//gi " All pesky non-asciis
:exec "norm /[\x00-\x1f\x80-\xff]/" " same thing
===== parse xml/soap =====
%s#><\([^/]\)#>\r<\1#g " split jumbled up XML file into one tag per line [N]
%s#><\([^/]\)#>\r<\1#g " split jumbled up XML file into one tag per line [N]
%s/\r&/g " simple split of html/xml/soap [N]
:%s#<[^/]#\rgic " simple split of html/xml/soap but not closing tag [N]
:%s#<[^/]#\rgi " parse on open xml tag [N]
:%s#\[\d\+\]#\rg " parse on numbered array elements [1] [N]
ggVGgJ " rejoin XML without extra spaces (gJ) [N]
%s=\\n#\d=\r&=g " parse PHP error stack [N]
:%s#^[^\t]\+\t## " Delete up to and including first tab [N]
===== Copy a set of columns using VISUAL BLOCK (NOT BY ordinary v command) =====
:%s/goat\|cow/sheep/gc " ORing (must break pipe)
:'a,'bs#\[\|\]##g " remove [] from lines between markers a and b [N]
:%s/\v(.*\n){5}/&\r " insert a blank line every 5 lines [N]
===== Calling a VIM function =====
:s/__date__/\=strftime("%c")/ " insert datestring
===== format a mysql query =====
:%s#\\|\\|\\|\<\inner join\>#\rg
===== filter all form elements into paste register =====
:redir @*|sil exec 'g#<\(input\|select\|textarea\|/\=form\)\>#p'|redir END
:nmap ,z :redir @*
:g/joe/,/fred/d " not line based (very powerfull)
:g/fred/,/joe/j " Join Lines [N]
:g/-------/.-10,.d " Delete string & 10 previous lines
:g/{/ ,/}/- s/\n\+/\r/g " Delete empty lines but only between {...}
:v/\S/d " Delete empty lines (and blank lines ie whitespace)
:v/./,/./-j " compress empty lines
:g/^$/,/./-j " compress empty lines
:g/^/t. " duplicate every line
:g/fred/t$ " copy (transfer) lines matching fred to EOF
:g/stage/t'a " copy (transfer) lines matching stage to marker a (cannot use .) [C]
:g/^Chapter/t.|s/./-/g " Automatically underline selecting headings [N]
:g/\(^I[^^I]*\)\{80}/d " delete all lines containing at least 80 tabs
===== copy after line containing "otherstr" =====
:'a,'bg/somestr/co/otherstr/ " co(py) or mo(ve)
===== as above but also do a substitution =====
:'a,'bg/str1/s/str1/&&&/|mo/str2/
:%norm jdd " delete every other line
===== incrementing numbers (type
* # g* g# " find word under cursor () (forwards/backwards)
% " match brackets {}[]()
. " repeat last modification
@: " repeat last : command (then @@)
matchit.vim " % now matches tags