vim usage

4486 단어 vim
Append each line starting with "Error"to a file:
 
:g/^Error/.w! >> errors.txt
 
 
===========================================================================
 
" global command display 
:g/gladiolli/#              : display with line numbers (YOU WANT THIS!)
:g/fred.*joe.*dick/         : display all lines fred,joe & dick
:g/\<fred\>/                : display all lines fred but not freddy
:g/^\s*$/d                  : delete all blank lines
:g!/^dd/d                   : delete lines not containing string
:v/^dd/d                    : delete lines not containing string
: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/
\+/\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/<input\|<form/p : ORing :g/^/put_ : double space file (pu = put) :g/^/m0 : Reverse file (m = move) :g/^/m$ : No effect! *N* :'a,'bg/^/m'b : Reverse a section a to b :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 " perform a substitute on every other line :g/^/ if line('.')%2|s/^/zz / " match all lines containing "somestr" between markers a & b " 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 <c-a> as 5 characters) :.,$g/^\d/exe "norm! \<c-a>": increment numbers :'a,'bg/\d\+/norm! ^A : increment numbers " storing glob results (note must use APPEND) you need to empty reg a first with qaq. "save results to a register/paste buffer :g/fred/y A : append all lines fred to register a :g/fred/y A | :let @*=@a : put into paste buffer :let @a=''|g/Barratt/y A |:let @*=@a " filter lines to a file (file must already exist) :'a,'bg/^Error/ . w >> errors.txt " duplicate every line in a file wrap a print '' around each duplicate :g/./yank|put|-1s/'/"/g|s/.*/Print '&'/ " replace string with contents of a file, -d deletes the "mark" :g/^MARK$/r tmp.txt | -d " display prettily :g/<pattern>/z#.5 : display with context :g/<pattern>/z#.5|echo "==========" : display beautifully " Combining g// with normal mode commands :g/|/norm 2f|r* : replace 2nd | with a star "send output of previous global command to a new window :nmap <F3> :redir @a<CR>:g//<CR>:redir END<CR>:new<CR>:put! a<CR><CR> "---------------------------------------- " Global combined with substitute (power editing) :'a,'bg/fred/s/joe/susan/gic : can use memory to extend matching :/fred/,/joe/s/fred/joe/gic : non-line based (ultra) :/biz/,/any/g/article/s/wheel/bucket/gic: non-line based *N* ---------------------------------------- " Find fred before beginning search for joe :/fred/;/joe/-2,/sid/+3s/sally/alley/gIC "---------------------------------------- " create a new file for each line of file eg 1.txt,2.txt,3,txt etc :g/^/exe ".w ".line(".").".txt" "---------------------------------------- " chain an external command :.g/^/ exe ".!sed 's/N/X/'" | s/I/Q/ *N*

좋은 웹페이지 즐겨찾기