{"id":616,"date":"2012-12-15T11:59:06","date_gmt":"2012-12-15T11:59:06","guid":{"rendered":"http:\/\/atheotsky.loc\/?p=14"},"modified":"2012-12-15T11:59:06","modified_gmt":"2012-12-15T11:59:06","slug":"daily-vim-grand-collection","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/daily-vim-grand-collection\/","title":{"rendered":"Daily vim – Grand collection"},"content":{"rendered":"

working with Blocks<\/p>\n

di> (“delete inner angle-block”)<\/p>\n

ci” (“change inner double-quote block”)<\/p>\n

daw, dap, dab<\/p>\n

caw, cap, cab<\/p>\n

>ib, <ib, >iB, >i}, >i)<\/p>\n

%<\/p>\n

= (auto indent selected text & auto format base on file type)<\/p>\n

<\/p>\n

q \u00a0 \u00a0 start\/stop record macros<\/p>\n

“+y (copy to clipboard)<\/p>\n

“+p (paste from clipboard)<\/p>\n

dst, cst, cs”) (vim surround)<\/p>\n

ysiw) , yssB (vim surround) – ys then select operator fast (y-s-s fast)<\/p>\n

“dyy, “a7yy (make use of buffer a, d)<\/p>\n

“dp, “ap ( use a,d buffer)<\/p>\n

“a5dd<\/p>\n

-> “d command (do command with buffer d)<\/p>\n

:reg<\/p>\n

y,d,c + movement (H,M,L,),},])<\/p>\n

:g\/pattern\/s\/old\/new\/g (ex search combine with replace)<\/p>\n

study unix commands for this \\(^o^)<\/p>\n

:.,$!sort -g<\/p>\n

:%!sort -d<\/p>\n

(and etc\u2026)<\/p>\n

working with tags<\/p>\n

:tags (show tags browse route)<\/p>\n

:tn, :tp (tag next, tag pre)<\/p>\n

:ts [ident] list the tags match [ident] , :sts [ident] with split window (can specify ‘vert’ for vertical split)<\/p>\n

g] (list)<\/p>\n

^] (go direct to 1st tag def.)<\/p>\n

working with completion<\/p>\n

^X [^F, ^L, ^D, ^I, ^K, ^T, ^], ^V, ^O, ^N, ^P] \u00a0 \u00a0 file,line,def,directory,words,tags,vimcmd,include f,next,pre<\/p>\n

working with tabs<\/p>\n

:tabs list all tabs<\/p>\n

:tabm 0 move tab to first<\/p>\n

:tabm move tab to last<\/p>\n

:tabm {i} move tab to i+1<\/p>\n

gt, gT, {i}gt move to tab in position i<\/p>\n

gi : go to insert mode where you left it last time<\/p>\n

g+,g- : undo state \/ branches ?<\/p>\n

zo,zc,zR(open all folds),zM(close all folds),zj,zk(navi)<\/p>\n

Vim navi<\/p>\n

(), {}, [[]], -\/+ (movement)<\/p>\n

fx, Fx, tx, Tx, ; ,<\/p>\n

:Explore (vim default file explorer)<\/p>\n

<C-d> : list posibilities – combine with Tab<\/p>\n

:vimgrep, :Ack (o, go, t, T, h, H, v, gv, q)<\/p>\n

:go NNN \u00a0 \u00a0 \u00a0go to byte NNN<\/p>\n

‘. \u00a0 \u00a0 jump to last modification line<\/p>\n

`. \u00a0 \u00a0 jump to exact spot in last modification line<\/p>\n

<C-O> \u00a0 \u00a0 retrace your movements in file (backward)<\/p>\n

<C-I> \u00a0 \u00a0 retrace your movements in file (forward)<\/p>\n

:ju(mps) \u00a0 \u00a0 list of your movements<\/p>\n

:history \u00a0 \u00a0 list of all your commands<\/p>\n

:source $MYVIMRC reload vimrc<\/p>\n

Vim command help<\/p>\n

<C-d> : list all commands base on input chars<\/p>\n

<C-f> : browse history base on input chars<\/p>\n

<TAB> : auto complete, loop through all commands base on input chars<\/p>\n

Set filetype for syntax highlighting & auto format<\/p>\n

:set filetype=[file type]<\/p>\n

file type can be php, html, sql, xml , js or cpp \u2026<\/p>\n

Working with diff<\/p>\n

vert diffsplit [file to compare]<\/p>\n

:[range]diffg[et]<\/p>\n

:[range]diffpu[t]<\/p>\n

do \u00a0 \u00a0 :[range]diffg[et] without range<\/p>\n

dp \u00a0 \u00a0 :[range]diffpu[t] without range<\/p>\n

:diffoff<\/p>\n

Tools<\/p>\n

:TOhtml \u00a0 \u00a0 export content of current file to html (theme included).<\/p>\n

Sessions (not so useful with plugin -> turn off plugin like NERDtree before mksession)<\/p>\n

:mksession [session name].vim \u00a0 \u00a0 make session<\/p>\n

:source [session name].vim \u00a0 \u00a0 restore session<\/p>\n

vim -S [session name].vim \u00a0 \u00a0 start vim with specific session.<\/p>\n

Vim and terminal<\/p>\n

:%! [cmd]<\/p>\n

:read ! [cmd]<\/p>\n

:!php -l % \u00a0 \u00a0 check php syntax<\/p>\n

Auto complete base on context – Object<\/p>\n

place DocBlock notation under variable:<\/p>\n

\/*@var $_product Mage_Catalog_Model_Product*\/<\/p>\n

Working with text case<\/p>\n

guu \u00a0 \u00a0 : lowercase line<\/p>\n

gUU \u00a0 \u00a0 : uppercase line<\/p>\n

~ \u00a0 \u00a0 \u00a0 : invert case (upper->lower; lower->upper) of current character<\/p>\n

gf\u00a0 \u00a0 \u00a0 : open file name under cursor (SUPER)<\/p>\n

ga\u00a0 \u00a0 \u00a0 : display hex, ascii value of character under cursor<\/p>\n

g8\u00a0 \u00a0 \u00a0 : display hex value of utf-8 character under cursor<\/p>\n

ggg?G \u00a0 : rot13 whole file<\/p>\n

xp\u00a0 \u00a0 \u00a0 : swap next two characters around<\/p>\n

CTRL-A,CTRL-X : increment, decrement next number on same line as the cursor<\/p>\n

CTRL-R=5*5\u00a0 \u00a0 : insert 25 into text<\/p>\n

= \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : (re)indent the text on the current line or on the area selected (SUPER)<\/p>\n

=%\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : (re)indent the current braces { … }<\/p>\n

G=gg\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : auto (re)indent entire document<\/p>\n

pssh secret!!!<\/b><\/p>\n

help 42 -> help holy-grail<\/p>\n

collaborate with shell<\/p>\n

:r!ls \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : reads in output of ls (use dir on Windows)<\/p>\n

:r !grep “^ebay” file.txt\u00a0 : read output of grep<\/p>\n

:20,25 !rot13\u00a0 \u00a0 \u00a0 \u00a0 : rot13 lines 20 to 25<\/p>\n

:r!date\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : insert date (use\u00a0 date \/T on Windows)<\/p>\n

:.!sh\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : execute contents of current line in buffer and capture the output<\/p>\n

Sorting with external sort<\/p>\n

:%!sort -u \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : contents of the current file is sorted and only unique lines are kept<\/p>\n

:’v,’w!sort\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : sort from line marked v thru lines marked w<\/p>\n

:g\/^$\/;,\/^$\/-1!sort\u00a0 : sort each block (note the crucial \ud83d\ude09<\/p>\n

!1} sort \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : sorts paragraph; this is issued from normal mode!)<\/p>\n

Entering !! in normal mode is translated to\u00a0 :.!<\/p>\n

Appending a command sends the current line to the command replacing it with command’s result<\/p>\n

!!date\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : Replace current line with date<\/p>\n

!!which command \u00a0 \u00a0 : Replace current line with the absolute path to command<\/p>\n

!!tr -d AEIO\u00a0 \u00a0 \u00a0 \u00a0 : translate current line deleting As, Es, Is, and Os from the current line<\/p>\n

You can also use ! on a visual selection. Select an area with one of the visualmode<\/p>\n

commands, and then type !command to pipe the whole selection through command.<\/p>\n

This is equivalent to :'<,’>!command.<\/p>\n

For example, after selecting multiple lines with visualmode:<\/p>\n

!sort\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 : sort selected lines<\/p>\n

!grep word\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 : keep only lines containing ‘word’ in the selected range.<\/p>\n","protected":false},"excerpt":{"rendered":"

All my vim tips are here, but not so easy to understand<\/p>\n","protected":false},"author":1,"featured_media":83,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,47],"tags":[],"aioseo_notices":[],"views":7,"_links":{"self":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/616"}],"collection":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/comments?post=616"}],"version-history":[{"count":0,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/616\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/"}],"wp:attachment":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media?parent=616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/categories?post=616"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/tags?post=616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}