" From ~/_vimrc vim:filetype=vim: " AUTHOR: GPL(C) Mohsin Ahmed, http://www.cs.albany.edu/~mosh " Registers: " :disp Show yank regs " :reg registers, %=filename, " v'xy Yank region into register x. " "a5yy "A5yy -- yank 5 lines to reg a then append further 5. " iC-rx Inserts register x " iC-r% Insert current filename (also #). " Pull cword to a command line or search " - pull small register " [0-9a-z] pull named registers " : Last comand line into text. " / Last search string " "*yy Line to Clipboard is register *, paste with S-Insert. " "*p clipboard (reg *) paste, also on S-Insert. " :s/str/x/g Register to cmdline " :let @a=@_ : clear register a " :let @*=@a : copy register a to paste buffer " :map "qyy:let @q=@q."zzz" " Jumps Marks: " :jumps List jump in this file, " ^I ^O Jump to prev/next jumpers (list with :jumps). " :marks Show marks; Use `[A-Z] Upcase char to goto other files. " ma mark point with a, Use `a goto a. " `` exchange-mark-and-point " * find next word under-cursor. " # find prev word under-cursor. " 20% Goto 20% of file from start. " Buffers: " :ls :buffers list buffers. " :buf N then goto buffer N. " :bdel buffer delete " Regions: " v begin visual v-mode, region defined by marks '< and '>. " ^V begin visual-rectangle vr-mode, mark rectangle. " gv reselect visual-region. " o exchange mark and point. " d delete region. " v switch vr-mode to v-mode. " ^V switch v-mode to vr-mode. " J join region. " IStr String rect " ^T ^D indent/unindent in insert mode. " gqap format this para, or gq[cursor move], eg. gq}, gqG, gq`` " vGgq format to end of buffer " {Visual}gq format visual region " ^E/^Y for scrolling up/down. " z zz z- Scroll to top/center/bot (without changing cursor pos). " Automation: macros and scripting. " qx .. q Record actions to macro register x. " @x Replay macro register x. (now on zx and F2='replay macro x'). " Edit x 'xp (paste register x), Edit macro, 'xdd (macro back to register x). " $ vim -o file1 file2 -- open into a split " $ vim -c "/main" file.c " $ ls | gvim - -- edit the pipe! " $ vim -c "%s/old/new/ge | set ff=dos" makefile " $ vim -c "argdo %s/old/new/ge | update" *.c " $ vim -w "script.vim" file1.c # record script of keystrokes. " $ vim -s "script.vim" file2.c # replay script. " K -- Runs `$key_word_program word_under_cursor`. " :mkvimrc/mkexrc -- Make/Write options to file. " :scriptnames -- list scripts loaded. " Windows: See windows.txt " :buffers :split :new file " ^W s Split ^W q Quit ^W j Down Win ^W t Top Win " ^W o Only ^W c Close ^W k Up Win ^W b Bot Win " ^W n New ^W w Other Win ^W p Prev Win " ^W f New Win find file under-cursor. " ^W ] New Win find tag under-cursor. " ^W g ] New Win :tselect .. " vim -o files Open separate window for each file. " C PROGRAMMING: See tips.txt index.txt " gd goto local var defn of id under-cursor. " gD goto global var Defn of id under-cursor. " gf goto include file under-cursor, eg #include 'gf'. " g] choose from menu of matching tags for id under cursor. " :bdel go (b)ack original file, after 'gf'. " [i TYPEDEF word under-cursor. " [I List grep(id under-cursor, current file). " ]I List grep(id under-cursor, ,.$ current file). " [d find #define of id under-cursor in file and incs. " :checkpath verify inc files present. " :cl List errors, " vim -q error.txt, use :cn (next err), :cl (list err). " [/ ]/ goto prev/next comment /* */ " [# ]# goto prev/next PreProc #ifdef/#else/.. " [(,]),[{,]} goto prev/next umatched paren/brace. C-Left/Right. " 99[{ 99]} prev/next func, finds the start/end of the current function, " even when {} are not in the first column. " :ce,:ri,:le center, right,left justify. " C-x C-a inc/dec ++,-- (octal/hex/number) number under-cursor, 0x0b. " ga show ascii code of char under-cursor. " C-e/C-y copy and insert char above/below cursor. " Completion: see vim_diff.txt. " ^P/^N dynamic completion. " ^X completion menu. " ^K keyword completion from dictionary. " ^X menu of completion keys. " ^F file names. eg. ~/.em^X^F(^N/^P to chose file name)acs. " ^K words from $dictionary, eg. mos^X^K(^N/^P to chose)er. " ^D definitions or macros. " ^I words from included files. " ^L whole lines. " ^] words from the tags file. " " Color Xterm: see options.txt " t_ti Restore screen, " http://www.clark.net/pub/dickey/xterm/xterm.faq.html " -r /usr/share/lib/terminfo/x/xtermc " for builtin function list see eval.txt " Tags: see tagsearch.txt " ctags --file-tags=yes -R . -o etags -e " ctags --file-tags=yes -R . " vim -t main, or :tag main " C-] goto tag " C-t return from tag. " See: tag, pop, ptag, tnext, tprev, tlist, tjump, tselect, tselect /, stjump " " MsDev: " See sendtovim.exe, keyboard map, copy to clip " Customize,tools,=gvim=arg:="+/$(CurText) +$(CurLine) $(FilePath)" " Implicit final hence the colon. " =vi=sendtovim:arg=":cd $(FileDir):e $(FilePath)\ " :$(CurLine)/$(CurText)$(CurCol)|:" " =vt=sendtovim:arg=":cd $(FileDir):ta $(CurText)/$(CurText)" " =emacs.bat=emacs:arg=+$(CurLine) $(FilePath) " HKEY_CLASSES_ROOT\*\shell\Vim\command gvim.exe "%1" " vim60: vc: c:\bin32\gvim.exe, +$(CurLine) -c "-/$(CurText)" "$(FilePath)"; " vc: gvim.exe, -c ":ta $(CurText)" "$(FilePath)"; " Emacs: :emacs % .. launches emacs on current file. " Explorer: " see gui_w32.txt " HKEY_CLASSES_ROOT\*\shell\Vim Edit with &Vim " FileType: " see man assoc ftype, init/vim-asoc.bat " sh assoc.ksh .log vim " sh assoc.ksh .txt vim " sh ftype.ksh -c Edit vim "gvim.exe \"%1\"" " sh ftype.ksh -c Open vim "gvim.exe \"%1\"" " Abbrev: " :imap xx yy "Comment not ok. Dont use common prefixes for xx, slows down input. " mapping can move over \n, while h can't. " Time: " man co .. for many/ISO time formats, and man strftime for %Y... " Y=1999,m=08,d=22,H=24,M=60,Z=PDT,b=Aug,B=August,%a=Sun,%A=Sunday " GrepFind: " :!grep *.* > err.log " vim -q err.log .. Quickfix mode " See clist cprev cnext clist " " Filter: double_qouting perl args will hang sh call to perl.exe " :1,$! perl -pe 's,(\w+)/,\"$1 \".length($1),gex' .. Dont ask. " " Gcc: " gcc *.c 2>> errlog ; vim -q errlog " vim -q errlog " :copen " :source ~/vim/cnext.vim " :map :cprev " :map :cnext " " =================================================================== " TIP. zf to visit current file in other window " map zF gf:sp:e#w:f " map zf osgfw " TIP. misc " map m :%s/\+$// "Remove control-m .. USE s" " map q :mksession $PWD/session.vim! $PWD/session.vim:qa " map Q :so $PWD/session.vim " map U :%s,\(.*\),\1
,gc "Convert URLs to HTML" " TIP. Using Dictionary " imap :!cat $DICT \|egrep -i "" " map zd :!egrep -i "^^" $WORDS " map zd :execute 'r !perl.exe -ne \"print \\"/\^\\\b\\U\\E\\\b/\\";\" d:/x' " map zd :execute 'r !perl.exe -ne \"print if m/\\U\\E/;\" $DICT' " map zd :execute '/' . expand(""):sp $DICTn " map zd :execute 'r !perl.exe -ne \"print if m/"^"\\U\\E/;\" $DICT' " map zD :pclose " map zd :exe "silent pedit +/^" . toupper(expand("")) . " $DICT" " TIP. zs to cd to dir mentioned in file. " map zs ma?^cd \S\+\ " :execute getline(".")\ " :echo "cwd()="getcwd()" $PWD="$PWD`a " TIP. One click file pickup with f5. " map ma?^cd \S\+\ " :execute getline(".")\ " :echo "cwd()="getcwd()" $PWD="$PWD`agf\ " :sp # " TIP. highlights virtual 8 columns and 80+ overshoot. " /\%8v\|\%16v\|\%24v\|\%32v\|\%40v\|\%48v\|\%56v\|\%64v\|\%72v\|\%80v..* " TIP. list lines matching current line. " map :exe "g/^\M" . getline(".") . "$/" " TIP. map Lnz -- Search again from next page " TIP. :execute send-to-vim.ksh line? " TIP. 0"ay0 :g//y A -- Yank matching lines to reg 'a' " TIP. Reverse file :g/^/m0 " TIP. Copy matching lines to eof :g//t$ " TIP. Upcase line -- gUU, tolower line -- guu " TIP. " perl s//$reg/ vim:s/str/x/g " perl s///e vim:s/str/\=strftime("%c")/ " TIP. " output to file: a,'b g/^Error/ . w >> errors.txt " TIP. Operate command over multiple files: " :argdo %s/foo/bar/ " :bufdo %s/foo/bar/ " :windo %s/foo/bar/ " TIP. gvim -c "/$1" $(egrep -isl "$1" *) & -- Edit all files having $1. " -i case, -s suppress-error, -l only filenames. " TIP. Add menu entry " amenu Mosh.Insert\ a\ VIM\ modeline ggOvim:ff=unix ts=4 ss=4vim60:fdm=markergg " TIP. Save word under cursor to file " function! SaveWord() " normal yiw " exe ':!echo '.@0.' >> word.txt' " endfunction " map ,p :call SaveWord() " TIP. toggle two words " :%s/\<\(on\|off\)\>/\=strpart("offon", 3 * ("off" == submatch(0)), 3)/g "Junk from ~/_vimrc " set titlestring=%n,File=%R%m%<%F,%=Line=%l/%L=%P,Column=%v,Point=%o,Char=%b=0x%B " set titlestring=%n.%F,%f,%=Point=%o,Char=%b=0x%B " set titlelen=70 ":au BufReadPost quickfile silent ":map cprev:map cnext" "map cprev "map cnext " File explorer switches ... Using emacs dired as vim60 loses dired buffer. " let g:explVertical=1 " let g:explSplitRight=1 let g:explDetailedList=1 let g:explDateFormat="%Y-%b-%d %H:%M" " set errorformat=%f:%l:%m " See options.txt, \"0 to not save registers. " addr.txt has vim:ts=2:sw=2:ws:viminfo=: "au FocusLost * :let @* = @0 "au FocusLost * :wv "au FocusGained * :rv " Keys: and dont work in Console/GUI on NT. " map :bnext "imap :bnext " map :close "imap :close " map w "imap w EOF