Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 17, 2020 07:46 pm GMT

Another one short Vim cheat sheet

I've used Vim time to time for a pretty long time, but mostly it was just some simple boring tasks like to change some configuration file on the remote server through SSH. Therefore I used the rather limited capabilities of Vim like just open the file, edit few lines and save it.

But recently I set out to study Vim deeper and read nice book for this - Learn Vim (the Smart Way). In the time of reading I made small notes about Vim's capabilities I discovered, and I'd to share them here in this short post with you!

Some of topics like advanced search, or Git, or etc I missed as I didn't want to put that all to my head for now (that's too much for me for the first time). So if I missed something important for you, probably I still need to grow to your level :) And yes, if you are mature experienced Vimmer, probably, all this stuff will be not pretty useful for you, as your fingers already knows all that.

Anyway here is the short list of Vim's stuff that you can to look for when you start to dig into it.

Insert Mode:
i - insert text before cursor
a - append text after cursor
o - starts new line below cursor & insert text
<esc> - exits insert mode

Normal mode:
. - replay previous change
u - undo
Ctrl-r - redo

Visual mode:
v - character-wise
V - line-wise
Ctrl-v - block-wise

Command-line mode:
:!command - execute an external command
:h - help

Buffers:
:new - create new buffer
:ls - list all buffers
:buffer [n] - select buffer n
:bdelete [n] - delete buffer n

Windows:
:split [filename] - horizontal slit
:vsplit [filename]- vertical split
Ctrl-w h - choose left window
Ctrl-w j - choose down window
Ctrl-w k - choose up window
Ctrl-w l - choose right window
Ctrl-w v - open vertical split
Ctrl-w s - open horizontal split
Ctrl-w c - close window
Ctrl-w o - make current window the only one on screen and closes other

Tabs:
:tabnew [filename] - open new tab
:tabclose - close tab
gt - go to next tab
gT - go to previous tab

Operators:
y - yank (copy)
d - delete and save to register
c - change
p - paste

Text Objects:
w - word
s - sentence
p - paragraph
i - inner text object
a - text object + whitespace

Motions:
h - left
j - down
k - up
l - right
0 - beginning of the line
$ - end of the line
w - beginning of the next word
e - end of the next word
b - beginning of the previous word
( - previous sentence
) - next sentence
{ - previous paragraph
} - next paragraph
% - another match of (), [], {}
nG - go to n line
gg - go to 1st line
G - go to last line

Search:
/ - search forward
? - search backward
n - next search match
N - previous search match
* - search for whole word under cursor forward
# - search for whole word under cursor backward
g* - search for word under cursor forward
g# - search for word under cursor backward

Substitution:
:s/old/new/ - substitute the first match
:s/old/new/g - substitute all matches

Macros:
qa - start recording macro in register a
q - stop recording macro
@a - execute macro from register a
@@ - execute last executed macros

Fold:
zf[operator] - fold according operator (motion or text object)
zo - open folded text
zc - close fold

For now that's all! I will continue to discover the magic of Vim world, hope you too:)


Original Link: https://dev.to/gleb_the_human/another-one-short-vim-cheat-sheet-39fc

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To