Skip to content

Instantly share code, notes, and snippets.

@andreibosco
Last active May 16, 2020 23:35
Show Gist options
  • Save andreibosco/3c8d3d7b9e3346926e9bdeb8fd972461 to your computer and use it in GitHub Desktop.
Save andreibosco/3c8d3d7b9e3346926e9bdeb8fd972461 to your computer and use it in GitHub Desktop.
Vim tips

VIM - Useful stuff

Plugins

Usage

Guides

(Most of the stuff in here comes from these guides)

Tips

General

  • The standard Vim Leader key is the \ character.
  • Close all buffers and quit: :qa
  • Save all buffers and quit: :wqa
  • To run terminal commands: :!command

Navigating tabs

  • New tab: tabnew or CTRL+t (if using my .vimrc file)
  • Close tab: tabc
  • Next tab: gt
  • Prior tab: gT
  • Numbered tab: tabnumber gt
  • Close all other tabs: :tabo or :tabonly

Window/splits

Splitting

  • Ctrl+W v: split vertically
  • Ctrl+W s: split horizontally

Navigating

  • Ctrl+W hjkl: change focus of current windows split
    • hjkl are the keys that vim uses instead of the arrow keys (h = left, j = bottom, k = up, l = right)
  • Ctrl+W HJKL: move current window split
    • Note the uppercase, meaning you have to use shift+h, for example.

Adjusting size

  • Ctrl+W +/-: increase/decrease height (ex. 20+)
  • Ctrl+W >/<: increase/decrease width (ex. 30<)
  • Ctrl+W _: set height (ex. 50_)
  • Ctrl+W |: set width (ex. 50|)
  • Ctrl+W =: equalize width and height of all windows

You can also use the resize commands:

  • :resize [+-]N: resize a horizontal split, increasing or decreasing height by N characters.
  • :vertical resize [+-]N: resize a vertical split, increasing or decreasing height by N characters.
  • :resize N: resize a horizontal split, setting height to N characters.
  • :vertical resize N: resize a vertical split, setting width to N characters.

Plugins commands

vim-multiple-cursor

To make a basic selection, use the Ctrl+N keystroke in normal mode, followed by a motion:

  • c – change text.
  • I – insert at start of range.
  • A – insert at end of range.

More actions can be found in the plugin’s quick start information.

vim-eunuch

This cryptically-named plugin adds a dozen core Unix file operations as Vim commands in the context of the current file.

:Rename new_name.sh
:Chmod +x
:SudoWrite

surround

It's easier to just check the project examples: https://github.com/tpope/vim-surround

git-gutter

To jump between changes and stage/discard individual hunks:

  • ]c: GitGutterNextHunk
  • [c: GitGutterPrevHunk
  • <Leader>hs: GitGutterStageHunk
  • <Leader>hu: GitGutterUndoHunk

NERD-commenter

  • Leader+cc: Comment out the current line or text selected in visual mode.
  • Leader+cn: Same as cc but forces nesting.
  • Leader+c<space>: Toggles the comment state of the selected line(s). If the topmost selected line is commented, all selected lines are uncommented and vice versa.
  • Leader+cm:Comments the given lines using only one set of multipart delimiters.
  • Leader+cs:Comments out the selected lines with a pretty block formatted layout.

Ack

Search pattern in files.

  • :Ack [options] {pattern} [{directories}]

Auto-pairs

https://github.com/jiangmiao/auto-pairs

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