Skip to content

This repository is intended to offer a comprehensive and practical guide for those who want to integrate the powerful capabilities of Vim into their workflow within Visual Studio Code. The cheat sheet provides key details, tips, and settings to maximize efficiency while programming.

Notifications You must be signed in to change notification settings

CarlsRemy/VimVsCode-Cheats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 

Repository files navigation

Vim VsCode Cheats Sheet

Introduction

In this document, I'll share my Vim learnings for the VS. Code, as well as any tips I find useful about that tool or extension.

Also remember to check the official documentation VSCodeVim or the next page to understand vim better Vim Tips

First advice or clarification

The letters change their behavior depending on whether they are uppercase or lowercase. By using Shift we tell vim not to add any modifiers to the Operator, otherwise with lower case it will wait for a second and even a third parameter for its execution.

As an example of this we have D. where pressing d with Caps Lock active or pressing d and Shift will cut the text from the pointer position to the end of the line, where doing it with lowercase d will do nothing until the same key is pressed a second time or a modifier is passed (w of word, s sentence, p of paragraph among others)

Tip

If yours is not so much theory but practice, you can visit these websites and learn in a more interactive way: Vim Snake, Vim Adventures, Vim Genius.
I also recommend this free Vim course taught on Udemy.

Modes

Normal is the default mode of files when opening them for the first time. this is read only, since with this we can only cut with X, C, S and D
Insert It is the way that allows us to edit it. Crtl + c is blocked, if we press this we will only change to normal mode. this mode is activated from Normal mode with the i key or Insert key
Visual this is useful to make selections of words or fragments of a phrase, it is activated from Normal mode with v
Visual Inline this is useful for making selections of entire paragraphs, it is activated from Normal mode with V
Visual Block this is useful for making Text Block selections, it is activated from Normal mode with Ctrl + v
Replace as its name indicates, it is to replace the text, it is activated from the normal mode with R or by pressing the Insert key from the insertion mode

Movement / Displacement

h allows us to move to the left. we encode the amount of characters that we will move with numbers
4 h will move us 4 positions to the left
j it would be the same as with h but moving down
k we'll move up
l we'll move to the right
g j this would be the same as j
g k this would be the same as k
g g we move to the first line, but we can also modify the line we go to
8 G positions us on line 8, if it does not exist it directs us to the last line
G it moves us to the last line, if it allows a numeric modifier
[ [ we move to the first line. does not allow numeric modifier
] ] we move to the last line. does not allow numeric modifier
H we scroll to the visible top of the screen, it would be the same as pressing the Page Up key
M we move to the visible central part of the screen
L we scroll to the visible bottom of the screen, it would be the same as pressing the Page Down key
0 moves to the first character of a line, of the line we are on
^ moves to the first character of a non-blank line, of the line we are on
$ moves to the last charcacter of a line, of the line we are on
_ moves to the first character of a line, of the line we are on
g _ moves to the last character of a non-blank line, of the line we are on
- moves up positioning it self in the first character that is non-blank
+ moves down to the first non-blank character
w moves to the first letter of each word, from right to the left and when finished go down to the next line
W moves to the first letter of each word, from right to the left and when finished go down to the next line (skip special characters)
b moves to the first letter of each word, from right to left and when it finishes it goes up to the previous line. the symbols are taken as separate words.
B moves to the first letter of each word, from right to left and when it finishes it goes up to the previous line. the symbols are taken as part of the words.
e moves to the last letter of each word, from left to right the and when finished go down to the next line. the symbols are taken as separate words.
E moves to the last letter of each word, from left to right the and when finished go down to the next line. the symbols are taken as part of the words.
g b select the word under the cushion and perform a similarity search, and introduce us in visual mode
g e moves to the last letter of each word, from left to right and when finished go up to the previous line
g f will open the file that has the name of the word under the cursor. If it does not exist, the process of creating a new file will be done.
Ctrl o jump to previous location where the cursor has recently been
Ctrl i jumps to the next previous location where the cursor has recently been
( moves to the next sentence
) moves to the previous sentence
{ moves us one paragraph Up
} moves us one paragraph Down
% it moves between the start and end blocks of {},[], ()
z z scroll the line with the cursor to the center of the screen
z t scroll the line with the cursor to the top
z b scroll the line with the cursor to the bottom

Operators

operators support numeric values, moves such as k,w and modifiers. example 2 + c + i + " which can be translated as it will cut 2 lines from its position down everything that is inside "

these do not change their function when changing from lowercase to uppercase, they only stop admitting modifiers at the end of them.

c cuts a line, but does not delete it. after this we will return to insert mode.
c - cut the line from the course to the next one above it, eliminating a line break.. after this we will return to insert mode.
c + cut the line from the course to the next one below it, eliminating a line break.. after this we will return to insert mode.
d performs the same function as c but without changing modes
s cut character and return to insert mode. only accepts numeric modifiers
S cut line and return to insert mode. only accepts numeric modifiers
x cut character below the cursor. only accepts numeric modifiers
X cut character before cursor. only accepts numeric modifiers
o inserts a blank line after the line where the cursor is positioned and returns to insert mode. only accepts numeric modifiers
O inserts a blank line before the line where the cursor is positioned and returns to insert mode. only accepts numeric modifiers
y y copy line
y w copy word
p paste the copied text
~ change a character from uppercase to lowercase and vice versa. only accepts numeric modifiers
" 0 Y copy and save with name "0" in the register. to see the log read the :reg command
" 0 p Paste from 0 register. to see the log read the :reg command
2 p paste the copied text twice
g is similar to ~ but this will do the whole line instead
g u u change the entire line to lowercase
g U U change the entire line to uppercase
u undo last change. only accepts numeric modifiers
r redo the last change. only accepts numerical modifiers
. repeat last action. only accepts numeric modifiers
> > tabulate the text. we can indicate the number of lines to affect
2 > > will tabulate the text affecting 2 lines
> 2 > will tabulate the text affecting 2 lines
< < will remove a tab from the text
g p paste after cursor
g P paste before cursor
g c c make a comment in line. if it is commented, it will eliminate the comment indicators, leaving the text of this
g C C make a comment in blocks. if it is commented, it will eliminate the comment indicators, leaving the text of this
g c - comments from the current line up. we can indicate how many lines up we want to affect
g C 2 - here we indicate that we want to affect 2 lines
g c + It is very similar to the previous sentence but this one comments from the current line downwards.
J join the line where we are positioned with the line below with a space between both
g J Similar to the previous statement only this one does not add any space
g t allow us to move to the next tab. if we pass a numeric modifier to the tab that corresponds to the number we pass
g T allow us to move to the previous tab. If we pass a numeric modifier, it will move as many tabs back as we indicate.
2 g T If we are in tab number 3, it will move us 2 tabs back, this positions us in the first

Modifiers

i represents the part inside a text, example the text that is inside " "
a renders the entire text object, including "", (), spaces, tabs
s represents the sentences
p represents the paragraphs
b represents the blocks of ()
B represents the blocks of {}
t represents the tag blocks <>.for this to work we must indicate em modifier a or i before this since there is another modifier that works with the T, example: c a t cuts the content and the tag itself or text within <>
/ represents the text from the cursor position to the appearance of the search occurrence, if it is not found it will do nothing, d / fire will delete all the text found before the word fire
f represents the text from to the position of the occurrence including itself, it searches for characters
F it is similar to the previous sentence only that it looks for the previous occurrence
t represents the text from to the position of the occurrence does not include itself, it searches for characters
T it is similar to the previous sentence only that it looks for the previous occurrence
< represent that character
> represent that character
( represent that character
) represent that character
{ represent that character
} represent that character
[ represent that character
] represent that character
" represent that character
' represent that character
` represent that character

Visual mode

a w select a word
a b select block of ()
a B select block of {}
a t select tag block <>
i b select text inside ()
i B select text inside {}
i t select text inside tags <>
o moves the cursor between the last letter of the selection and the first

Search

allows us to search the current file easily. allows us to use Regular Expression (regex), which is a huge advantage over Vs Code's built-in search engine.

to search for a specific word we use < /> , it is useful when we search for words that could be contained in other words, for example sensitive and insensitive, it would be done /

/ allows you to search forwards
? allows you to search backwards
# af we are in normal mode, it allows us to search for the word under the cursor, then when it finds consistency, it allows us to scroll down between them
* performs the same function, only it allows us to scroll up
n next occurrence
N previous occurrence

Flag search

c case insensitive
C case sensitive

Commands

the commands in vim begin with ":" followers of the sentence to be executed, the vast majority are descriptive and allow abbreviations which I will indicate with [] the syllables that are optional for their operation, example: w is the abbreviation for :write , which in the document will be written like this :w[rite]

:e[dit] create or edit file. we must indicate the file after said command example :e main.js
:reg[istro] show log of whatever is copied with vim (it's different from trash )
:w[rite] save a file
:q[uit] close file. it will give an error if it finds unsaved changes
:q! ! at the end of the command causes the same to close discarding any unsaved changes
:x close and save changes
:wq close and save changes
:wa[ll] save changes to all files
:qa[ll] close all files
:tabnew open file in new tab:v
:tabn[ext] move to the next tab
:tabp[revious] move to the previous tab
:tabm[over] allows us to change the position of the tab, it goes from index 0
:tabc[lose] close current tab
:tab[only] close all tabs and keep open only the focused one
:tabdo run command on all tabs example :tabdo wq (will save and close each tab)
:sp[lit] split into two windows, top half and bottom half
:vs[plit] split into two windows, left and right
:noh[lsearch] clear search
:%s/ / / It is used to find and replace one text with another in a file. %s/Search/replace/flag where good search is the word or pattern to search for, replace the replacement obviously and flag the filter or search flag
:.! we can execute terminal commands and add the text returned by it to our file. in windows we can execute cmd commands

Flag substitution

g find each occurrence
i case insensitive
I case sensitive
c ask for confirmation before replacing.

Ranges

ranges are a good way to indicate a range of action for commands. these are written towards :.,2d where d is an operator to be executed

:% indicates that you want to affect the entire file
:.,2 this range consists of 2 parts start qwhich in this case is . which is expressed as the current position of the cursor and the 2 indicates that the range ends at line 2
:.,$ this would be similar to the previous one with the slight difference that $ implies that it will start at the current cursor position and end at the last line of the file.
:1,.-1 here it is indicated that the range begins on line 1 and ends one line before the current position of the cursor, we can also do .+1 to indicate that it ends one line below the current position of the cursor

Other curious things

Z Z close and save changes
i return to insert mode place the cursor one character before the previous position
I return to insert mode place cursor on first character
a return to insert mode place cursor on last character
A return to insert mode place the cursor one character after the previous position
e a will return to insert mode by placing the cursor on the last letter of the word in which we were positioned
g d go to the definition of the word under the cursor

Macro

Macros in Vim are used to store a series of commands that perform an action and then be able to execute the same script over and over again without having to write the same thing every time.

These are assigned a one-letter name.

q a to start recording, a macro with the name "a"
q Stop recording macro
@ a play "a" macro

About

This repository is intended to offer a comprehensive and practical guide for those who want to integrate the powerful capabilities of Vim into their workflow within Visual Studio Code. The cheat sheet provides key details, tips, and settings to maximize efficiency while programming.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published