Skip to content

Instantly share code, notes, and snippets.

@MikyStar
Last active January 7, 2020 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikyStar/16e23e0b4c28dc4fb0a38e3b099d5e51 to your computer and use it in GitHub Desktop.
Save MikyStar/16e23e0b4c28dc4fb0a38e3b099d5e51 to your computer and use it in GitHub Desktop.
VIM CheatSheet

VIM CheatScheet

Default bindings

Browsing

Ctrl+W -> Enter window mode Ctrl+W, HJKL -> Browse splits Ctrl+W, R -> Rotate up/left Ctrl+W, r -> Rotate down/right

Ctrl+ww -> browse throught windows ( nerdtree, splits ... )

:# -> Go to line # #G -> Go to line # #| -> Go to column #

gt -> to next tab gT -> go to previous tab {i}gt -> go to tab in position i

f{char} -> Move to next occurence of char F{char} -> Move to next occurence of char backwards

'' -> Move to last position ( it's double single quote )

H -> Move to top of screen M -> Move to middle of screen L -> Move to bottom of screen

Ctrl+U -> Browse half screen up Ctrl+D -> Browse half screen down

Ctrl+B -> Page up Ctrl+F -> Page down

#z -> Make top of screen start at line #

Replace & Search

Between lines :#,#s/old/new/gc

:%s -> All lines of the file

Ctrl+r,"-> Paste current register to command

Terminal

:term

Ctrl+w -> Switch terminal to VIM mode ---> N -> Enter normal mode and can browse through output of terminal for instance ---> i -> Go back to terminal mode

:! % -> Execute a shell command :silent ! -> Execute a shell commmand without the need to press enter at the end :r ! -> Put the output of the command into the current buffer

Windows

Resizing

:res 60 -> 60 rows :res +5 :vertical resize 50 -> 50 columns

Splitting

:sp -> Split horizontally :vsp -> Split vertically

Ctrl+W, R -> Swap splits

Ctrl+W, HJKL -> Browse between splits VIM like Remapped to just Ctrl + HJKL => 'Window browsing'

Browse cursor positions

Ctrl + O -> backward Ctrl + I -> forward

Registers

:reg -> List all of them

"#p -> Paste content of the # register kyy -> Copy current line in register k Kyw -> Append current word to register k

:WipeReg -> Custom command to delete all registers

Specific registers :

. Last inserted text : Last command " Last register

@: -> Repeat last command @@ -> Repeat again last command

Marks

:marks -> List all marks

ma -> Put a marker named "a" at that position 'a -> Jump to mark "a" d'a -> Delete from current to line to line on mark "a" d{backtick}a -> Delete from current position to position on mark "a"

:delmarks! -> Delete all lowercase marks for the current buffer :delmarks a -> Delete mark 'a' :delmarks a-d -> Delete mark 'a, b, c, d'

Changes

:changes -> List current changes :e! -> Discard all changes

Ctrl + R -> Redo the previous undo through u

Change case

~ -> Makes selected caracter switch case 3~ -> Makes 3 next caracters switch case 3w -> Makes 3 next words switch case

Openning

:e -> Reloads current file :e Open file in current window :tabedit -> Open file in new tab :tabonly -> Close every tabs except the current one

:x -> Save and quit

Recording

qa -> Starts recording in the register a q -> Stop recording @a -> Play register a

Vimdiff

Configure Git to use it

git config --global diff.tool vimdiff git config --global difftool.prompt false git config --global alias.d difftool

Keybings

do → Get the content of the opposite line where the cursor is dp → Push the content where the cursor is on the oposite line ]c → Next diff [c → Previous diff zo → Open fold zf → Close fold

Plugins

Tabulous

Rename current tab

:TabulousRename

NerdTree

Ctrl+n to toggle

t -> Open in new Tab T -> Opens silently i -> Open in split view horizontal s -> Open in split view vertical R -> Reloads root directory r -> Reloads current directory O -> Expand recursively P -> Jump to root p -> Jump to parent J -> Go to last child

YouCompleteMe

GoTo, etc. -> Go to include/declaration/definition GetDoc -> View documentation comments for identifiers GetType -> Type information for identifiers FixIt -> Automatically fix certain errors GoToReferences -> Reference finding RefactorRename -> Renaming symbols Format -> Code formatting

Git

Vim as a mergetool

$ git mergetool -> Open vim as a mergetool to handle conflict between a merge in two branchs

  • LOCAL -> The file in the current branch
  • BASE -> The file as it was before it was modified in both branches hence the conflict
  • REMOTE -> The file as it is in the branch I'm merging into the current one

In the final merged file ( the view on the bottom ) go to a conflict and execute those commands to select what to keep :diffg RE -> Get from REMOTE :diffg BA -> Get from BASE :diffg LO -> Get from LOCAL

GitGutter

:GitGutterLineHighlightsToggle -> Change background of new/changed lines => Remapped to :Githl

:GitGutterNextHunk -> Go to next hunk => Remapped to :Gitnext :GitGutterPrevHunk -> Go to previous hunk => Remapped to :Gitprev

:GitGutterStageHunk -> Stage a hunk => Remapped to :Gitstage :GitGutterUndoHunk -> Undo a staged hunk => Remapped to :Gitunstage

:GitGutterPreviewHunk -> See what has changed for that hunk

Fugitive

:Gdiffsplit -> Make a split with hunks highlighted => Remapped to :Gitsplit

Others

:noh -> Clear highlighted stuff :tabclose -> Close current tab :messages -> Show vim messages :map -> See how keys are mapped :map key -> See what are the bindings with key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment