• Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vim Cheat Sheet, useful command and information.

Vim Cheat Sheet ๐Ÿค“

Vim Cheat Sheet, useful commands compatible with VSCodeVim for Microsoft Visual Studio Code.

Introduction

In this document, I'll share with you my Vim learnings, listing everyday commands, nouns, and movements I found useful to be more productive in everyday coding. Vim is a powerful text editor, this document is not exhaustive.

Vim as Language

Vim commands are formed from a combination of verbs and targets. The targets could be objects (words, sentences, paragraphs, lines, the contents of parentheses) or movements (jump to the end of a word, jump to end of the paragraph, jump forward until the letter โ€˜eโ€™, etc). Forming objects generally involves the use of a modifier. You can also add a count to perform the action count times.

Commands

v enter visual mode
V enter visual mode and select current line
c change
cc delete current line and then enter insert mode
C Delete from the cursor position to the end of the line then enter insert mode
d delete (remove from the document and put in buffer)
dd delete current line
D Delete from the cursor position to the end of the line
y yank/copy
yy or Y yank/copy the line
i enter insert mode
I enter insert mode at the beginning of the line
p paste the buffer after the cursor
P paste the buffer before the cursor
r[char] replace the character under the cursor [char]
R enter Replace mode
s delete the character under the curser and puts you into insert mode
S delete current line and then enter insert mode (same as cc)
x delete the character under the cursor
u undo the last command
a append and enter insert mode after the carat
A append to line (enter insert mode at the end of the line)
o open a line after the current one and enter insert mode
O open a line before the current one and enter insert mode

Modifiers

i inside
a around
t[char] till... finds a character
T[char] like t but in opposite direction
f[char] find... like till except including the [char]
F[char] like f, but in opposite direction
/ search...find a string/regex
? like / but in opposite direction

Targets (Text objects)

w word
W WORD (consists of a sequence of non-blank characters, separated with white space)
s sentence
p paragraph
b block/parentheses
t tag, works for html/xm

Nouns/Movements

Nouns or movements are commands for moving within the document or representing an area within a document.

h, j, k, l move, equivalent to the arrow keys left, down, up, right
H move to the top of screen
M move to the middle of screen
L move to the bottom of screen
zz scroll the line with the cursor to the center of the screen
zt scroll the line with the cursor to the top
zb scroll the line with the cursor to the bottom
gg go to the first line
G go to the last line
Ctrl-D move half-page down
Ctrl-U move half-page up
Ctrl-B page up
Ctrl-F page down
0 move to the very beginning of the current line
^ move to the first non-whitespace character on the line
$ move to the end of the line
w, b move to the next/previous word
W, B as w/b only Words are bigger
), ( move to the next/previous sentence
}, { move to the next/previous paragraph
/[regexp] like t but instead of finding a character, it finds a regexp
?[regexp] like /, but search in opposite direction
% jump to the matching parenthesis (vim understands nested parenthesis)
_ move to the current line (useful for making commands line-based)
#[char] jump to the previous instance of the word under [char]
>> indent line
<< outdent line
>> indent line (shift line one shiftwidth rightwards)
<< outdent line (shift line one shiftwidth leftwards)
== reindent current line
*[char] jump to the next instance of the word under [char]
ddp / ddkP are common commands to move a line one down / up

Useful

vi[char] visualize all content inside that [char] excluding delimiter
va[char] visualize all content inside that [char] including delimiter
vi{ select all content inside curly braces excluding braces
va{ select all content inside curly braces including braces
viw select world under the cursor
vit visually select text in a tag
vat visually select text around a tag
vap visually select paragraph under cursor
gc toggles line comment, example gcc to toggle line comment for the current line and gc2j to toggle line comments for the current line and the next line
gC toggles block comment, example gCi to comment out everything within parenthesis
ciw change inner word will change the whole word under the cursor
cw change the word from the current cursor position
/ enter regex search mode
n find the next instance of the search term
N find the previous instance of the search term
. repeat last change (extremely powerful)
^ or 0 move to the beginning of the line
Shift+0 move to the end of the line
Shift+i move to the beginning of the line and switch to insert mode
Ctrl-R redo the last undo (sidenote: in vim undo/redo forms a tree, changes arenโ€™t lost)
Ctrl-[ exit insert mode
Ctrl-c exit insert mode
Ctrl-ww window switching
gg=G Autoformat/indent code

Registers

Registers in Vim let you run actions or commands on text stored within them. To access a register, you type a before a command, where a is the name of a register. Please, note some of these commands are not supported by VSCodeVim yet.

:reg access all currently defined registers
"kyy copy the current line into register k
"Kyy append to a register by using a capital letter
"kp paste value of the register
"+p paste from system clipboard on Linux
"*p paste from system clipboard on Windows (or from "mouse highlight" clipboard on Linux)

Others

dat delete the current tag (and all its content)
f[char] find character and move cursor at position [char]
t[car] find character and move cursor at one position before [char]
vi[ visual select inside [
i[car] expand selection to that [char], similar including a[char]
gt move the cursor to next tab
gT move the cursor to prior tab
nnngt numbered tab
:tabonly close all tabs and keep open only the focused one
:split split into two windows, top half and bottom half
:sp same as :split
:vsplit split into two windows, left and right
:vsp same as :vsplit
:sp spit current document in two horizontally
:vs spit current document in two vertically
Ctrl-y move the screen up one line
Ctrl-e move the screen down one line
Ctrl-u move cursor & screen up ยฝ page
Ctrl-d move cursor & screen down ยฝ page
Ctrl-b move the screen up one page, cursor to the last line
Ctrl-f move the screen down one page, cursor to the first line
Ctrl-y only change the cursor position if it would be moved off-screen, same as Ctrl-e
zt move current line to the top of the screen
zb move current line to the bottom of the screen
t till, example dt. (delete till dot) or df.(delete till dot included)
Ctrl-O retrace your movements in file in backward
Ctrl-I retrace your movements in file in forwards
J joins the line the cursor is on with the line below
viwp visual select inner word and paste (change a selected word using current buffer )
"+y copy to clipboard
"+p paste to clipboard

Deleting

dw delete from the current cursor position to the beginning of the next word character
diw delete inner word will delete the whole word under the cursor
d$ delete from the current cursor position to the end of the current line
D as d$
dtX delete forward up to character X
dfX delete forward through character X
dTX delete backward up to character X
dFX delete backward through character X
:%d delete all content of the document

Change case

~ changes the case of current character
guu change the current line from upper to lower
Vu change the current line from upper to lower, like guu
gUU change the current line from lower to upper
VU change the current line from lower to upper, like gUU
guw change to the end of current word from upper to lower
guaw change all of the current word to lower.
gUw change to the end of the current word from lower to upper
gUaw change all of the current word to upper
g~~ invert case to entire line
guG change to lowercase until the end of document

Notes

  1. The quickest way to retrace your movements is to hit either: two apostrophes or two backticks. The difference is that the backtick goes to the same location on the line, whereas the apostrophe goes to the start of the line. There are loads of useful marks like this, see :help mark-motions.

  2. Move to the end of the line in normal mode in VIM: Jump to last nonblank g_ or use $ which moves to the last character on the line.

  3. You can use Ctrl-W direction to switch windows (where direction is one of the normal hjkl cursor movement keys, or the arrow keys).

  4. The focus is on the new split initially. To move between splits first press Ctrl-w.

Interesting resources

Using marks

Vim + Tmux

Mastering the Vim Language

All the right moves

Graphical cheat sheet

Vim Visual Block Mode

SpaceVim

More Repositories

1

typescript-book

The Concise TypeScript Book: A Concise Guide to Effective Development in TypeScript. Free and Open Source.
TypeScript
7,532
star
2

animatelo

Animatelo is a bunch of cool, fun, and cross-browser animations for you to use in your projects. This is a porting to Web Animation API of the fabulous animate.css project.
JavaScript
482
star
3

keyframes-tool

Keyframes-tool is a NodeJs command-line tool which converts CSS Animations to keyframes object suitable for Web Animations API. Use this tool to move your animations from stylesheets to JavaScript.
JavaScript
61
star
4

jquery-slidertv

SliderTV is an easy-to-use jQuery slider plugin optimized for Smart TV apps. Use jQuery SliderTV for controlling any HTML based content in horizontal or vertical order in a carousel-like fashion.
JavaScript
12
star
5

react-color-picker-palette

ColorPickerPalette is a React reusable color picker palette written in TypeScript.
TypeScript
9
star
6

blocchi-puzzle

A tetromino game based on React, Redux, TypeScript, and functional programming.
TypeScript
6
star
7

typescript-web-workers

How to make Web Workers work with TypeScript? This repository contains a minimal setup with a working example.
TypeScript
5
star
8

frontend-boilerplate

This project is an opinionated boilerplate which helps you build fast, robust, and adaptable single-page application (SPA) in TypeScript with React.
JavaScript
4
star
9

jjj

Minimal and fast command-line file lister with Vim key bindings.
C
4
star
10

gibbok

3
star
11

bem-pixel-perfect-responsive-design

An example of CSS pixel perfect adaptive design based on BEM methodology.
HTML
3
star
12

react-video-list

A basic "Top 10s Video List" application done in React, which I coded in a few hours as a way to pass the time on a rainy day.
JavaScript
3
star
13

notes-graphql

Notes on GraphQL
3
star
14

useful

Useful collection of Git and Linux commands
3
star
15

files-importer

files-importer is a Node.js command line tool, written in functional programming style, which synchronously copy the contents of a directory (include subdirectories recursively) to another location without creating duplicate files. It can be used to import only images and videos that have not already been imported from a camera or a memory card.
TypeScript
3
star
16

graphql-apollo-setup

TypeScript
2
star
17

dijit-select-optgroup

SelectOptgroup is a styleable, searchable drop down select box for Dojo which includes grouping of options (similar to html <select> element with <optgroup>).
JavaScript
2
star
18

image-editor

An image editor application based on React, TypeScript, and functional programming.
TypeScript
2
star
19

notes-web-vitals

Notes on Web Vitals
1
star
20

notes-next-js

Notes about Next.js
1
star
21

event-timeline

Event timeline
TypeScript
1
star
22

dojo-colorpicker

JavaScript
1
star
23

dojo-keyboard-shortcuts

Dojo Keyboard Shortcuts is an input capture module for Dojo. Whenever your application needs to detect custom shortcuts this module is for you.
JavaScript
1
star
24

javascript-faq

JavaScript FAQ is a mini collection of essential interview questions and answers.
1
star
25

notes-rxjs

Notes on RxJS
1
star
26

notes-pact

Notes on PACT contract testing
1
star
27

react-redux-weather-app

A weather application based on ES6, Flow, React, Redux, Material-UI and OpenWeatherMap's API [WORK IN PROGRESS].
JavaScript
1
star