Skip to content

Instantly share code, notes, and snippets.

@laleph
Last active May 24, 2016 14:36
Show Gist options
  • Select an option

  • Save laleph/ab4b725bf72da8efd1fed8c4581e9fad to your computer and use it in GitHub Desktop.

Select an option

Save laleph/ab4b725bf72da8efd1fed8c4581e9fad to your computer and use it in GitHub Desktop.
VIM

#Vim Cheat Sheet

  • gqip - Reformats paragraph to textwidth
  • gq - 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 mode
  • gU<movement> - Uppercases
  • gu<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 of g for global (all occurances in a line, i to ignore case, and c to 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

vimdiff cheat sheet

This is a vimdiff cheat sheet as a git mergetool.

Commands

]c          - go to next difference  
[c          - go to previous difference  

do          - diff obtain (other to current), shortened ':diffget'  
dp          - diff put    (current to other), shortened ':diffput'  

:diffupdate - re-scan the files for differences  
:diffthis   - get a diff of files on buffers (from normal mode) 
:diffoff    - return to normal mode   
zo            - open folded text  
zc            - close folded text  

Ctrl+W Ctrl+W - switch to next window  
:ls           - show windows info 

qa!         - quit all buffers  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment