#Vim Cheat Sheet
gqip- Reformats paragraph to textwidthgq- Reformats selection:Tab /=- Equally spaces based on the = symbol (requires Tabular vim plugin):setf language- Changes current language:set language=language- Changes current language<C-a>- Increments the number under the cursor<C-x>- Decrements the number under the cursor~- Toggles case and moves to next character in normal modegU<movement>- Uppercasesgu<movement>- Lowercases<visual>U- Uppercases in Visual mode<visual>u- Uppercases in Visual mode<C-o>- While in insert mode lets you run a single command-mode command and returns you back to insert mode:cq- Quits with an error code. (Good for canceling a SCM commit)
##Sed-style Replacements
s/<sed regex>/<replacement>/<flags><flags>- Can be a combintion ofgfor global (all occurances in a line,ito ignore case, andcto confirm each substitution
###Sed-style Regex
\?- 0 or 1*- 0 or more\+- Matches one or more\( \)- Captured grouping (can be used later in replacement with\1,\2, etc.\%( \)- Non capturing group^and$- Beginning and end of line respectively
Concept: A buffer is the in-memory text of a file. A window is a viewport on a buffer. A tab page is a collection of windows.
#cursor movement w,e,b -> word movement % -> go to matching parentheses ({[ [{, ]} -> go to ({[ *,# -> next/previous occurence of the word under cursor gg,G,11G -> begin/end, linenumber of file o,O -> insert before/after the current line dd -> delete the current line
#diff :edit file1 :diffthis :vnew :edit file2 :diffthis
#undo redo u -> undo Ctrl+r -> redo
#search :/,n,N -> find next, previous :noh -> no highlight
#replace :s/a/b/g -> replace
#mode i -> insert mode V -> visual block mode v -> visual mode : -> command mode
#block comment V -> visual block mode (select whole line) I -> insert at left esc
#copy and paste d,y -> cut/copy(yank) dd,yy -> cut/copy current line p,P -> paste before/after cursor
#exec cmd :!{command} -> run cmd :r!{command} -> get the output of the linux_cmd into current vim :sh -> start a shell
#buffer :edit {file} -> edit the file in current window :buffers/:ls/:files -> list buffers :buffer {number}/:buffer! {number} -> go to buffer :ls! -> list all hidden buffers
#tab Ctrl-w v -> vsplit Ctrl-w s -> split Ctrl-w [hjkl] -> switch focus Ctrl-w x -> exchange split Ctrl-w _ -> maximun current split Ctrl-w | -> maximun current vsplit Ctrl-w = -> split equally + / - ->change split size > / < -> change vsplit size {number}+ -> run multiple time