Skip to content

Instantly share code, notes, and snippets.

@cheeze2000
Last active December 21, 2023 12:43
Show Gist options
  • Save cheeze2000/ae9a32465667c81427396dfea9c959f3 to your computer and use it in GitHub Desktop.
Save cheeze2000/ae9a32465667c81427396dfea9c959f3 to your computer and use it in GitHub Desktop.
My Vim Cheat Sheet

This cheat sheet is very opinionated and it summarises keymaps that I find important and useful. These keymaps are default keymaps which means they work out of the box with Vim as well as Vim extensions on other editors.

This cheat sheet also contains examples where I would showcase how I use these keymaps.

Key Bindings

Note: C-a denotes Ctrl + a and {...} denotes a parameter. Although my key bindings don't really use Ctrl a lot, I still recommend mapping Ctrl to a convenient key, such as Caps Lock.

Prelude

To exit from Insert mode, do C-[.
To exit from Visual mode, do v.
To exit from Visual Line mode, do V.

From this point onwards, "Visual mode" will refer to both Visual and Visual Line modes.

Left-right Motions

Key Description
h left
l right

Up-down Motions

Key Description
k up
j down
gg go to first line
G go to last line

Text Object Motions

Key Description
e one word forward
b one word backward

Pattern Searches

Key Description
/{re} search for pattern
* search for identifier under cursor
n next search result
N previous search result

Various Motions

Key Description
% Find matching parenthesis, bracket or brace

Scrolling

Key Description
C-d scroll down
C-u scroll up

Inserting Text

Key Description
A append text at end of line
i insert text before cursor
I insert text at start of line (ignoring whitespace)
o open new line below cursor
O open new line above cursor

Deleting Text

Key Description
x delete character under cursor
d delete (in Visual mode)
daw delete word
dd delete line
D delete until end of line

Copying and Moving Text

Key Description
y yank (in Visual mode)
yy yank line
p put after cursor
P put before cursor

Changing Text

Key Description
r change character
s delete character and enter Insert mode
c change (in Visual mode)
ce change until end of word
cc change line
C change until end of line
< left indent (in Visual mode)
<< left indent line
> right indent (in Visual mode)
>> right indent line

Visual Mode

Key Description
v start or stop highlighting characters
V start or stop highlighting lines
C-v start or stop highlighting a rectangular area

Repeating Commands

Key Description
. repeat last content change

Undo or Redo Commands

Key Description
u undo
C-r redo

More Stuff

Text Objects I use these a lot but didn't put them in this cheat sheet because I want this cheat sheet to be less intimidating.

Examples

This is a must-know!

/* from this */
p {
  font-size: large;
}

/* to this */
p {
  color: pink;
  font-size: large;
}

/* o color:␣pink; C-[ */

I use e and b for horizontal navigation a lot. There might be other better ways but I consider this the most intuitive for me.

-- from this
require("config.def").setup()

-- to this
require("config.abc").setup()
require("config.def").setup()

-- yy P e e e b ce abc C-[

Text objects are awesome.

// from this
const xs = [0, 3, 6];

// to this
const xs = [0, 6, 12];

// ci[ 0,␣6,␣12 C-[
// from this
System.Collections.Generic.List

// to this
List

// d3f.
@abstraq
Copy link

abstraq commented Apr 6, 2022

poggers.

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