Skip to content

Instantly share code, notes, and snippets.

@benmezger
Created February 25, 2019 13:07
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 benmezger/0d9c7a6cd7b04ea29269ba2234c0a1c4 to your computer and use it in GitHub Desktop.
Save benmezger/0d9c7a6cd7b04ea29269ba2234c0a1c4 to your computer and use it in GitHub Desktop.
My personal Vim cheatsheet

Vim Cheatsheet

Using Vim buffers

Closing buffers

Unload buffer [N] (default: current buffer) and delete it from the buffer list. If the buffer was changed, this fails, unless when [!] is specified, in which case changes are lost. The file remains unaffected.

:bd

Like |:bdelete|, but really delete the buffer.

:bw
Note

NOTE: a word of caution: w does not stand for write but for wipeout.

Opening buffers

By default, Vim opens a new empty buffers when using the commands below, however, if specifying <filename> where filename is the name of the file, it opens a new buffer with the existing file. It <filename> does not exist, it creates an empty file.

Note

<filename> is optional.

Create a split window with a unnamed or named buffer
:new <filename>
Will open one in the current window
:enew <filename>
Will open on in a vertically split window
:vnew <filename>
Will open one in a new tab [1]
:tabnew <filename>

Vim splits

Vim allows you to split buffers so you can easily work looking at multiple files. Vim allows the user to split the file vertically or horizontally. By default, Vim duplicates the current buffer if no filename or buffer is specified.

Takes an optional filename and opens the file in a vertical split
:vs <filename>
:vertical <filename>
:vsp <filename>
Takes an optional filename and opens the file in a horizontal split
:sp <filename>
:split <filename>

Vim split height and resize ^^^^^^

Vim also allows you to specify a custom height for your buffer.

Specify the height of a buffer by prefixing a number
:10sp <filename>
:10vsp <filename>

To resize a current split, swap position, and move them to a tabview [[Vim tabs]], vim has a few key bindings to help out.

Table 1. Keyboard shortcurts to change split shapes and position
Shortcut Action

ctrl+w _

Max out the height of the currents split

ctrl+w |

Max out the width of the current split

ctrl+w =

Normalize all split sizes (handy when resizing the terminal)

ctrl+W R

Swap top/bottom or left/right split

ctrl+W T

Break out current window into a new tabview

ctrl+W o

Close every window in the current tabview but the current one

Vim tabs

Vim Plugins

Vim-Easy-Align

From their oficial Github repository


1. See [Vim tabs] for more information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment