-
-
Save erikwco/4e4d43a800543cb106eb44d7be282aaf to your computer and use it in GitHub Desktop.
advanced vim commands to review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
da< (or) da( (or) da{ // delete the block including <,(,{ and >,),} rsply | |
di< (or) di( (or) di{ // simillarly, but excluing <,(,{ and >,),} rsply | |
yi< (or) yi( (or) yi{ // yanks simillarly. Simillarly for ciw, viw, etc | |
df<Space> // delete from current char including the next space | |
daw // delete current word including the next space | |
diq // delete current word excluding the next space | |
yiw // yank current word excluding the next space | |
yaw // yank current word including the next space | |
:v/./d // delete blank lines | |
:g/^$/d | |
de // delete to the end of the word | |
'' // last presented line | |
`` // last presented location in the line | |
'. // last edited line | |
`. // simillarly | |
]p // pasting in that current indent | |
"a]p // paste from buffer 'a' with current indent | |
"ap // paste from buffer 'a' w/o any indent | |
ctrl-xf // file | |
ctrl-xl // line | |
:ce (or) :center // centers the text lines to the textwidth | |
:%ce // centers the whole file | |
:ri // right | |
:le // left | |
gq // allign set of lines based on textwidth | |
gggqG // (:set tw=80). | |
ctrl-a // increases a number, if select pattern is choosed | |
// the whole number is increased accordingly | |
ctrl-x // same as ctrl-a, but decrease the value | |
ga // value at cursor location | |
g ctrl-g // (w/o space) location of cursor | |
:buffer file_name // opens file_name, if it is already opened | |
// it is equivalant of giving the buf no in :buffer | |
:%!xxd // converts the contents in to xxd output | |
:%xxd -r // revert back | |
/ma\{,5} // m, ma,.... maaaaa | |
/\(foo\|bar\)\+ // foobar, foofoo, barfoobar,.... foo* | |
/match/3 // 3 lines after the search string | |
/match/-2 // 2 lines before the search string | |
/match/e2 // 2 chars after the string end | |
/match/e-2 // 2 chars before the string end | |
/match/b2 // 2 chars after the string begining | |
/match/b-2 // 2 chars before the string begining | |
/match/s3 // same as /match/b3 | |
diw // delete the word where the cursor is | |
:args *.c | |
:argdo %s/text/replacement_text/ge | update // change done in all .c files | |
:set smartcase | |
:set smartindent | |
:set ruler | |
:set nowrapscan | |
:e! // open the same file freshly discarding current changes | |
:help ctrl-a // help for ctrl-a | |
ctrl-] // jump to that tag | |
ctrl-t // jump back to the previous position | |
ctrl-o // jump to previous cursor postion | |
ctrl-i // jump back to those position | |
ytx // yanks upto x from current cursor position | |
yTx // same as ytx, but in reverse direction | |
y2fx // yanks upto the 2nd occurance of x | |
yFx | |
To get the header file (function declerations alone from a c file) using ctags | |
:%s/^.*\/\^//g | |
:%s/.*v$//g | |
:%s/\(.*\)$.*/\1;/g | |
:.,.s/.*/\U&/g // change to upper case | |
:%s/.*/\U&/g // change to upper case the whole file | |
gd // search for definition in same function | |
gD // search for definition in same file | |
:set makeprg=nmake // nmake is used instead of make when :make | |
:set makeprg=nmake\ -f\ project.mak | |
:colder // to use older error list | |
:cnewer // to use the new erro list | |
:set list // displays enter, tab, etc | |
:set wrap // wrap the text to next line when the line length | |
:set nowrap // exceeds the length set by textwidth | |
[[ // go to the function start simillarly for ]] | |
[{ // go to the block start simillarly for ]} | |
[I // list all lines matching the text | |
:set path+= // used by :find command to search a file | |
:set path+=/usr/*/include // /usr/a/include, /usr/b/include | |
:set path+=/usr/**/include // /usr/a/include, /usr/a/b/include | |
zz // moves current cursor line to mid of screen | |
zt // moves current cursor line to top of screen | |
zb // moves current cursor line to bot of screen | |
:set history=100 | |
:set history& // & sets the default value | |
:map <F5> i{<esc>ea}<esc> // surrounds a word with {}; \ can be added to maping | |
de // delete till end of word only | |
d2e | |
dw // delete word and next space also | |
d4w | |
c2w // delets 2 word and prepares for editing | |
X (or) dl // deletes left (= back space while editing) | |
x (or) dh // deletes right | |
D (or) d$ // delete till end of line | |
C (or) c$ // delete till end of line and prepares for editing | |
s (or) cl // delete the char and prepares for editing | |
S (or) cc // delete the current line and prepares for editing | |
5rx // replaces 5 charecters with x | |
:scriptnames // displays the script name files | |
ctrl-i, ctrl-o // in ESC mode, to trace back to the positions where the | |
// cursers where | |
ctrl-i // for tab in insert mode. | |
50% // in ESC mode, to go to that location of that file. | |
ctrl-f,ctrl-b, ctrl u, ctrl-d | |
ctrl-e,ctrl-y // moves the screen 1 ln w/o changing the curser loc | |
3* // 3rd occurance of the string under curser | |
3# | |
:set wrapscan | |
:set nowrapscan | |
:set incsearch // incrementally searchs when typing itself | |
:set noincsearch | |
:set number | |
:set nonumber | |
:set ruler | |
:set noruler | |
:set ignorecase | |
:set noignorecase | |
:set ignorecase smartcase // after seting this, search will be case sensitive | |
// if search pattern has any Upper case letter | |
:set showmatch | |
:set matchtime=15 // for 1.5 secs | |
:find filename // search in path for filename. path set by :set path+= | |
:abbrivate a abc | |
:unabbrivate a | |
:abclear // clears all abbrivation | |
:set display=uhex // ga | |
$vim -b exe_file // opens in binary and sets for editing binary or exe file | |
$vim -x filename | |
:X | |
:set key= | |
:buffers // displays files opened; % repersents current file, # reps previous file | |
// ctrl-6 for switching bet % and # files. | |
:buffer n // go to the nth file | |
:ls // same as buffers | |
:hide edit filename //opens filename without saving the current file | |
:sbuffer n // same as buffer but opens in split window | |
:set fileformat=unix, dos, mac | |
:set fileformat+=dos // use 'ff' for 'fileformat' | |
:split file_name | |
:split . ctrl-ww // switch between 2 splited windows | |
:lcd /etc | |
:set path+= | |
// special characters in vim : . * [ ] % / ? \ ~ $ | |
ctrl-T (or) ctrl-right mouse click (or) :pop // To come out of a tagged location | |
// (th use mouse, :set mouse=a) | |
ctrl-] (or) ctrl-left mouse click (or) g-left mouse click // To go to any tag | |
:mksession vim.vim | |
:store vim.vim | |
:vim -S vim.vim | |
:set modeline=10 // for {any vim:set sw=4: any} | |
:pwd | |
:edit . // open the current directory | |
--------------------------------- | |
:pwd // displays current_directory | |
:cd /etc | |
:pwd // display /etc | |
:!sh | |
$pwd // display /etc | |
$exit // return back to vi | |
:cd - // return to previous directory | |
----------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment