Practical Vim Edit text at the speed of thought - xZixz/TDIL GitHub Wiki
Before June 26 2017
-
>Gincreases 1 indentation -
Asquashes$ainto a single keystroke: to the end of the line then switch toINSERT MODE -
Csquashesc$ -
ssquashescl: clear the letter then switch to INSERT MODE -
Ssquashes^C: go to the head of the line, clear the line then switch to INSERT MODE -
Isquashes^i: go to the head of the line, switch to INSERT MODE -
osquashesA<CR> -
Osquashesko: go to the upper line, insert an empty line then switch to INSERT MODE -
;repeats lastf/F{char}command -
,reverse of; -
t{char}likef{char}but the cursor stands before the matched character -
*perform a search for the word under the cursor -
dawdelete the word where the cursor stands in,awis the text object for selecting current word -
wmoves the cursor to the first character of a word -
biswin reversed direction -
emoves the cursor the end character of a word -
geisein reversed direction -
<C-a>increases the nearest ahead number by 1(default) -
<C-x>same as<C-a>but with subtraction -
dapdelete an entire paragraph,p-{motion}is for paragraph -
gU{motion}uppercase -gUUshort for uppercase a line -
gu{motion}downcase -guushort for downcase a line -
g~{motion}reverse the case -g~~reverse case of a line - when an operator command is invoked (with no motion), it acts upon the current line
-
==autoindent -
<C-o>switch to Insert Normal mode -
<C-h>delete back one character -
<C-w>delete back one word -
<C-u>delete to start of line -
t{char}motion - till character -
<C-r>{num}- in INSERT MODE - paste the register{num} -
<C-r>=- in INSERT MODE - type in the expression for expression register -
<C-v>{code}<C-v>u{code}- in INSERT MODE - insert special character -
ga- show the info of the character the cursor is standing on, including character code -
<C-k>{char1}{char2}- insert the character using Digraph -
rR- switch to Replace Mode,rreplace one single character,Rreplace multiple characters, back to Normal Mode by pressing<Esc> -
gR- switch to Virtual Replace Mode, which treats tab character as though it consisted of spaces.
July 5 2017
-
venable character-wise Visual Mode -
Venable line-wise Visual Mode -
<C-v>enable block-wise Visual Mode -
gvreselect the last visual selection -
oin VISUAL MODE go to other end of highlighted text -
itthe motion to chooseinside a tag
July 6 2017
-
{num}Ggo to the line num -
:{num}Command Line Mode: the line to be chosen -
:{start},{end}Command Line Mode: range of lines to be chosen -
:.Command Line Mode: current line -
:$Command Line Mode: line at the at of the file -
:%Command Line Mode: all the file -
:'<,'>Command Line Mode: selected text of Visual Mode -
:/{regex}/,/{regex}/Command Line Mode: choose text bases on matched patterns -
:{range}{+/-}{num}Command Line Mode: offset from the range -
zz: Scroll the screen with the cursor in the middle of the screen
July 7 2017
-
:[range]t{address}copy a range to the address -
:[range]m{addresss}move a range the address
July 8 2017
-
:[range]normal {Normal Mode Command}execute Normal Mode Command in Command Line Mode -
<C-d>in Command Line Mode shows suggestions, to move around selections -
<C-r><C-w>to put the current word at the cursor to Command Line Mode - Put
set history=200tovimrcfile to increase the number of command to be saved in Vim history -
<C-f>in Command Line Mode switch into command-line window -
!{shell-command}execute shell command in Command Line Mode -
%in command line is represents the current file name -
:shellto open an interactive shell session,$exitto return back to Vim - Can use
Ctrl-zandfgbash shell instead of above, it's easier -
:read !{shell-command}output the result of the command to buffer -
:write !{shell-command}use lines in buffer as argument of of the shell command -
!{motion}to set a selection then jump into Command Line Mode with!after the selection to prepare for:[range]!{shell-command}
July 9 2017
-
:lsshows all the buffers loaded -
:bprev, :bnext, :bfirst, :blast, :b{num}navigate to a buffer,:bp, :bn, :bf, :blare for short respectively -
:{num}bddelete a specific buffer -
[b, ]b, [B, ]Bare the same as above respectively if useunimpairedplugin -
<C-^>toggles between current buffer and last viewed buffer
July 10 2017
-
:args {arglist}put files in argument list -
:argsshow argument lists -
**wildcard used for recursing down the subfolers -
:args \command`output the command result toargs` -
:eread file from disk back into the buffer -
:qaclose all windows -
:wawrite all modified buffers to disk -
<C-w>ssplits the current window horizontally -
<C-w>vsplits the current window vertically -
sp {file}splits the current window horizontally, loads{file}into the new window -
vsp {file}splits the current window vertically, loads{file}into the new window -
<C-w>wcycles between windows -
<C-w>{h,j,k,l}Focus the window with directions -
clor<C-w>ccloses current active window -
onor<C-w>okeeps only current window -
<C-w>=equalizes width and height of all windows -
<C-w>_maximizes the height of current active window -
<C-w>|maximizes the width of current active window -
{n}<C-w>_sets current active window height tonrows -
{n}<C-w>|sets currents active window width toncolumns - Watch screencast on Vimcasts.org: http://vimcasts.org/e/7 to know more about the possibilities of rearranging windows
-
:tabe {filename}opens file in a new tab -
<C-w>Tmoves current window into a new tab -
:tabccloses current tab -
:tabokeep only current tab -
:tabn {n}or{n}gtswitches to tab page numbern -
:tabnorgtswitches next tab page -
:tabporgTswitches previous tab page -
:tabmove {n}move current tab to thenposition
July 11 2017
-
:pwdsame usage aspwdin bash shell -
%:h <Tab>in Command Line Mode is expanded to current relative buffer path -
%%same effect as%:h <Tab>if set acnoremapin.vimrcas in Vim-tips.md -
:set path+={path}add more paths for:find,**can be used for all subfolders -
:find {filename}open file searched in paths set above -
rails.vimis the plugin for RoR development:https://github.com/tpope/vim-rails -
:e.opens file explorer for current working directory -
:Eopens file explorer for the directory of the active buffer -
:Sexplore:Vexploreopens file explorer in a horizontal and vertical split window respectively - When writing a buffer to nonexistent directories (use
:e {filename}to create a file), make the directory by:!mkdir -p %:hfirst, then:w - When editing a file, then save but you don't have permission (need root permission), user this command in Command Line Mode:
:w !sudo tee % > /dev/null
July 12 2017
-
g{motion}applies motions on display lines, motions can bej,k,0,^ -
^goes to first non blank character of the line -
W, B, E, gEsame effects asw, b, e, gebut on WORD-wise, while the downcase ones effect on word-wise -
t{char}places the cursor before the occurrence of the{char}- often used withd{motion}orc{motion}
July 13 2017
-
/{chars}searches for thechars, a specialmotion, is an exclusive motion - the character the cursor standing on is excluded from the operation -
a,iin text object stands forall,insideof the range of selection using text object. - Coming after
a,iin text object are),{,],>,\,". They are the delimiters of the text object. -
{a,i}ttext object of data in a xml tag -
{a,i}bsame for{a,i}) -
{a,i}Bsame for{a,i}{ -
{a,i}wtext object for current word -
{a,i}Wtext object for current WORD -
{a,i}stext object for current sentence -
{a,i}ptext object for current paragraph -
m{a-zA-Z}issues a mark, lowercase marks used for local buffer, uppercase marks used for global. -
'{mark}jumps to the marked position -
`{mark}jumps to the marked line, stands the first non-blank character -
``positon before the last jump within current file -
`.location of the last change -
`^location of the last insertion -
`[Start of last change or yank -
`]End of last change or yank -
`<Start of last visual selection -
`>End of last visual selection -
%jumps between sets of parentheses:(){}[]... - Use
matchit.vimto have more matches using%, likedef/endin Ruby - Use
surround.vim(https://github.com/tpope/vim-surround) to:-
S{parenthese}in Visual Mode wrap a selection inparenthese -
cs{parenthese}{parenthese}stand cursor in side a block wraped by a pair of parentheses, replace by new pair or parenthese
-
July 14 2017
-
<C-o>,<C-i>jumps back and forth between two files -
(,)jumps to start of previous/next sentence -
{,}jumps to start of previous/next paragraph -
H,M,Ljumps to top/middle/bottom of screen -
gfjumps to the file name under the cursor -
<C-]>jumps to definition of keyword under the cursor -
'{mark},`{mark}jumps to a mark -
<C-i>and<Tab>are the very same, map one key will effect the other key
July 15 2017
-
g;,g,moves cursor back/forth to the last change in the change list -
gimoves cursor back to the last INSERT MODE buffer and switchs to INSERT MODE -
?{pattern}searches pattern backward (reverse of/) -
#is reverse of* -
gfopens the file with the name under the cursor -
:set suffixesadd+={filesuffix}to specify one of more file extensions forgfcommand - Installs
bundler.vim(https://github.com/tpope/vim-bundler) for Ruby project paths - Installs
vim-ruby(https://github.com/vim-ruby/vim-ruby) for for Ruby file-type which handles the setup ofsuffixesaddandpath. - Mark
mVfor the~/.vimrcfile - Mark
mMfor the file we stand before travel far - Try to get into a habit of setting global mark before using any commands that interact with the quickfix list, and commands that interact with buffer and arguments lists
July 16 2017
-
xpthis combo can swap position of two characters standing next to each other -
ddpcombo swaps two consecutive lines -
yypcombo duplicates a line and place after current line -
"{register}to choose a register toy - yank,d - cut, ... andp - put -
""is the unname register -
"0is the yank register that contains the text usingy - yank - When use an uppercase for register name, it appends text to the specified register, not overwrite
-
"_is the black hole register which returns nothing, which can be helpful fordcommand with the purpose of not overwrite the unname register -
Pputs the content of the register before the cursor -
"+register is synced with OS's clipboard, write data to it, data will go to OS's clipboard; get data from it, the data is from Os's clipboard -
"*register is synced with X11 windowing system, its name isxterm_clipboardwhich can see its availability in:versionwith a+before its name, otherwise- - These are read-only registers whose values are set implicitly by Vim:
-
"%Name of the current file -
"#Name of the alternate file -
".Last inserted text -
":Last Ex command -
"/Last search pattern
-
-
pa selected region in VISUAL MODE will replace the selected region with the content in register, also write selected region to unname register - Use
<C-r>{register}in INSERT MODE to consistentlyp- puts the text in the register after the cursor position -
gpandgPput the cursor at the end of pasted text instead of at the beginning aspandPdo - When pasting the text using system paste command with Vim started with no setups (original state), Vim acts as though each character has been typed by hand. It may mess up the text in many ways, like if
autoindentis on, each line of text may wander further and further to the right. It will not happen if we setpasteption. - We can toggle the
pasteoption by set a key like<f5>to it by the Ex command::set pastetoglle=<f5> - The best way is to avoid toggling
pasteoption by using"+register instead. Pasting from system clipboard can be done by"+p
July 17 2017
Fucking do nothing
July 18 2017
Another day fucking do nothing
July 19 2017
Another fucking day fucking do nothing
July 20 2017
YOU 'VE JUST DOMINATED THE FUCKING DO NOTHING DAYS STREAK
July 21 -> 23 2017
K. LET CELEBRATE A WEEK OF DO NOTHING, LOSER.
July 24 2017
-
q{register}records a macro, saves macro to{register} -
@{register}executes the macro at{register} -
@@reexecutes the last most recent invoked macro -
{num}@{register}executes the macronumtimes. - When a motion fails, like
jat the last line of the file ornwhen already at the last matched word, the macro aborts. Take this as a feature, not a bug. Put a big number before{num}@{register}so that we do not need to care how many times the macro repeats but just know it's a number that can cover all the file. - You can record the
{motion}.as a convenient macro for reapeating. The most nicely register to use for this purpose isq. It can be translated asqqto record,@qto repeat and22@qto fast repeat with a big number. - When you use
{num}@{register}, the macros are executed by sequence while using VISUAL MODE then apply the register, the macros are executed in parallel
July 25 2017
-
q{uppercased-register}to append keystrokes toregister -
:sourceor:soto source a.vimfile -
:argdo normal @{register}applies the macro to all files. When record the macro the first time on a buffer, resist the urge to save the file with:wfor turning back the original state of the file (before we record the change) by using:e!(:edit!). Then the command to apply the macro to all files will not apply to the first buffer twice - To execute the macro on files in series, append
:nextcommand in the macro. Then use{big-enough-number}@{register}. In applying the macro on files, in most cases, it's better to apply in series so that you can identify the error quickly -
wall: apply:wto all files -
:let {variable}={value}assigns thevalueto thevariable, then thevariable's value can be insert to the document through expression register -
:echo {variable}to print out the value ofvariablein COMMAND LINE MODE -
:put {register}to print out the content of the register. It always prints the content below the cursor and in a new line - Macro in a register can be printed out, then editted and yanked back to the register.
- Setting
ignorecasefor enabling Vim's search patterns case insensitivity - Enable
smartcasewill overrideignorecase. Whensmartcaseis set, if your search pattern got any uppercase character, your search pattern will be case sensitive, if your search pattern is all lowercase character, your search pattern will be case insensitive. - Appending
\c,\Cat anywhere of your search pattern will override the two options above.\cis for case insensitive,\Cis for case sensitive - Start a search pattern with
\vto treat regular expression almost same way as Perl, Python or Ruby which no need to escape special meaning character -
\xin Vim regular expression is short for[0-9a-fA-F](hex character).
July 26 2017
-
\V-very nomagic- means that in the pattern after it, only the back slash has a special meaning - As a general rule, use
\vfor regular expression search, user\Vfor verbatim search -
\_sis stand forspacein Vim regex -
<>in Vim regex are delemiters for word boundary. It matches the exact word of the pattern, not inside any longer word - To use parentheses in Vim regex without capturing it, add
%before the parentheses -
g*andg#perform searches like*and#but without word delimiters -
zsandzeare used for "crop" the match from a pattern,zsstands for start,zestands for end stands for start,zestands for end - Even for
\Vsearch, there are characters that needs to escape:\,/- in forward search,?- in backward search - In expression register prompt, we can use
escape({string}, {char})to programmatically escape thechar. To serve the purpose above, we can useescape({register}, '/\')for forward searching, andescape({register}, '?\')for backward searching
July 27 2017
-
Ntraverse search in inversion ofn -
?same function as/but backward - Vim uses the last search pattern if we do this
/<CR>or?<CR> - Disable
wrapscanto search to the end of the document without wrapping around - To 'unset' an option, use
:set no{option}, addnoprefix tooptionor:set {option}!, append suffix!tooption -
:nohin short of:nohlsearchwill turn off hightlight temprorarily until the next search -
<C-r><C-w>autocompletes the searc field using the remainder of the current preview match -
:%s///gnto echo out the number of matches.%sactually issubstituebut the option/nsimply makes it ignore the replace and count only - Append
/eafter a pattern to put the cursor at the end of the match after each move - it's an search offset -
q/to open a buffer window of history of search patterns, you can use all the power of editing of Vim there
July 28 2017 - no progress this day
July 29 2017 - no progress this day too
July 30 2017 - no progress this fucking day too
July 31 2017
- Install
vim-visual-star-search: Github for using*to search for selected word
August 1 2017
-
:[range]s[ubstitute]/{pattern}/{string}/[flags]is the syntax of subtitute command -
gflag isglobally, causing it to change all matches within a line rather than a single occurence -
cflag isconfirm, to ask for rejecting each change -
nflag is for showing the number of ocurrences -
eflag is to silence the error when matching likePattern not found.error -
&flag tells Vim to reuse the flags from the previous substitute - Special characters used in search patterns:
-
\rcarriage return -
\ttab character -
\\single backslash -
\1first submatch -
\2second submatch (and so on, up to\9) -
\0entire matched pattern -
&entire matched pattern -
~string from previous invocation of:substitute -
\=evaluate expression, use result as replacement
-
- To search all file use
%sand\gflag,%is the range for entire file -
<C-e>scrolls the screen up -
<C-y>scrolls the screen down - When use
\cflag in substitution, Vim will ask us to respond to each of the matches:-
y- substitute this match -
n- skipp this match -
q- quiting substituting -
l- substitutes this match then quit -
a- substitues this and any remaining matches
-
August 2 2017
-
<C-r>/at the command line pastes the contents of the last search register if you want to complete the search command instead using blank search pattern for the latest search pattern. - In the replacement field, the
\=item tells Vim to evaluate a Vim script expression. In Vim script,@{register}refer to content of a register. -
:let @{register}=assign the{register}value - In combination, we can use this:
:%s//\=@a/gto use the pattern in\register for search pattern and content inaregister as the replacement field -
g&repeat the last search with%appending at the start, means repeat the last search across the entire file -
gvreselects the last selected block, switch to Visual Mode -
:&repeats the last substitute without flags -
:&&makes a complete combo for redo a substitute command - Substitute command can be used do move
submatches in match pattern usingcapture-\{num} -
submatch({register})returns the value ofregisterin Vim script expression - Abolish.vim is a terrific plugin should read
-
:vimgrepis a built-in search engine in Vim, the output will go into aquickfixlist, which can be viewed by:copen, usage: `:vimgrep {pattern} {file_range} - Install qargs.vim to use
:Qargsto populate file names from:vimgrepcommand to argument list - Use
:argdoto apply substitution on all file in argument list
August 3 2017 Fucking do nothing again - loser needs to double it tomorrow
August 4 5 6 2017 - you were forgiven
August 7 2017
-
:[range] global[!] /{pattern}/ [cmd]is the syntax of:globalcommand - Default
rangeof:globalcommand is entire file (%) -
:gis short for:global,:vis short for:vglobalwhich applies command the lines which do no match thepattern
August 8 2017
-
:g/{pattern}/[range][cmd]is the general form of the command of:g/{start}/ .,{finish} [cmd]which will apply thecmdfor each block from{start}to{finish} -
:g/{pattern}/sil- addsilassilentto mute all the messages echoed bycmd -
:set tags?inspects where Vim looks fortagsfiles -
:!ctags -Rgeneratestagsfile in Vim - Create a mapping for invoke
ctags::nnoremap <f5> :!ctags -R<CR> -
:autocmd BufWritePost * call system("ctags -R")to setup autocommand that invokesctagsevery time saving changes to a file - Also must visit Effortless Ctags with Git to set up hooks for
post-commit,post-mergeandpost-checkout -
<C-]>makes cursor jump from the keyword under the cursor to the definition -
<C-t>back to the previous definition in tag history -
g<C-]>shows a list of choices form the tag match list then enter the number(destination) to jump to the definition -
:tnext,:tprev,:tfirst,:tlastfor jumping around matching tags -
]t,[tare recommended to use than above,umimpaired.vimis needed -
:tselectprompts user to choose an item for the tag match list -
:tag {keyword}to jump to the first tag that matches -
:tjump {keyword}prompts user to select from multiple matches for{keyword} - 2 above can use regular expression in
{keyword}, and can usetabfor autocompletion, sometime it's faster than moving the cursor to the text then use<C-]> -
:popreverses through the tag history -
:tagadvances through the tag history
August 9 2017 do nothing day AGAIN, you should be ashamed of yourself
August 10 2017
-
:maketo compile C code using Vim Command Line, if there are errors, Vim will jump to the first error. -
:make!will keep the cursor where it is, and not jump to the error -
:cnext-:cnjump to next item in quickfix list -
:cprev-:cpjump to previous item in quickfix list -
:cfirst- jump to first item in quickfix list -
:clast- jump to last item in quickfix list -
:cnfile- jump to first item in next file -
:cpfile- jump to last item in previous file -
:cc N- jump tonth item -
:copen- open quickfix window -
:cclose- close quickfix window -
:colder- revert to an older version of quick fix list -
:cnewer- revert form and older version to a newer one
August 11 2017 August 12 2017 August 13 2017 August 14 2017
August 15 2017
-
:grepwrapsgrepof bash shell, write the result to the quickfix list -
grepprgsetting specifies what to run in the shell when Vim's:grepcommand is executed -
grepformatsetting tells Vim how to parse the output from the command ingrepprg -
vim-fugitveis a plug in with usefulgrep-like program- Example:
:set grepprg=ack\ --nogroup\ --column\ $*,:set grepformat=%f:%l:%c:%m
- Example:
-
vim[grep]uses the regular expression to search in the files - Leaving the search field of
:vim[grep]empty will make the search matches every line in every file -
<C-n>and<C-p>commands invoke generic keyword autocompletion - Autocompletion prefixed with
<C-x>-
<C-x><C-n>current buffer keywords -
<C-x><C-i>included file keywords -
<C-x><C-]>tagsfile keywords -
<C-x><C-k>dictionary lookup -
<C-x><C-l>whole line completion -
<C-x><C-f>filename completion -
<C-x><C-o>Omni-completion
-
- While the auto-complete dropdown is being shown, these keystrokes can be used to interact with it
-
<C-n>uses the next match from the word list -
<C-p>uses the previous match from the word list -
<Down>selects the next match from the list -
<Up>selects the previous match from the list -
<C-y>accepts current selected match - only needed when using<Down>/<Up>to navigate -
<C-e>reverts to originally typed text -
<C-h>/<BS>deletes one character from the current match -
<C-l>undoes<C-h> -
<{char}>stops completion and insert{char} -
<C-n><C-p>combo to open the auto-complete list
-
August 16 2017
-
completeoption holds a comma-separated list of one-letter flags, whose presence enables scanning of a particular place. The default setting iscomplete=.,w,b,u,t,i -
:set complete-=ito disable scanning of included files,+=for enabling the flag -
:set spellfor flagging out bad spell words -
[sjumps to previous spelling error -
]sjumps to next spelling error -
z=open window which shows a list of spell suggestion -
{num}z=to choose the numbered suggestion without showing window -
:set spelllang=en_uswill check spelling on American way. Ex: moustache will be flagged as misspelled - If the
spelllangis not supported yet, Vim will offer to fetch and install it -
zgadd the word under the cursor to a spell file -
zwremove the word under the cursor to a spell file -
zugundoeszgorzw - Add file for spell check (add vocabulary), add
setlocal spellfile+=~{filepath}