ÿ¸öÏëÉîÈëѧϰ Vim Óû§¶¼»áÈÏÕæÔĶÁµÄÎÄÕ£¬¹ÙÍøÁ´½Ó£º
http://www.rayninfo.co.uk/vimtips.html
ÕâÆªÎÄÕ±»ºÜ¶àÈË·Òë¹ý£¬µ«ÄÇÊǶ¼ºÜÔçÁË£¬ËùÔÚÔÀ´µÄһϵÁзÒëµÄ»ù´¡ÉÏÐÞÕýÔÀ´·ÒëÇ·Í׵쬴íÎóµÄ£¬ÒÔ¼°½üÁ½Äê¸üеÄÄÚÈÝ¡£
__BEGIN__
------------------------------------------------------------------------------
# searching ²éÕÒ
/joe/e : cursor set to End of match
°Ñ¹â±ê¶¨Î»ÔÚÆ¥Åäµ¥´Ê×îºóÒ»¸ö×Öĸ´¦
/joe/e+1 : cursor set to End of match plus 1
°Ñ¹â±ê¶¨Î»ÔÚÆ¥Åäµ¥´Ê×îºóÒ»¸ö×ÖĸµÄÏÂÒ»¸ö×Öĸ´¦
/joe/s-2 : cursor set to Start of match minus 2
°Ñ¹â±ê¶¨Î»ÔÚÆ¥Åäµ¥´ÊµÚÒ»¸ö×ÖĸÍùǰÊýÁ½¸ö×ÖĸµÄλÖÃ
/^joe.*fred.*bill/ : normal
±ê×¼µÄÕýÔò±í´ïʽ
/^[A-J]\+/ : search for lines beginning with one or more A-J
²éÕÒÒÔÒ»¸ö»ò¶à¸ö A-J ÖеÄ×Öĸ¿ªÍ·µÄÐÐ
/begin\_.*end : search over possible multiple lines
²éÕÒÔÚ begin ºÍ end Á½¸öµ¥´ÊÖ®¼ä¾¡¿ÉÄܶàµÄÐÐ
/fred\_s*joe/i : any whitespace including newline
²éÕÒÔÚ fred ºÍ joe Á½¸öµ¥´ÊÖ®¼äÈÎÒâ¶àµÄ¿Õ¸ñ£¬°üÀ¨ÐÂÐÐ
/fred\|joe : Search for FRED OR JOE
²éÕÒ fred »ò joe
/\([^0-9]\|^\)%.*% : Search for absence of a digit or beginning of line
²éÕÒ
/.*fred\&.*joe : Search for FRED AND JOE in any ORDER!
²éÕÒͬʱ°üº¬ FRED ºÍ JOE µÄÐУ¬²»·Öǰºó˳Ðò
/\<fred\>/i : search for fred but not alfred or frederick
²éÕÒ fred, ¶ø²»ÊÇ alfred »òÕß frederick£¬Ò²¾ÍÊÇÈ«×ÖÆ¥Åä
/\<\d\d\d\d\> : Search for exactly 4 digit numbers
²éÕÒ4¸öÊý×ÖµÄÈ«×ÖÆ¥Åä
/\D\d\d\d\d\D : Search for exactly 4 digit numbers
²éÕÒ4¸öÊý×ÖµÄÈ«×ÖÆ¥Åä
/\<\d\{4}\> : same thing
ͬÉÏ
# finding empty lines ²éÕÒ¿ÕÐÐ
/^\n\{3} : find 3 empty lines
²éÕÒ 3 ÐпÕÐÐ
# Specify what you are NOT searching for (vowels)
# Ö¸¶¨²»Òª²éÕÒʲô
/\c\v([^aeiou]&\a){4} : search for 4 consecutive consanants
# using rexexp memory in a search
# ÔÚ²éÕÒÖÐʹÓÃÕýÔò±í´ïʽ´æ´¢
/\(fred\).*\(joe\).*\2.*\1
# Repeating the Regexp (rather than what the Regexp finds)
# ÖØ¸´ÕýÔò±í´ïʽ
/^\([^,]*,\)\{8}
# visual searching
# ¿ÉÊÓģʽϵIJéÕÒ
:vmap // y/<C-R>"<CR> : search for visually highlighted text
²éÕÒ±»¸ßÁÁÏÔʾµÄÎı¾
:vmap <silent> // y/<C-R>=escape(@", '\\/.*$^~[]')<CR><CR> : with spec chars
# searching over multiple lines \_ means including newline
# ²éÕÒ¶àÐС£\_ ±íʾ°üÀ¨ÐÂÐÐ
/<!--\_p\{-}--> : search for multiple line comments
²éÕÒ¶àÐÐ×¢ÊÍ
/fred\_s*joe/i : any whitespace including newline
²éÕÒÔÚ fred ºÍ joe Á½¸öµ¥´ÊÖ®¼äÈÎÒâ¶àµÄ¿Õ
¸ñ£¬°üÀ¨ÐÂÐÐ
/bugs\(\_.\)*bunny : bugs followed by bunny anywhere in file
bugs ºóÈÎÒâλÖú¬ÓÐ bunny µ¥´ÊµÄ¶à¸öÐÐ
:h \_ : help
°ïÖú
# search for declaration of subroutine/function under cursor
# ²éÕÒ¹â±êÏÂ×Ó³ÌÐò/º¯ÊýµÄÉùÃ÷
:nmap gx yiw/^\(sub\<bar>function\)\s\+<C-R>"<CR>
# multiple file search
# ÔÚ¶à¸öÎļþÖвéÕÒ
:bufdo /searchstr
:argdo /searchstr
# How to search for a URL without backslashing
# ÈçºÎ²»Ê¹Ó÷´Ð±Ïß²éÕÒ URL
?http://www.vim.org/ : search BACKWARDS!!! clever huh!
----------------------------------------
# substitution
# Ìæ»»
:%s/fred/joe/igc : general substitute command
ÆÕÍ¨Ìæ»»ÃüÁî
:%s/\r//g : Delete DOS returns ^M
ɾ³ý DOS »Ø³µ·û ^M
# Is your Text File jumbled onto one line? use following
# ÄãµÄÎı¾ÎļþÊÇ·ñÂÒÆß°ËÔãµÄÅųÉÒ»ÐУ¿Ê¹ÓÃÈçÏÂÃüÁî
:%s/\r/\r/g : Turn DOS returns ^M into real returns
ת»» DOS »Ø³µ·û ^M ÎªÕæÕýµÄ»Ø³µ·û
:%s= *$== : delete end of line blanks
ɾ³ýÐÐβ¿Õ¸ñ
:%s= \+$== : Same thing
ͬÉÏ
:%s#\s*\r\?$## : Clean both trailing spaces AND DOS returns
ɾ³ýÐÐβ¿Õ¸ñºÍ DOS »Ø³µ·û
:%s#\s*\r*$## : same thing
ɾ³ýÐÐβ¿Õ¸ñºÍ DOS »Ø³µ·û
# deleting empty lines
# ɾ³ý¿ÕÐÐ
:%s/^\n\{3}// : delete blocks of 3 empty lines
ɾ³ýÈýÐпÕÐÐ
:%s/^\n\+/\r/ : compressing empty lines
ѹËõ¶àÐпÕÐÐΪһÐÐ
# IF YOU ONLY WANT TO KNOW ONE THING
# Èç¹ûÄãÖ»ÏëÃ÷°×Ò»¼þÊÂÇé
:'a,'bg/fred/s/dick/joe/igc : VERY USEFUL
·Ç³£ÓÐÓÃ
# duplicating columns
# ¸´ÖÆÁÐ
:%s= [^ ]\+$=&&= : duplicate end column
¸´ÖÆ×îºóÒ»ÁÐ
:%s= \f\+$=&&= : same thing
ͬÉÏ
:%s= \S\+$=&& : usually the same
ͬÉÏ
# memory
# ¼ÇÒ䣬»ò½ÐÒýÓÃ
:s/\(.*\):\(.*\)/\2 : \1/ : reverse fields separated by :
·´×ªÒÔ : ·Ö¸ôµÄ×Ö¶Î
:%s/^\(.*\)\n\1/\1$/ : delete duplicate lines
ɾ³ýÖØ¸´µÄÐÐ
# non-greedy matching \{-}
# ·Ç̰À·Æ¥Åä \{-}
:%s/^.\{-}pdf/new.pdf/ : delete to 1st pdf only
ֻɾ³ýµ½µÚÒ»¸ö pdf
# use of optional atom \?
:%s#\<[zy]\?tbl_[a-z_]\+\>#\L&#gc : lowercase with optional leading characters
²»¶®
# over possibly many lines
# Æ¥Å価¿ÉÄܶàµÄÐÐ
:%s/<!--\_.\{-}-->// : delete possibly multi-line comments
ɾ³ý¾¡¿ÉÄܶàµÄ×¢ÊÍ
:help /\{-} : help non-greedy
·Ç̰À·Æ¥ÅäµÄ°ïÖú
# substitute using a register
# ʹÓüĴæÆ÷Ìæ»»
:s/fred/<c-r>a/g : sub "fred" with contents of register "a"
ÓÃ"a"¼Ä´æÆ÷ÀïµÄÄÚÈÝÌæ»»"fred"
:s/fred/\=@a/g : better alternative as register not displayed
¸üºÃµÄ·½·¨£¬²»ÓÃÏÔʾ¼Ä´æÆ÷ÄÚÈÝ
# multiple commands on one line
# дÔÚÒ»ÐÐÀïµÄ¸´ÔÓÃüÁî
:%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/
# ORing
:%s/suck\|buck/loopy/gc : ORing (must break pipe)
²»¶®
# Calling a VIM function
# µ÷Óà Vim º¯Êý
:s/__date__/\=strftime("%c")/ : insert datestring
²åÈëÈÕÆÚ
# Working with Columns sub any str1 in col3
# ´¦ÀíÁУ¬Ìæ»»ËùÓÐÔÚµÚÈýÁÐÖÐµÄ str1
:%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2:
# Swapping first & last column (4 columns)
# ½»»»µÚÒ»ÁкÍ×îºóÒ»ÁÐ (¹²4ÁÐ)
:%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1:
# filter all form elements into paste register
# °ÑËùÓеÄformÔªËØ£¨¾ÍÊÇhtmlÀïÃæµÄformÀ²£©·Åµ½registerÀï
:redir @*|sil exec 'g#<\(input\|select\|textarea\|/\=form\)\>#p'|redir END
:nmap ,z :redir @*<Bar>sil exec
'g@<\(input\<Bar>select\<Bar>textarea\<Bar>/\=form\)\>@p'<Bar>redir END<CR>
# increment numbers by 6 on certain lines only
# ²»¶®
:g/loc\|function/s/\d/\=submatch(0)+6/
# better
# ¸üºÃµÄ·½·¨
:%s#txtdev\zs\d#\=submatch(0)+1#g
:h /\zs
# increment only numbers gg\d\d by 6 (another way)
# ²»¶®
:%s/\(gg\)\@<=\d\+/\=submatch(0)+6/
:h zero-width
# find replacement text, put in memory, then use \zs to simplify substitute
# ²éÕÒÐèÌæ»»µÄÎı¾£¬±£´æ£¬È»ºóʹÓà \zs ÃüÁî¼òµ¥Ìæ»»
:%s/"\([^.]\+\).*\zsxx/\1/
# Pull word under cursor into LHS of a substitute
# ²»¶®
:nmap <leader>z :%s#\<<c-r>=expand("<cword>")<cr>\>#
# Pull Visually Highlighted text into LHS of a substitute
# ²»¶®
:vmap <leader>z :<C-U>%s/\<<c-r>*\>/
----------------------------------------
# all following performing similar task, substitute within substitution
# Multiple single character substitution in a portion of line only
:%s,\(all/.*\)\@<=/,_,g : replace all / with _ AFTER "all/"
# Same thing
:s#all/\zs.*#\=substitute(submatch(0), '/', '_', 'g')#
# Substitute by splitting line, then re-joining
:s#all/#&^M#|s#/#_#g|-j!
# Substitute inside substitute
:%s/.*/\='cp '.submatch(0).' all/'.substitute(submatch(0),'/','_','g')/
----------------------------------------
# global command display (see tip 227)
# È«¾ÖÃüÁîÏÔʾ£¨²Î¼û tip 227)
:g/fred.*joe.*dick/ : display all lines fred,joe & dick
ÏÔʾËùÓаüº¬fred,joe ºÍ dick µÄÐÐ
:g/\<fred\>/ : display all lines fred but not freddy
ÏÔʾËùÓÐÈ«×ÖÆ¥Åä fred µÄÐÐ
:g/<pattern>/z#.5 : display with context
ÏÔʾÉÏÏÂÎÄ
:g/<pattern>/z#.5|echo "==========" : display beautifully
ÏÔʾµÃºÜƯÁÁ
:g/^\s*$/d : delete all blank lines
ɾ³ýËùÓеĿÕÐÐ
:g!/^dd/d : delete lines not containing string
ɾ³ýËùÓÐÐÐÊײ»ÊÇ dd µÄÐÐ
:v/^dd/d : delete lines not containing string
ͬÉÏ
:g/fred/,/joe/d : not line based (very powerfull)
²¢²»»ùÓÚÐÐ(·Ç³£Ç¿´ó)
:g/{/ ,/}/- s/\n\+/\r/g : Delete empty lines but only between {...}
ɾ³ýÔÚ {...} Ö»¼ûµÄ¿ÕÐÐ
:v/./.,/./-1join : compress empty lines
ѹËõ¿ÕÐÐ
:g/^$/,/./-j : compress empty lines
ѹËõ¿ÕÐÐ
:g/<input\|<form/p : ORing
²»¶®
:g/^/pu _ : double space file (pu = put)
°ÑÎļþÖпÕÐÐÔö¼ÓÒ»±¶
:g/^/m0 : Reverse file (m = move)
·×ªÎļþ
:g/fred/t$ : copy lines matching fred to EOF
°ÑÆ¥Åä fred µÄÐп½±´µ½Îļþ×îºó
:g/stage/t'a : copy lines matching stage to marker a
°ÑÆ¥Åä stage µÄÐÐ×ö±ê¼Ça
:%norm jdd : delete every other line
¸ôÒ»ÐÐɾ³ýÒ»ÐÐ
# incrementing numbers (type <c-a> as 5 characters)
:.,$g/^\d/exe "norm! \<c-a>": increment numbers
Ôö¼ÓÿÐÐÐÐÊ×µÄÊý×Ö
:'a,'bg/\d\+/norm! ^A : increment numbers
Ôö¼Ó±ê¼Ç a µ½±ê¼Ç b Ö»¼ûÿÐÐÐÐÊ×µÄÊý×Ö
# storing glob results (note must use APPEND)
# ±£´æÈ«¾ÖÃüÁîµÄ½á¹û (×¢Òâ±ØÐëʹÓÃÌí¼Óģʽ)
:g/fred/y A : append all lines fred to register a
Ìí¼ÓËùÓÐΪfredËùÆ¥ÅäµÄÐе½register a
:'a,'b g/^Error/ . w >> errors.txt
# duplicate every line in a file wrap a print '' around each duplicate
# ¸´ÖÆÃ¿Ò»ÐУ¬È»ºóÔÚ¸´ÖƳöÀ´µÄÿһÐÐÁ½²à¼ÓÉÏÒ»¸ö print '¸´ÖƳöÀ´µÄÄÚÈÝ'
:g/./yank|put|-1s/'/"/g|s/.*/Print '&'/
# replace string with contents of a file, -d deletes the "mark"
# ÓÃÎļþÖеÄÄÚÈÝÌæ»»×Ö·û´®£¬-d ±íʾɾ³ý¡°±ê¼Ç¡±
:g/^MARK$/r tmp.ex | -d
----------------------------------------
# Global combined with substitute (power editing)
# È«¾ÖÃüÁîºÍÌæ»»ÃüÁîÁªÒö (Ç¿´óµÄ±à¼ÄÜÁ¦)
:'a,'bg/fred/s/joe/susan/gic : can use memory to extend matching
¿ÉÒÔʹÓ÷´ÏòÒýÓÃÀ´Æ¥Åä
:g/fred/,/joe/s/fred/joe/gic : non-line based (ultra)
----------------------------------------
# Find fred before beginning search for joe
# ÏÈÕÒfred£¬È»ºóÕÒjoe
:/fred/;/joe/-2,/sid/+3s/sally/alley/gIC
----------------------------------------
# Absolutely essential
# »ù´¡
----------------------------------------
* # g* g# : find word under cursor (<cword>) (forwards/backwards)
ѰÕÒ¹â±ê´¦µÄÏÁÒåµ¥´Ê(<cword>) (ǰÏò/ºóÏò)
% : match brackets {}[]()
À¨ºÅÅä¶ÔѰÕÒ {}[]()
. : repeat last modification
matchit.vim : % now matches tags <tr><td><script> <?php etc
ʹµÃ % Äܹ»Åä¶Ô±ê¼Ç <tr><td><script> <?php µÈµÈ
<C-N><C-P> : word completion in insert mode
²åÈëģʽϵĵ¥´Ê×Ô¶¯Íê³É
<C-X><C-L> : Line complete SUPER USEFUL
ÐÐ×Ô¶¯Íê³É(³¬¼¶ÓÐÓÃ)
/<C-R><C-W> : Pull <cword> onto search/command line
°ÑÏÁÒåµ¥´Ê <cword> дµ½ ËÑË÷ÃüÁîÐÐ
/<C-R><C-A> : Pull <CWORD> onto search/command line
°Ñ¹ãÒåµ¥´Ê <cWORD> дµ½ ËÑË÷ÃüÁîÐÐ
:set ignorecase : you nearly always want this
ËÑË÷ʱºöÂÔ´óСд
:syntax on : colour syntax in Perl,HTML,PHP etc
ÔÚ Perl,HTML,PHP µÈÖнøÐÐÓï·¨×ÅÉ«
:h regexp<C-D> : type control-D and get a list all help topics containing
°´Ï control-D ¼ü¼´¿ÉµÃµ½°üº¬ÓÐ regexp µÄ°ïÖúÖ÷ÌâµÄÁбí
regexp (plus use TAB to Step thru list)
(ʹÓÃTAB¿ÉÒÔʵÏÖ°ïÖúµÄ×Ô¶¯²¹Æë)
----------------------------------------
# MAKE IT EASY TO UPDATE/RELOAD _vimrc
# ʹ¸üР_vimrc ¸üÈÝÒ×
:nmap ,s :source $VIM/_vimrc
# ÒëÊÍ£ºnmap Êǰó¶¨Ò»¸öÔÚnormalģʽϵĿì½Ý¼ü
:nmap ,v :e $VIM/_vimrc
# ÒëÊÍ£ºÔÚnormalģʽÏ£¬ÏȺó°´Ï ,s Á½¸ö¼üÖ´ÐÐ_vimrc£¬¶ø ,v ÔòÊDZà¼_vimrc
----------------------------------------
#VISUAL MODE (easy to add other HTML Tags)
# visual ģʽ (Àý×ÓÊÇ£ºÇáËÉÌí¼ÓÆäËûµÄ HTML Tags)
:vmap sb "zdi<b><C-R>z</b><ESC> : wrap <b></b> around VISUALLY selected Text
ÔÚvisualģʽÏÂÑ¡ÖеÄÎÄ×Öǰºó·Ö±ð
¼ÓÉÏ<b>ºÍ</b>
:vmap st "zdi<?= <C-R>z ?><ESC> : wrap <?= ?> around VISUALLY selected Text
ÔÚvisualģʽÏÂÑ¡ÖеÄÎÄ×Öǰºó·Ö±ð¼Ó
ÉÏ<?= ºÍ ?>
----------------------------------------
# Exploring
# Îļþä¯ÀÀ
:Exp(lore) : file explorer note capital Ex
¿ªÆôĿ¼ä¯ÀÀÆ÷£¬×¢ÒâÊ××ÖĸEÊÇ´óдµÄ
:Sex(plore) : file explorer in split window
ÔÚÒ»¸ö·Ö¸îµÄ´°¿ÚÖпªÆôĿ¼ä¯ÀÀÆ÷
:ls : list of buffers
ÏÔʾµ±Ç°bufferµÄÇé¿ö
:cd .. : move to parent directory
½øÈ븸Ŀ¼
:args : list of files
ÏÔʾĿǰ´ò¿ªµÄÎļþ
:lcd %:p:h : change to directory of current file
¸ü¸Äµ½µ±Ç°ÎļþËùÔÚµÄĿ¼
:autocmd BufEnter * lcd %:p:h : change to directory of current file
automatically (put in _vimrc)
×Ô¶¯¸ü¸Äµ½µ±Ç°ÎļþËùÔÚµÄĿ¼ (·Åµ½ _vimrc)
----------------------------------------
# Buffer Explorer (Top Ten Vim Script)
# »º³åÇø(buffer)ä¯ÀÀÆ÷ (µÚÈý·½µÄÒ»¸ö×îÁ÷ÐеĽű¾)
# needs bufexplorer.vim http://www.vim.org/script.php?script_id=42
# ÐèÒªÏÂÔØ bufexplorer.vim
\be : buffer explorer list of buffers
ÔÚ»º³åÇøä¯ÀÀÆ÷Öдò¿ª»º³åÇøÁбí
\bs : buffer explorer (split window)
ÒԷָ¿ÚµÄÐÎʽ´ò¿ª»º³åÇøä¯ÀÀÆ÷
----------------------------------------
# Changing Case
guu : lowercase line
ÐÐСд
gUU : uppercase line
Ðдóд
Vu : lowercase line
ÐÐСд
VU : uppercase line
Ðдóд
g~~ : flip case line
Ðзת
vEU : Upper Case Word
×Ö´óд(ÏÁÒå×Ö)
vE~ : Flip Case Word
×ַת(ÏÁÒå×Ö)
ggguG : lowercase entire file
°ÑÕû¸öÎÄÕÂÈ«²¿Ð¡Ð´
# Titlise Visually Selected Text (map for .vimrc)
vmap ,c :s/\<\(.\)\(\k*\)\>/\u\1\L\2/g<CR>
# Uppercase first letter of sentences
# ´óдËùÓоä×ӵĵÚÒ»¸ö×Öĸ
:%s/[.!?]\_s\+\a/\U&\E/g
----------------------------------------
gf : open file name under cursor (SUPER)
È¡µ±Ç°¹â±ê´¦µÄ¹ãÒå×Ö×÷ΪÎļþÃû£¬È»ºóÊÔͼ´ò¿ªËü£¡
ga : display hex,ascii value of char under cursor
ÏÔʾ¹â±ê´¦×Ö·ûµÄascii,hex,oct,...
ggVGg? : rot13 whole file
ÓÃrot13±àÂëÕû¸öÎļþ
ggg?G : rot13 whole file (quicker for large file)
ÓÃrot13±àÂëÕû¸öÎļþ(¶Ô´óÎļþ¸ü¿ìһЩ)
:8 | normal VGg? : rot13 from line 8
´ÓµÚ8ÐпªÊ¼£¬ÓÃrot13±àÂëºóÃæµÄÎı¾
:normal 10GVGg? : rot13 from line 8
´ÓµÚ8ÐпªÊ¼£¬ÓÃrot13±àÂëºóÃæµÄÎı¾
# ¡¾¹ØÓÚrot13¡ª¡ªËÈÃÓ¢ÎÄÊÇżÊý¸ö×Öĸ°¡¡¿
# ROT13 ÊÇÒ»ÖÖ¼òµ¥µÄ±àÂ룬Ëü°Ñ×Öĸ·Ö³ÉǰºóÁ½×飬ÿ×é13¸ö£¬±àÂëºÍ½âÂë
# µÄËã·¨Ïàͬ£¬½ö½ö½»»»×ÖĸµÄÕâÁ½¸ö²¿·Ö£¬¼´£º[a..m] --> [n..z] ºÍ [n..z]
# --> [a..m] ¡£ ROT13 ÓüòÒ×µÄÊÖ¶ÎʹµÃÐżþ²»ÄÜÖ±½Ó±»Ê¶±ðºÍÔÄ
# ¶Á£¬Ò²²»»á±»ËÑË÷Æ¥Åä³ÌÐòÓÃͨ³£µÄ·½·¨Ö±½ÓÕÒµ½¡£¾³£ÓÃÓÚ USENET Öз¢±íÒ»
# Щ¹¥»÷ÐÔ»òÁîÈ˲»¿ìµÄÑÔÂÛ»òÓмòµ¥±£ÃÜÐèÒªµÄÎÄÕ¡£
# ÓÉÓÚ ROT13 ÊÇ×ÔÄæËã·¨£¬ËùÒÔ£¬½âÂëºÍ±àÂëÊÇͬһ¸ö¹ý³Ì¡£
<C-A>,<C-X> : increment,decrement number under cursor
Ôö¼Ó,¼õÉÙ ¹â±ê´¦µÄÏÁÒå×ÖËù±íʾµÄÊý×Ö
win32 users must remap CNTRL-A
Win32µÄÓû§¿ÉÄÜÐèÒªÖØÐ¶¨ÒåÒ»ÏÂCtrl-A
<C-R>=5*5 : insert 25 into text (mini-calculator)
²åÈë25 (Ò»¸öÃÔÄã¼ÆËãÆ÷)
----------------------------------------
# Makes all other tips superfluous
:h 42 : also http://www.google.com/search?q=42
:h holy-grail
:h!
----------------------------------------
# Markers & moving about
# ±ê¼ÇºÍÒÆ¶¯
'. : jump to last modification line (SUPER)
Ìøµ½×îºóÐ޸ĵÄÄÇÒ»ÐÐ (³¬¼¶ÓÐÓÃ)
`. : jump to exact spot in last modification line
²»½öÌøµ½×îºóÐ޸ĵÄÄÇÒ»ÐУ¬»¹Òª¶¨Î»µ½Ð޸ĵã
g; : cycle thru recent changes (oldest first) (new in vim6.3)
Ñ»·Ìø×ªÐ޸ĵã(´Ó×îÀϵÄÐ޸ĵ㿪ʼ) (vim6.3ÖÐÐÂÔö)
g, : reverse direction (new in vim6.3)
·´ÏòÑ»·Ìø×ªÐ޸ĵã (vim6.3ÖÐÐÂÔö)
:changes
:h changelist : help for above
<C-O> : retrace your movements in file (starting from most recent)
ÒÀ´ÎÑØ×ÅÄãµÄÌø×ª¼Ç¼Ïò»ØÌø (´Ó×î½üµÄÒ»´Î¿ªÊ¼)
<C-I> : retrace your movements in file (reverse direction)
ÒÀ´ÎÑØ×ÅÄãµÄÌø×ª¼Ç¼ÏòÇ°Ìø
:ju(mps) : list of your movements
ÁгöÄãÌø×ªµÄ×ã¼£
:help jump-motions
:history : list of all your commands
ÁгöÀúÊ·ÃüÁî¼Ç¼
:his c : commandline history
ÃüÁîÐÐÃüÁîÀúÊ·
:his s : search history
ËÑË÷ÃüÁîÀúÊ·
q/ : Search history Window
ËÑË÷ÃüÁîÀúÊ·µÄ´°¿Ú
q: : commandline history Window
ÃüÁîÐÐÃüÁîÀúÊ·µÄ´°¿Ú
:<C-F> : history Window
ÀúÊ·ÃüÁî¼Ç¼µÄ´°¿Ú
----------------------------------------
# Abbreviations & maps
# # ËõдºÍ¼üÅÌÓ³Éä
:map <f7> :'a,'bw! c:/aaa/x
# ÒëÊÍ£ºmapÊÇÓ³ÉäÒ»¸önormalģʽϵļü
# ÕâÀïÊǰÑF7¼üÓ³Éä³É°Ñ±ê¼Çaµ½±ê¼ÇbÖмäµÄÄÚÈÝÁí´æÎªÒ»¸öÎļþ/aaa/x
# ±ê¼Ç(mark)µÄ·½·¨£º°Ñ¹â±êÒÆ¶¯µ½ÐèÒª±ê¼ÇµÄµØ·½£¬ÊäÈëm£¬È»ºóÊä
Èë±ê¼ÇÃû£¬ÀýÈça
# ÒýÓñê¼ÇµÄ·½·¨£º'a £¬¼´£ºµ¥ÒýºÅ¼Ó±ê¼ÇÃû
:map <f8> :r c:/aaa/x
# ÒëÊÍ£º°ÑF8¼üÓ³Éä³ÉÔÚµ±Ç°Î»ÖòåÈëÎļþ/aaa/xµÄÄÚÈÝ
:map <f11> :.w! c:/aaa/xr<CR>
# ÒëÊÍ£º.£¨µãºÅ£©±íʾµ±Ç°ÐÐ
# ËùÒÔF11¾ÍÊǰѵ±Ç°ÐдæÎª/aaa/xr
# ×îºóµÄ<CR>±íʾһ¸ö»Ø³µ
:map <f12> :r c:/aaa/xr<CR>
:ab php : list of abbreviations beginning php
Áгöphp±íʾµÄËõд
# ÒëÊÍ£º¶¨ÒåÒ»¸öËõдʹÓãº:iab hm hmisty
# Ò»¸öÓÐȤµÄÏÖÏóÊÇ£¬ËüÁгöµÄ»áÊÇphpºÍËüµÄǰ×Ó´®¿ªÍ·µÄËõд
# ÀýÈ磬ÓÐÕâô¼¸¸öËõд£º
# h => hmisty1 , hm => hmisty2 , hmi => hmisty3, m => hmisty4
# ÄÇôʹÓà :ab hm»áÏÔʾÕâô¼¸¸öËõд£ºhm ºÍ h
# ¶ø²»ÊÇÄãÏëÏóÖÐµÄ hm ºÍ hmi
:map , : list of maps beginning ,
ÁгöÒÔ¶ººÅ¿ªÊ¼µÄ¼üÅÌÓ³Éä
# allow use of F10 for mapping (win32)
# ÔÊÐí F10 µÄÓ³ÉäÓ÷¨ (win32)
set wak=no : :h winaltkeys
²Î¼û :h winaltkeys
# For use in Maps
# ÔÚ¼üÅÌÓ³ÉäÖг£Óõıíʾ
<CR> : carriage Return for maps
»Ø³µ
<ESC> : Escape
ESC
<LEADER> : normally \
תÒå·ûºÅ \
<BAR> : | pipe
¹ÜµÀ·ûºÅ
<BACKSPACE> : backspace
Í˸ñ·ûºÅ
# display RGB colour under the cursor eg #445588
# ÏÔʾ¹â±êÏÂÊýÖµµÄ RGB ÑÕÉ«
:nmap <leader>c :hi Normal guibg=#<c-r>=expand("<cword>")<cr><cr>
----------------------------------------
# Using a register as a map (preload registers in .vimrc)
:let @m=":'a,'bs/"
:let @s=":%!sort -u"
----------------------------------------
# List your Registers
# Áгö¼Ä´æÆ÷(Registers)
:reg : display contents of all registers
ÏÔʾËùÓмĴæÆ÷µÄÄÚÈÝ
:reg a : display content of individual registers
ÏÔʾ a ¼Ä´æÆ÷µÄÄÚÈÝ
"1p.... : retrieve numeric registers one by one
:let @y='yy@"' : pre-loading registers (put in .vimrc)
----------------------------------------
# Useful tricks
# ÓÐÓõÄÇÏÃÅ
"ayy@a : execute "Vim command" in a text file
°Ñµ±Ç°ÐÐ×÷Ϊһ¸öVimÃüÁîÀ´Ö´ÐÐ
yy@" : same thing using unnamed register
ͬÉÏ£¬²»¹ýÊÇÓÃÄäÃû¼Ä´æÆ÷
u@. : execute command JUST typed in
Ö»Ö´ÐмüÈëµÄÃüÁî
----------------------------------------
# Get output from other commands (requires external programs)
# ´ÓÆäËû³ÌÐò»ñÈ¡Êä³ö (ÐèÒªÍⲿ³ÌÐò)
:r!ls.exe : reads in output of ls
¶ÁÈ¡lsµÄÊä³öµ½µ±Ç°Î»ÖÃ
!!date : same thing (but replaces/filters current line)
¶ÁÈ¡dateµÄÊä³ö (µ«ÊÇ»áÌæ»»µ±Ç°ÐеÄÄÚÈÝ)
# ÒëÊÍ£ºÆäʵÄãÊäÈëÁË!!ºó£¬vim¾Í×Ô¶¯×ª»»µ½ :.! µÈ´ýÄã¼ÌÐøÊäÈë
# Sorting with external sort
# ʹÓÃÍⲿ³ÌÐòsort½øÐÐÅÅÐò(sortÊÇUnix±ê×¼ÃüÁls,dateÒ²ÊÇ)
:%!sort -u : use an external program to filter content
ʹÓÃsort³ÌÐòÅÅÐòÕû¸öÎļþ£¨Óýá¹ûÖØÐ´Îļþ£©
# ÒëÊÍ£º%±íʾÕû¸öÎļþµÄËùÓÐÐÐ
# !sort±íʾִÐÐÍⲿÃüÁîsort
# -uÊÇsortµÄ²ÎÊý£¬man sort¿´¿´£¬Õâ¸ö²ÎÊýµÄÒâÒåÊǺϲ¢ÏàͬµÄÐÐ
# u¾ÍÊÇunique,Èç¹ûÁ½ÐÐÄÚÈÝÏàͬ£¬Ôò½á¹ûÖÐÖ»±£ÁôÒ»ÐеÄ˵
:'a,'b!sort -u : use an external program to filter content
¶Ômark a µ½mark bÖмäµÄÄÚÈݽøÐÐÅÅÐò
!1} sort -u : sorts paragraph (note normal mode!!)
ÅÅÐòµ±Ç°¶ÎÂä (Ö»ÄÜÔÚnormalģʽÏÂʹÓÃ!!)
# ÒëÊÍ£º!±íʾʹÓÃfilter£¬1}±íʾfilterµÄ¶ÔÏóÊÇ´Óµ±Ç°ÐпªÊ¼Ïòºó
ÊýÒ»¶Î
# ¶ÎÂäÖ¸µ½¿ÕÐд¦½áÊø£¬²»°üÀ¨¿ÕÐÐ
# ÆäʵÄãÒ»µ©ÊäÈë !1}£¬vim¾Í×Ô¶¯¼ÆË㵱ǰ¶ÎÂäÓ¦¸Ãµ½ÄÇÒ»ÐÐ(eg.+
5)£¬È»ºóÉú³É
# :.,.+5! µÈ´ýÖ®ºóÊäÈësort -u£¬»Ø³µ£¬Íê³É²Ù×÷
# .±íʾµ±Ç°ÐУ¬.+5µ±È»¾ÍÊǵ±Ç°ÐÐÏòºóÊý5ÐÐ
----------------------------------------
# Multiple Files Management (Essential)
# ¶àÎĵµ²Ù×÷ (»ù´¡)
:bn : goto next buffer
Ìø×ªµ½ÏÂÒ»¸öbuffer
:bp : goto previous buffer
Ìø×ªµ½ÉÏÒ»¸öbuffer
:wn : save file and move to next (super)
´æÅ̵±Ç°Îļþ²¢Ìø×ªµ½ÏÂÒ»¸ö
:wp : save file and move to previous
´æÅ̵±Ç°Îļþ²¢Ìø×ªµ½ÉÏÒ»¸ö
:bd : remove file from buffer list (super)
°ÑÕâ¸öÎļþ´ÓbufferÁбíÖÐ×öµô
:bun : Buffer unload (remove window but not from list)
жµôbuffer (¹Ø±ÕÕâ¸öbufferµÄ´°¿Úµ«ÊDz»°ÑËü´ÓÁбíÖÐ×öµô)
:badd file.c : file from buffer list
°ÑÎļþfile.cÌí¼Óµ½bufferÁбí
:b 3 : go to buffer 3
Ìøµ½µÚ3¸öbuffer
:b main : go to buffer with main in name eg main.c (ultra)
Ìøµ½Ò»¸öÃû×ÖÖаüº¬mainµÄbuffer,ÀýÈçmain.c
:sav php.html : Save current file as php.html and "move" to php.html
°Ñµ±Ç°Îļþ´æÎªphp.html²¢´ò¿ªphp.html
:sav! %<.bak : Save Current file to alternative extension
»»Ò»¸öºó׺±£´æ
:sav! %:r.cfm : Save Current file to alternative extension
:e! : return to unmodified file
·µ»Øµ½ÐÞ¸Ä֮ǰµÄÎļþ(ÐÞ¸ÄÖ®ºóûÓдæÅÌ)
:w c:/aaa/% : save file elsewhere
°ÑÎļþ´æµ½Ò»¸öµØ¶ù
:e # : edit alternative file
±à¼±ê¼ÇΪ#µÄbuffer(Õâ¸öbuffer±ØÐ뺬ÓÐÒ»¸ö¿É±à¼µÄÎļþ)
# ÓÃlsÃüÁî¾ÍÄÜ¿´µ½ÄÄÒ»¸öbufferÓÐ#
# %a±íʾµ±Ç°ÕýÔڱ༵Äbuffer
# u ±íʾ²»Äܱ༻òÕßÒѾ±»×öµôµÄbuffer
:rew : return to beginning of editted files list (:args)
»Øµ½µÚÒ»¸ö¿É±à¼µÄÎļþ
:brew : buffer rewind
»Øµ½µÚÒ»¸öbuffer
:sp fred.txt : open fred.txt into a split
ÔÚÒ»¸öˮƽ·Ö¸îµÄ´°¿ÚÖдò¿ªÎļþfred.txt # Òë×¢£ºvs fred.txt¿É
ÒÔʵÏÖ´¹Ö±·Ö¸î
:sball,:sb : Split all buffers (super)
°Ñµ±Ç°ËùÓк¬Óпɱà¼ÎļþµÄbufferÏÔʾµ½Ò»¸ö·Ö¸î´°¿ÚÖÐ
:scrollbind : in each split window
:map <F5> :ls<CR>:e # : Pressing F5 lists all buffer, just type number
ÔÚnormalģʽϰ´F5¼ü£¬Ôò»áÏÔʾËùÓк¬ÓÐÒ»¸ö
¿É±à¼ÎļþµÄbuffer£¬È»ºóÌáʾÄãÊäÈëbufferµÄÐòºÅ£¬
ÊäÈëºó»Ø³µ£¬Ôò±à¼Õâ¸öbuffer
:set hidden : Allows to change buffer w/o saving current buffer
ÔÊÐí²»±£´æbuffer¶øÇл»buffer (w/o=without)
----------------------------------------
# Quick jumping between splits
# Ôڷָ¿ÚÖпìËÙÇл»
:map <C-J> <C-W>j<C-W>_
# ÕâÊÇÒ»¸ö¼üÅ̰󶨣¬°ÑCtrl-J¶¨Òå³ÉÇл»µ½ÏÂÒ»¸ö´°¿Ú²¢×î´ó»¯
:map <C-K> <C-W>k<C-W>_
# ÕâÊÇÒ»¸ö¼üÅ̰󶨣¬°ÑCtrl-K¶¨Òå³ÉÇл»µ½ÉÏÒ»¸ö´°¿Ú²¢×î´ó»¯
----------------------------------------
# Recording (BEST TIP of ALL)
# ÃüÁîÂ¼ÖÆ (×î¼Ñ¼¼ÇÉ)
qq # record to q
Â¼ÖÆµ½q
your complex series of commands # ÊäÈëһϵÁи´ÔÓµÄÖ¸Áî
q # end recording
Ôٴΰ´qÍ£Ö¹Â¼ÖÆ
@q # to execute
Ö´ÐÐqÖд洢µÄÖ¸Áî
@@ # to Repeat
ÖØ¸´Ö´ÐÐ
5@@ # to Repeat 5 times
ÖØ¸´Ö´ÐÐ5±é
# editing a register/recording
# ±à¼¼Ä´æÆ÷/Â¼ÖÆ
"qp :display contents of register q (normal mode)
ÏÔʾ¼Ä´æÆ÷ q µÄÄÚÈÝ (ÆÕͨģʽ)
<ctrl-R>q :display contents of register q (insert mode)
ÏÔʾ¼Ä´æÆ÷ q µÄÄÚÈÝ (²åÈëģʽ)
# you can now see recording contents, edit as required
# ÄãÏÖÔÚ¿ÉÒÔ¿´µ½¼Ç¼ÄÚÈÝ£¬Ëæ±ã±à¼
"qdd :put changed contacts back into q
@q :execute recording/register q
Ö´ÐмǼ/¼Ä´æÆ÷ q
# Operating a Recording on a Visual BLOCK
# ÔÚ¿ÉÊÓ¿éÖÐÔËÐмǼ
1) define recording/register
1) ¶¨Òå¼Ç¼/¼Ä´æÆ÷
qq:s/ to/ from/g^Mq
2) Define Visual BLOCK
2) ¶¨Òå¿ÉÊÓ¿é
V}
3) hit : and the following appears
3) ¼üÈë : ½«ÏÔʾÏÂÃæÐÅÏ¢
:'<,'>
4)Complete as follows
4) Íê³ÉÈçϲÙ×÷
:'<,'>norm @q
----------------------------------------
# Visual is the newest and usually the BEST editting mode
# ¿ÉÊÓģʽÊÇ×îÐÂҲͨ³£ÊÇ×îºÃµÄ±à¼Ä£Ê½
# Visual basics
# ¿ÉÊÓģʽ»ù´¡
v : enter visual mode
½øÈë¿ÉÊÓģʽ
V : visual mode whole line
ÕûÐеĿÉÊÓģʽ
<C-V> : enter VISUAL BLOCK mode
½øÈë¿ÉÊÓ¿éģʽ
gv : reselect last visual area
ÖØÐÂѡȡ×îеĿÉÊÓÇøÓò
o : navigate visual area
ä¯ÀÀ¿ÉÊÓÇøÓò
"*y : yank visual area into paste buffer
¸´ÖÆ¿ÉÊÓÇøÓòµ½¼ôÌù°å
V% : visualise what you match
???
V}J : Join Visual block (great)
Á¬½Ó¿ÉÊÓ¿é
----------------------------------------
# Delete first 2 characters of 10 successive lines
# ɾ³ýÁ¬Ðø10ÐÐÖÐÿÐеÄÍ·2¸ö×Ö·û
0<c-v>10j2ld
----------------------------------------
# how to copy a set of columns using VISUAL BLOCK
# ÈçºÎÓÿÉÊӿ鿽±´¼¸ÁÐ
# visual block (AKA columnwise selection) (NOT BY ordinary v command)
# ¿ÉÊÓ¿é(²¢·Çͨ³£µÄ v ÃüÁî)
<C-V> then select "column(s)" with motion commands (win32 <C-Q>)
<C-V>£¬È»ºóͨ¹ýÒÆ¶¯ÃüÁîÑ¡ÔñÁÐ (win32 <C-Q>)
then c,d,y,r etc
È»ºóÖ´ÐÐ c,d,y,r µÈÃüÁî
----------------------------------------
# _vimrc essentials
# _vimrc»ù´¡
:set incsearch : jumps to search word as you type (annoying but excellent)
ʵʱƥÅäÄãÊäÈëµÄÄÚÈÝ
:set wildignore=*.o,*.obj,*.bak,*.exe : tab complete now ignores these
tab¼üµÄ×Ô¶¯Íê³ÉÏÖÔÚ»áºöÂÔÕâЩ
:set shiftwidth=3 : for shift/tabbing
×Ô¶¯Ëõ½øÉèΪ4¸ö×Ö·û
# Òë×¢£ºÒ»¸ötabλͨ³£ÊÇ8¸ö×Ö·û
# ËùÒÔ£¬ÎÒÃÇ»¹ÒªÉ趨 :set tabstop=4£¬Õâ
Ñù£¬ËùÓеÄËõ½ø¶¼ÊÇ4×Ö·ûÁË
:set vb t_vb=". : set silent (no beep)
³ÁĬ·½Ê½(²»Òª½Ðbeep£¡)
:set browsedir=buffer : Maki GUI File Open use current directory
ÉèÖà GUI °æ±¾Îļþ´ò¿ªÊ±£¬Ê¹Óõ±Ç°Â·¾¶
----------------------------------------
# launching Win IE
# ¼ÓÔØ IE ä¯ÀÀÆ÷
:nmap ,f :update<CR>:silent !start c:\progra~1\intern~1\iexplore.exe file://%:p<CR>
:nmap ,i :update<CR>: !start c:\progra~1\intern~1\iexplore.exe <cWORD><CR>
# ÒëÊÍ£ºnmapÊÇ×öÒ»¸önormalģʽϵļüÅ̰ó¶¨
# ÕâÀï°ó¶¨ÁËÒ»¸ö¶ººÅÃüÁî ,f
# :updateÊÇдÕâ¸öÎļþ£¬Óë:w²»Í¬£¬ËüÖ»Óе±Îļþ±»ÐÞ¸ÄÁ˵Äʱºò²Åд
# :silent±ðÈõ¯³ö´°¿Ú±¨¸æÖ´Ðнá¹û
# !...ºóÃæ¾ÍÊÇÖ´ÐÐwindowsÃüÁîÁË¡£ºÇºÇ£¬È¥ÎÊbill gatesʲôÒâ˼°É¡£
----------------------------------------
# FTPing from VIM
# Óà VIM ͨ¹ý ftp ±à¼Îļþ
:cmap ,r :Nread ftp://209.51.134.122/public_html/index.html
:cmap ,w :Nwrite ftp://209.51.134.122/public_html/index.html
gvim ftp://209.51.134.122/public_html/index.html
# Òë×¢£ºcmapÊÇÃüÁî(command)ģʽ°ó¶¨
----------------------------------------
# appending to registers (use CAPITAL)
# ¸½¼Óµ½Ò»¸öregister (ÓôóдµÄregisterÃû×Ö)
"a5yy #¸´ÖÆ5Ðе½aÖÐ
10j #ÏÂÒÆ10ÐÐ
"A5yy #ÔÙÌí¼Ó5Ðе½aÖÐ
----------------------------------------
[I : show lines matching word under cursor <cword> (super)
ÏÔʾ¹â±ê´¦µÄÏÁÒå×Ö¿ÉÒÔÆ¥ÅäµÄÐÐ(¸ß¼¶Ö¸Áî)
# Òë×¢£º# ¿ÉÒÔÈ«ÎIJéÕÒÓë¹â±ê´¦µÄÏÁÒå×ÖÏàÆ¥ÅäµÄ×Ö£¬
# ÕâÔÚ²éÕÒº¯ÊýÔÐͺÍʵÏÖ£¬»òÕß±äÁ¿Ê¹ÓõÄʱºòºÜÓÐÓÃ
----------------------------------------
# Conventional Shifting/Indenting
# ³£¹æËõ½ø
:'a,'b>> # °Ñmark aµ½mark bÖ®¼äµÄÄÚÈÝËõ½øÁ½´Î
# visual shifting (builtin-repeat)
# ÔÚvisualģʽÏÂËõ½ø (ÎÞÏÞ¿ÉÖØ¸´)
:vnoremap < <gv
# ÒëÊÍ£º:vnoremap ÖØ¶¨ÒåÁËvisualģʽÏ < ·ûºÅµÄº¬Òå
# °ÑËü¶¨Òå³É <gv
# ¼´£ºÏÈ<ÏòÍâËõ½ø£¬È»ºógvÖØÐÂÑ¡ÔñÉÏÒ»´ÎÑ¡ÔñÁ˵ÄÇøÓò
# ÕâÑùÔÚvisualģʽϾͿÉÒÔʵÏÖÁ¬Ðø°´<¶øÁ¬ÐøËõ½øÁË
:vnoremap > >gv
# ͬÀÄÚËõ
# Block shifting (magic)
# ¿éËõ½ø
>i{
>a{
# also
>% and <%
----------------------------------------
# Redirection & Paste register *
# ÖØ¶¨Ïòµ½¼ôÌù°åºÍ´Ó¼ôÌù°åÕ³Ìù
:redir @* : redirect commands to paste buffer
ÖØ¶¨ÏòÃüÁîµÄÊä³ö½á¹û£¨×îÏ·½ÃüÁîÐÐÉϵĽá¹û£©
:redir END : end redirect
½áÊøÖØ¶¨Ïò
:redir >> out.txt : redirect to a file
ÖØ¶¨Ïòµ½Ò»¸öÎļþ
# Working with Paste buffer
# ²Ù×÷¼ôÌù°å
"*yy : yank to paste
¸´ÖƵ½¼ôÌù°åÖÐ
"*p : insert from paste buffer
´Ó¼ôÌù°åÖÐÕ³Ìù
# yank to paste buffer (ex mode)
# ¿½±´µ½¼ôÌù°å (ex ģʽ)
:'a,'by* : Yank range into paste
°Ñ±ê¼Çaµ½±ê¼Çb¼ûµÄÄÚÈÝ¿½±´µ½¼ôÌù°å
:%y* : Yank whole buffer into paste
°ÑÕû¸öÎļþ¿½±´µ½¼ôÌù°å
# filter non-printable characters from the paste buffer
# ´Ó¼ôÌù°åÉϹýÂ˷ǿɴòÓ¡×Ö·û
# useful when pasting from some gui application
# µ±´ÓһЩ GUI ³ÌÐòÕ³Ìùʱ»áÓÐÓô¦
:nmap <leader>p :let @* = substitute(@*,'[^[:print:]]','','g')<cr>"*p
----------------------------------------
# Re-Formatting text
# ÖØÐ¸ñʽ»¯Îı¾
gq} : Format a paragraph
¸ñʽ»¯Ò»¸ö¶ÎÂä
ggVGgq : Reformat entire file
ÖØÐ¸ñʽ»¯Õû¸öÎļþ
Vgq : current line
¸ñʽ»¯µ±Ç°ÐÐ
# break lines at 70 chars, if possible after a ;
# ÔÚ70ÁеÄʱºò»»ÐÐ
:s/.\{,69\};\s*\|.\{,69\}\s\+/&\r/g
----------------------------------------
# Operate command over multiple files
# ¶Ô¶à¸öÎĵµÊµÊ©ÃüÁî
:argdo %s/foo/bar/e : operate on all files in :args
¶ÔËùÓÐ:argsÁбíÖеÄÎĵµÖ´ÐÐÃüÁî
:bufdo %s/foo/bar/e
:windo %s/foo/bar/e
:argdo exe '%!sort'|w! : include an external command
ʹÓÃÍⲿÃüÁî
:bufdo /foo/
----------------------------------------
# Command line tricks
# ÃüÁîÐÐÉϵļ¼ÇÉ
gvim -h : help
Æô¶¯°ïÖú
ls | gvim - : edit a stream!!
±à¼Ò»¸öÊý¾ÝÁ÷
cat xx | gvim - -c "v/^\d\d\|^[3-9]/d " : filter a stream
gvim -o file1 file2 : open into a split
ÒԷָ¿Ú´ò¿ªÁ½¸öÎļþ
# execute one command after opening file
# Ö¸³ö´ò¿ªÖ®ºóÖ´ÐеÄÃüÁî
gvim.exe -c "/main" joe.c : Open joe.c & jump to "main"
# execute multiple command on a single file
# ¶ÔÒ»¸öÎļþÖ´Ðжà¸öÃüÁî
vim -c "%s/ABC/DEF/ge | update" file1.c
# execute multiple command on a group of files
# ¶ÔÒ»×éÎļþÖ´Ðжà¸öÃüÁî
vim -c "argdo %s/ABC/DEF/ge | update" *.c
# remove blocks of text from a series of files
# ´ÓÒ»×éÎļþÖÐɾ³ýÎı¾¿é
vim -c "argdo /begin/+1,/end/-1g/^/d | update" *.c
# Automate editting of a file (Ex commands in convert.vim)
# ×Ô¶¯±à¼Îļþ (±à¼ÃüÁîÐòÁÐEx commandsÒѾ°üº¬ÔÚconvert.vimÖÐÁË)
vim -s "convert.vim" file.c
#load VIM without .vimrc and plugins (clean VIM)
# ²»Òª¼ÓÔØ.vimrcºÍÈκÎplugins (Æô¶¯Ò»¸ö¸É¾»µÄVIM)
gvim -u NONE -U NONE -N
# Access paste buffer contents (put in a script/batch file)
# ¶ÁÈ¡¼ôÌù°åÄÚÈÝ (·Åµ½½Å±¾»òÅú´¦ÀíÎļþÖÐ)
gvim -c 'normal ggdG"*p' c:/aaa/xp
# print paste contents to default printer
# °Ñ¼ôÌù°åÄÚÈÝ´òÓ¡µ½Ä¬ÈÏ´òÓ¡»ú
gvim -c 's/^/\=@*/|hardcopy!|q!'
----------------------------------------
# GVIM Difference Function (Brilliant)
gvim -d file1 file2 : vimdiff (compare differences)
vimdiff (±È½Ï²»Í¬)
dp : "put" difference under cursor to other file
°Ñ¹â±ê´¦µÄ²»Í¬·Åµ½ÁíÒ»¸öÎļþ
do : "get" difference under cursor from other file
ÔÚ¹â±ê´¦´ÓÁíÒ»¸öÎļþÈ¡µÃ²»Í¬
----------------------------------------
# Vim traps
# VimÏÝÚå
In regular expressions you must backslash + (match 1 or more)
In regular expressions you must backslash | (or)
In regular expressions you must backslash ( (group)
In regular expressions you must backslash { (count)
# ÔÚvimµÄÕýÔò±í´ïʽÖУ¬ + | ( { ǰ¶¼±ØÐë¼ÓתÒå·û \
/fred\+/ : matches fred/freddy but not free
Æ¥Åäfred»òfreddyµ«ÊDz»Æ¥Åäfree
/\(fred\)\{2,3}/ : note what you have to break
???
----------------------------------------
# \v or very magic (usually) reduces backslashing
# \v £¬»ò½Ð×övery magic (ͨ³£¶¼ÊÇÕâô½Ð)¿ÉÒÔÈ¡ÏûתÒå·û
/codes\(\n\|\s\)*where : normal regexp
ÆÕͨµÄÕýÔò±í´ïʽ
/\vcodes(\n|\s)*where : very magic
----------------------------------------
# pulling objects onto command/search line (SUPER)
# °Ñ¶«Î÷Ë͵½ÃüÁîÐÐ/ËÑË÷ÐÐ (SUPER)
<C-R><C-W> : pull word under the cursor into a command line or search
ËÍÒ»¸öÏÁÒå´Ê
<C-R><C-A> : pull WORD under the cursor into a command line or search
ËÍÒ»¸ö¹ãÒå´Ê
<C-R>- : pull small register (also insert mode)
ËÍÒ»¸öСÐͼĴæÆ÷ (²åÈëģʽÏÂÒ²ÓÐЧ)
<C-R>[0-9a-z] : pull named registers (also insert mode)
ËÍÒ»¸öÃüÃû¼Ä´æÆ÷ (²åÈëģʽÏÂÒ²ÓÐЧ)
<C-R>% : pull file name (also #) (also insert mode)
ËÍÎļþÃû¹ýÈ¥ (#Ò²ÐÐ) (²åÈëģʽÏÂÒ²ÓÐЧ)
----------------------------------------
# manipulating registers
# ²Ù×÷¼Ä´æÆ÷
:let @a=@_ : clear register a
Çå¿Õ¼Ä´æÆ÷a
:let @a="" : clear register a
ͬÉÏ
:let @*=@a : copy register a to paste buffer
¿½±´¼Ä´æÆ÷ a µÄÄÚÈݵ½¼ôÌù°å
map <f11> "qyy:let @q=@q."zzz"
----------------------------------------
# help for help
# ¹ØÓÚ°ïÖúµÄ°ïÖú
:h quickref : VIM Quick Reference Sheet (ultra)
VIM ¿ìËٲο¼ÊÖ²á (ultra)
:h tips : Vim's own Tips Help
Vim×Ô¼ºµÄtips
:h visual<C-D><tab> : obtain list of all visual help topics
µÃµ½Ò»¸ö¹ØÓÚvisual¹Ø¼ü×ֵİïÖúÁбí
: Then use tab to step thru them
: È»ºóÓÃtab¼üȥѡÔñ
:h ctrl<C-D> : list help of all control keys
ÏÔʾËùÓйØÓÚCtrlµÄ°ïÖú
:helpg uganda : Help grep
ÏÔʾ grep °ïÖú
:h :r : help for :ex command
:exðºÅÃüÁî
:h CTRL-R : normal mode
ÆÕͨģʽÃüÁî
:h /\r : what's \r in a regexp (matches a <CR>)
\rÔÚÕýÔò±í´ïʽÖÐÊÇʲôÒâË¼ÄØ£¿
:h \\zs : double up backslash to find \zs in help
:h i_CTRL-R : help for say <C-R> in insert mode
insertģʽϵÄCtrl-R
:h c_CTRL-R : help for say <C-R> in command mode
ÃüÁîÐÐ(command-line)ģʽϵÄCtrl-R
:h v_CTRL-V : visual mode
visualģʽϵÄCtrl-V
:h tutor : VIM Tutor
VIM Ö¸ÄÏ
<C-[>, <C-T> : Move back & Forth in HELP History
ÔÚ°ïÖúÀúÊ·ÖУ¬Ïòǰ/ºóÒÆ¶¯
gvim -h : VIM Command Line Help
¹ØÓÚ VIM ÃüÁîµÄ°ïÖú
----------------------------------------
# where was an option set
# Ñ¡ÏîÉèÖÃÔÚÄÄÀ
:scriptnames : list all plugins, _vimrcs loaded (super)
ÁгöËùÓмÓÔØµÄ plugins, _vimrcs
:verbose set history? : reveals value of history and where set
ÏÔʾhistoryµÄÖµ²¢Ö¸³öÉèÖÃÎļþµÄλÖÃ
:function : list functions
ÁгöËùÓк¯Êý
:func SearchCompl : List particular function
ÁгöÖ¸¶¨µÄº¯Êý
----------------------------------------
# making your own VIM help
# ÖÆ×÷Äã×Ô¼ºµÄVIM°ïÖú
:helptags /vim/vim63/doc : rebuild all *.txt help files in /doc
ÖØ½¨ /doc ÖÐËùÓÐµÄ *.txt °ïÖúÎļþ
:help add-local-help
----------------------------------------
# running file thru an external program (eg php)
# ÓÃÍⲿ³ÌÐòÀ´ÔËÐгÌÐò (ÀýÈç php)
map <f9> :w<CR>:!c:/php/php.exe %<CR>
map <f2> :w<CR>:!perl -c %<CR>
----------------------------------------
# capturing output of current script in a separate buffer
# ÔÚÁíÒ»¸öbufferÖУ¬²¶×½µ±Ç°½Å±¾µÄÊä³ö
:new | r!perl # : opens new buffer,read other buffer
н¨Ò»¸öbuffer£¬´ÓÁíÒ»¸öbufferÖжÁÈë½á¹û
:new! x.out | r!perl # : same with named file
ͬÉÏ£¬²¢Ö¸¶¨Ò»¸öÐÂÎļþÃû
----------------------------------------
# Inserting DOS Carriage Returns
# ²åÈëDOS»»Ðзû
:%s/nubian/<C-V><C-M>&/g : that's what you type
:%s/nubian/<C-Q><C-M>&/g : for Win32
¶ÔÓÚWin32Ó¦¸ÃÕâÑù
dn_t...@yahoo.ca
:%s/nubian/^M&/g : what you'll see where ^M is ONE character
Äã¿´µ½µÄ^MÊÇÒ»¸ö×Ö·û
:%s/nubian/\r&/g : better
¸üºÃµÄÐÎʽ
----------------------------------------
# automatically delete trailing Dos-returns,whitespace
# ×Ô¶¯É¾³ýÐÐβ Dos»Ø³µ·ûºÍ¿Õ¸ñ
autocmd BufRead * silent! %s/[\r \t]\+$//
autocmd BufEnter *.php :%s/[ \t\r]\+$//e
----------------------------------------
# perform an action on a particular file or file type
# ¶ÔÖ¸¶¨Îļþ»òÎļþÀàÐÍÖ´ÐÐij¸ö¶¯×÷
autocmd VimEnter c:/intranet/note011.txt normal! ggVGg?
autocmd FileType *.pl exec('set fileformats=unix')
----------------------------------------
# Retrieving last command line command for copy & pasting into text
# °Ñ×îºóÒ»¸öÃüÁîÌùµ½µ±Ç°Î»ÖÃ
i<c-r>:
# Retrieving last Search Command for copy & pasting into text
# °Ñ×îºóÒ»¸öËÑË÷Ö¸ÁîÌùµ½µ±Ç°Î»ÖÃ
i<c-r>/
# ÒëÊÍ£ºiÊǽøÈëinsertģʽ£¬
# Ctrl-rÊÇ¿ªÆô²åÈëģʽÏÂregisterµÄÒýÓÃ
# :ºÍ/·Ö±ðÒýÓÃÁËÁ½¸öregisterµÄÄÚÈÝ
----------------------------------------
# more completions
# ¸ü¶àµÄÍê³É¹¦ÄÜ
<C-X><C-F> :insert name of a file in current directory
²åÈ뵱ǰĿ¼ÏµÄÒ»¸öÎļþÃûµ½µ±Ç°Î»ÖÃ
# ÔÚinsertģʽÏÂʹÓÃ
# È»ºóÓà Ctrl-P/Ctrl-N ·Ò³
----------------------------------------
# Substituting a Visual area
# Ìæ»»Ò»¸övisualÇøÓò
# select visual area as usual (:h visual) then type :s/Emacs/Vim/ etc
# Ñ¡ÔñÒ»¸öÇøÓò£¬È»ºóÊäÈë :s/Emacs/Vim/ µÈµÈ£¬vim»á×Ô¶¯½øÈë:ģʽ
:'<,'>s/Emacs/Vim/g : REMEMBER you dont type the '<.'>
Ç°ÃæµÄ'<,'>ÊÇvim×Ô¶¯Ìí¼ÓµÄ
gv : Re-select the previous visual area (ULTRA)
ÖØÐÂÑ¡Ôñǰһ¸ö¿ÉÊÓÇøÓò (ULTRA)
----------------------------------------
# inserting line number into file
# ÔÚÎļþÖвåÈëÐкÅ
:g/^/exec "s/^/".strpart(line(".")." ", 0, 4)
:%s/^/\=strpart(line(".")." ", 0, 5)
:%s/^/\=line('.'). ' '
----------------------------------------
#numbering lines VIM way
# ÓÃVIMµÄ·½Ê½À´±àºÅÐÐ
:set number : show line numbers
ÏÔʾÐкÅ
:map <F12> :set number!<CR> : Show linenumbers flip-flop
:%s/^/\=strpart(line('.')." ",0,&ts)
#numbering lines (need Perl on PC) starting from arbitrary number
#´ÓÈÎÒâÐпªÊ¼±àºÅ(ÐèÒªperl)
:'a,'b!perl -pne 'BEGIN{$a=223} substr($_,2,0)=$a++'
# Produce a list of numbers
# ²úÉúÊý×ÖÁбí
#Type in number on line say 223 in an empty file
qqmnYP`n^Aq : in recording q repeat with @q
# increment existing numbers to end of file (type <c-a> as 5 characters)
# µÝÔöÒÑ´æÔÚÊý×Öµ½ÎļþÄ©
:.,$g/^\d/exe "normal! \<c-a>"
# advanced incrementing
# ¸ß¼¶µÝÔö£¬²Î¼û£º
http://vim.sourceforge.net/tip_view.php?tip_id=150
----------------------------------------
# advanced incrementing (really useful)
# ¸ß¼¶µÝÔö (ÕæµÄºÜÓÐÓÃ)
" put following in _vimrc
" °ÑÏÂÃæ¼¸¾ä·Åµ½ _vimrc #vimrc½Å±¾Óà " ×öÐÐ×¢ÊÍ·û
let g:I=0
function! INC(increment)
let g:I =g:I + a:increment
return g:I
endfunction
" eg create list starting from 223 incrementing by 5 between markers a,b
" ÀýÈç´Ómark a µ½mark b µÝÔö£¬´Ó223¿ªÊ¼£¬²½³¤Îª5
:let I=223
:'a,'bs/^/\=INC(5)/
" create a map for INC
cab viminc :let I=223 \| 'a,'bs/$/\=INC(5)/
----------------------------------------
# editing/moving within current insert (Really useful)
# ÔÚµ±Ç°²åÈëģʽϱà¼/ÒÆ¶¯ (ÕæµÃºÜÓÐÓÃ)
<C-U> : delete all entered
ɾ³ýÈ«²¿
<C-W> : delete last word
ɾ³ý×îºóÒ»¸öµ¥´Ê
<HOME><END> : beginning/end of line
ÒÆ¶¯µ½ÐÐÊ×/ÐÐβ
<C-LEFTARROW><C-RIGHTARROW> : jump one word backwards/forwards
Ïòǰ/ºóÒÆ¶¯Ò»¸öµ¥´Ê
<C-X><C-E>,<C-X><C-Y> : scroll while staying put in insert
----------------------------------------
#encryption (use with care: DON'T FORGET your KEY)
# ¼ÓÃÜ(СÐÄʹÓ㬲»ÒªÍüÁËÃÜÂë)
:X : you will be prompted for a key
vim»áÌáʾÄãÊäÈëÃÜÂë
:h :X
----------------------------------------
# modeline (make a file readonly etc) must be in first/last 5 lines
# ģʽÐÐ (ʹÎļþÖ»¶ÁµÈ)£¬±ØÐëÔÚǰ/ºó 5ÐÐÄÚ
// vim:noai:ts=2:sw=4:readonly:
# vim:ft=html: : says use HTML Syntax highlighting
ʹÓà HTML Óï·¨¸ßÁÁ
:h modeline
----------------------------------------
# Creating your own GUI Toolbar entry
# ½¨Á¢Äã×Ô¼ºµÄ²Ëµ¥Ïî
amenu Modeline.Insert\ a\ VIM\ modeline <Esc><Esc>ggOvim:ff=unix ts=4
ss=4<CR>vim60:fdm=marker<esc>gg
----------------------------------------
# A function to save word under cursor to a file
# Ò»¸ö±£´æµ±Ç°¹â±êϵÄÏÁÒå×Öµ½Ò»¸öÎļþµÄº¯Êý
function! SaveWord()
normal yiw
exe ':!echo '.@0.' >> word.txt'
endfunction
map ,p :call SaveWord()
----------------------------------------
# function to delete duplicate lines
# ɾ³ýÖØ¸´Ðеĺ¯Êý
function! Del()
if getline(".") == getline(line(".") - 1)
norm dd
endif
endfunction
:g/^/ call Del() #ʹÓøú¯ÊýµÄÒ»¸öÀý×Ó
----------------------------------------
# Digraphs (non alpha-numerics)
# Ë«×Ö½Ú±àÂë (non alpha-numerics)
:digraphs : display table
ÏÔʾ±àÂë±í
:h dig : help
°ïÖú
i<C-K>e' : enters �
ÊäÈë ¨¦
i<C-V>233 : enters � (Unix)
ÊäÈë ¨¦ (Unix)
i<C-Q>233 : enters � (Win32)
ÊäÈë ¨¦ (Win32)
ga : View hex value of any character
²é¿´×Ö·ûµÄhexÖµ
# Deleting non-ascii characters (some invisible)
# ɾ³ý·Ç ascii ×Ö·û
:%s/[<C-V>128-<C-V>255]//gi : where you have to type the Control-V
:%s/[€-�]//gi : Should see a black square & a dotted y
:%s/[<C-V>128-<C-V>255<C-V>01-<C-V>31]//gi : All pesky non-asciis
:exec "norm /[\x00-\x1f\x80-\xff]/" : same thing
#Pull a non-ascii character onto search bar
yl/<C-R>" :
----------------------------------------
# All file completions grouped (for example main_c.c)
# ÎļþÃû×Ô¶¯Íê³É (ÀýÈç main_c.c)
:e main_<tab> : tab completes
tab ¼üÍê³É
gf : open file under cursor (normal)
´ò¿ª¹â±ê´¦¹ãÒå×ÖÃüÃûµÄÎļþ (normalģʽ)
main_<C-X><C-F> : include NAME of file in text (insert mode)
ÎļþÃû×Ô¶¯Íê³É(insertģʽ)
----------------------------------------
# Complex Vim
# Vim¸´ÔÓʹÓÃ
# swap two words
# ½»»»Á½¸öµ¥´Ê
:%s/\<\(on\|off\)\>/\=strpart("offon", 3 * ("off" == submatch(0)), 3)/g
# swap two words
# ½»»»Á½¸öµ¥´Ê
:vnoremap <C-X> <Esc>`.``gvP``P
----------------------------------------
# Convert Text File to HTML
# °ÑtextÎļþת»»³ÉhtmlÎļþ(oh,ft)
:runtime! syntax/2html.vim : convert txt to html
ת»» txt ³É html
:h 2html
----------------------------------------
# VIM has internal grep
# VIM ÓÐÒ»¸öÄÚ²¿×Ô´øµÄ grep ÃüÁî
:grep some_keyword *.c : get list of all c-files containing keyword
µÃµ½Ò»¸ö°üº¬some_keywordµÄcÎļþÃûÁбí
:cn : go to next occurrence
È¥ÏÂÒ»¸ö³öÏÖµÄλÖÃ
----------------------------------------
# Force Syntax coloring for a file that has no extension .pl
# Ç¿ÖÆÎÞÀ©Õ¹ÃûµÄÎļþµÄÓï·¨×ÅÉ«·½Ê½
:set syntax=perl
# Remove syntax coloring (useful for all sorts of reasons)
# È¡ÏûÓï·¨×ÅÉ« (ºÜÓÐÓÃ)
:set syntax off
# change coloring scheme (any file in ~vim/vim??/colors)
# ¸Ä±äÉ«²ÊÖ÷Ìâ (ÔÚ~vim/vim??/colorsÖеÄÈκÎÎļþ)
:colorscheme blue
# Force HTML Syntax highlighting by using a modeline
# ͨ¹ýʹÓÃģʽÐÐÇ¿ÆÈʹÓà HTML Óï·¨¸ßÁÁ
# vim:ft=html:
----------------------------------------
:set noma (non modifiable) : Prevents modifications
·ÀÖ¹ÐÞ¸Ä
:set ro (Read Only) : Protect a file from unintentional writes
Ö»¶Á±£»¤
----------------------------------------
# Sessions (Open a set of files)
# ¶Ô»° (´ò¿ªÒ»¶ÑÎļþ)
gvim file1.c file2.c lib/lib.h lib/lib2.h : load files for "session"
ÔÚ"¶Ô»°"ÖмÓÔØÕâЩÎļþ
:mksession : Make a Session file (default Session.vim)
Éú³ÉÒ»¸öSessionÎļþ (ĬÈÏÊÇSession.vim)
:q
gvim -S Session.vim : Reload all files
ÖØÐ¼ÓÔØËùÓÐÎļþ
----------------------------------------
# tags (jumping to subroutines/functions)
# ±ê¼Ç(tags) (Ìø×ªµ½×Ó³ÌÐò/º¯Êý)
taglist.vim : popular plugin
ºÜÁ÷ÐеIJå¼þ
:Tlist : display Tags (list of functions)
ÏÔʾ±ê¼Ç (º¯ÊýÁбí)
<C-]> : jump to function under cursor
Ìø×ªµ½¹â±ê´¦µÄº¯Êý
----------------------------------------
# columnise a csv file for display only as may crop wide columns
:let width = 20
:let fill=' ' | while strlen(fill) < width | let fill=fill.fill | endwhile
:%s/\([^;]*\);\=/\=strpart(submatch(1).fill, 0, width)/ge
:%s/\s\+$//ge
# Highlight a particular csv column (put in .vimrc)
function! CSVH(x)
execute 'match Keyword /^\([^,]*,\)\{'.a:x.'}\zs[^,]*/'
execute 'normal ^'.a:x.'f,'
endfunction
command! -nargs=1 Csv :call CSVH(<args>)
# call with
:Csv 5 : highlight fith column
----------------------------------------
# folding : hide sections to allow easier comparisons
# ÕÛµþ£ºÒþ²ØÄ³Ð©Æ¬¶Ï£¬ÊDz鿴¸üÈÝÒ×
zf} : fold paragraph using motion
ʹÓö¯×÷ÃüÁîÕÛµþÒ»¸ö¶ÎÂä
v}zf : fold paragraph using visual
ʹÓÿÉÊÓģʽÕÛµþÒ»¸ö¶ÎÂä
zf'a : fold to mark
ÕÛµþµ½Ò»¸ö±ê¼ÇÉÏ
zo : open fold
´ò¿ªÕÛµþ
zc : re-close fold
ÖØÐ¹رÕÕÛµþ
----------------------------------------
# displaying "invisible characters"
# ÏÔʾ"²»¿É¼û×Ö·û"
:set list
:h listchars
----------------------------------------
# How to paste "normal commands" w/o entering insert mode
# ÈçºÎÔÚ²»½øÈë²åÈëģʽµÄÇé¿öÏÂÕ³Ìù"ÆÕͨģʽµÄÃüÁî"
:norm qqy$jq
----------------------------------------
# manipulating file names
# ´¦ÀíÎļþÃû
:h filename-modifiers : help
°ïÖú
:w % : write to current file name
дÈ뵱ǰÎļþ
:w %:r.cfm : change file extention to .cfm
¸Ä±äÎļþÀ©Õ¹ÃûΪ .cfm
:!echo %:p : full path & file name
ÏÔʾÍêÕû·¾¶ºÍÎļþÃû
:!echo %:p:h : full path only
Ö»ÏÔʾÍêÕû·¾¶
<C-R>% : insert filename (insert mode)
²åÈëÎļþÃû (²åÈëģʽ)
"%p : insert filename (normal mode)
²åÈëÎļþÃû (ÆÕͨģʽ)
/<C-R>% : Search for file name in text
ÔÚÎı¾ÖвéÕÒÎļþÃû
----------------------------------------
# delete without destroying default buffer contents
# ɾ³ý£¬µ«²»ÆÆ»µ buffer ÄÚÈÝ
"_d : what you've ALWAYS wanted
ÄãÒ»Ö±ÏëÒªµÄ¶«Î÷
"_dw : eg delete word (use blackhole)
ÀýÈ磺ɾ³ýÒ»¸öµ¥´Ê (ʹÓúڶ´???)
----------------------------------------
# pull full path name into paste buffer for attachment to email etc
# ËÍÍêÕûµÄ·¾¶Ãûµ½¼ôÌù°å£¬ÓÃÓÚÓʼþ¸½¼þµÈ
nnoremap <F2> :let @*=expand("%:p")<cr> :unix
nnoremap <F2> :let @*=substitute(expand("%:p"), "/", "\\", "g")<cr> :win32
----------------------------------------
# Simple Shell script to rename files w/o leaving vim
# ²»ÓÃÀ뿪 Vim ¾ÍÄÜÐÞ¸ÄÎļþÃûµÄ¼òµ¥ shell ½Å±¾
$ vim
:r! ls *.c
:%s/\(.*\).c/mv & \1.bla
:w !sh
:q!
----------------------------------------
# count words in a text file
# ÔÚÒ»¸öÎı¾Àï¼ÆËãµ¥´ÊÊý
g<C-G>
----------------------------------------
# example of setting your own highlighting
# Äã×Ô¼ºÉèÖøßÁÁÏÔʾµÄÀý×Ó
:syn match DoubleSpace " "
:hi def DoubleSpace guibg=#e0e0e0
----------------------------------------
# Programming keys depending on file type
# ¸ù¾ÝÎļþÀàÐÍÓ³Éä¿ì½Ý¼ü
:autocmd bufenter *.tex map <F1> :!latex %<CR>
:autocmd bufenter *.tex map <F2> :!xdvi -hush %<.dvi&<CR>
----------------------------------------
# reading Ms-Word documents, requires antiword
# ¶ÁÈ¡ MS-Word Îĵµ£¬ÐèÒª antiword
:autocmd BufReadPre *.doc set ro
:autocmd BufReadPre *.doc set hlsearch!
:autocmd BufReadPost *.doc %!antiword "%"
----------------------------------------
# Just Another Vim Hacker JAVH
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
# ÒëÊÍ£ººÇºÇ£¬ËÀ´½âÊÍһϰɣ¡
# Æäʵ²»¹ýÊÇÔÚÆô¶¯vimµÄʱºòÖ´ÐÐÁËÒ»¸öÃüÁî
# ÏÈдÈëÁË Just Another Vim Hacker µÄrot13±àÂë
# È»ºóÔÙ½âÂë
----------------------------------------
__END__