Skip to content

Instantly share code, notes, and snippets.

@lourenci
Last active October 29, 2019 14:36
Show Gist options
  • Save lourenci/338f4ad9546774c0c1a75f8c54decaab to your computer and use it in GitHub Desktop.
Save lourenci/338f4ad9546774c0c1a75f8c54decaab to your computer and use it in GitHub Desktop.
Useful vim tips

Execute a command in every line matching the pattern

:g/pattern/normal command

Examples:
  • Execute a macro store in @a in every line starting with //: :g/\/\//normal @a

  • Delete every line starting with //: :g/\/\//normal dd

Folding

command effect
zi switch folding on or off
za toggle current fold open/closed
zA toggle current fold recursively
zR open all folds
zM close all folds
zv expand folds to reveal cursor
zj move to next fold
zk move to previous fold

Execute a command in all opened buffers

:bufdo <command>

Execute a command in all windows

:windo <command>

Execute a command in all the quicklist

:cdo <command>

Search only in selection

  • Select where you have to find something.
  • <ESC>
  • Prepend \%V to the search:
    • /\%Vpattern

Search for a pattern then from there for another pattern

/string1/;/string2

Repeat last ex-command

The last executed ex-command is stored in : register, thus you can execute it through the @: then @@.

Scroll windows synchronously

:windo set scrollbind

Switch vertical split to horizontal split and vice-versa

  • Switch to vertical: ctrl+w + H
  • Switch to horizontal: ctrl+w + K

Check for some already associated map

:verbose map [keymap]

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