Skip to content

Instantly share code, notes, and snippets.

Last active Jul 1, 2021
What would you like to do?

Vim cheatsheet

Opening windows

:new [filename]

Open a new window above the current window

:vnew [filename]

Open a new window beside the current window

:split <filename>

Edit the specified file in new window above the current window

:vsplit <filename>

Edit the specified file in new window beside the current window

Moving between windows


Navigate to the window in the given direction (<C-w>j navigates down)


Move the current window in the given direction (<C-w>J moves it down)

Visual Block mode

Visual block mode allows for selecting a column of text. Unlike standard (aka characterwise) and linewise visual mode, visual block mode is likely the best tool for certain jobs and we recommend using it. Some ideal use cases for visual block mode are editing a git rebase summary

Visual block mode can be started with <C-v> from normal mode. Once started, use normal mode motions to move the highlight region.

Visual block mode uses similar mappings to normal mode, but not identical. The following is a list of the common visual block operations and their mapping:



d, or x

Delete the visual block selection




Replace all characters in the block with the next character you type


Insert text before the block


Insert text after the block

Increasing or decreasing numbers

In normal mode, typing Ctrl-A will increment the next number, and typing Ctrl-X will decrement the next number

Creating new relative files

From within Vim, new files are created like existing files are edited, via commands like :edit filename or :split filename. To persist them to disk, you need to (optionally type in contents and) persist them via :write.

Like a command prompt, Vim has a notion of current directory (:pwd lists it). All file paths are relative to it. You don't need to duplicate the path to your current file, there are some nice shortcuts for them: % refers to the current file, :h is a modifier for its directory, minus the file name (cp. :help filename-modifiers). So,

:e %:h/filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment