Saying sorry to Vim
Some time ago, I decided to stop being ignorant in the area of Vim text editor, mainly due to playing with my raspberryPi or pushing myself more into using git via terminal mainly, you have to believe me, that Vim skills are welcome not only for these use cases.
Key thing to know is that this powerful editor is available on most Linux distributions by default, if not, you can easily install it.
Do you see this... learn it once, and you are using it everywhere. There is also a crazy amount of plugins which you can additionally install, to make your flow even more pleasant.
C'mon, also as an engineer, we need to know at least how to ‘exit’ from the vi document. I believe that even basic knowledge of Vim will buy you a lot of time in your day to day work, and for sure you will look more ‘pro’.
First step
With a very fundamental level of Vim knowledge, I started to explore the quickest paths to learn more, and I have found a nice tweet, which was promoting very cool looking platform game, using which, in easy, and funny way I was able to refresh my memory, and learn more shortcuts. The name of the game is VIM Adventures, and you can find it here #highlyRecommend. After some time with the game, I started to feel comfortable with the editor once again, and in this way I could force myself more toward Vim, during my day to day work.
Gluing a short cheat sheet, base on my needs
We can't estimate how much you need to know upfront, so I didn't even want to create a collection of cheat sheet shortcuts upfront, I decided that I do it, once I face the need to use a particular feature of Vim (incremental approach to creating my personal cheat sheet). This technique is commonly known as YAGNI in software development, funny thing, but I apply this rule quite often, even in my life.
Please find below all shortcuts which I have found useful for me, for sure list is going to grow with the time (maybe good idea would be to put it in github repo 🤔).
My base cheat sheet
Help
-
:help keyword
- open help for keyword
Create/save file
-
vi {fileName}
- create/open file from Terminal -
:q
- exit without saving -
:q!
- force exit without saving (in case you have changes, which needs to be ignored) -
:wq
- save and exit -
:w
- save only
Navigation
-
h, j, k, l
- move cursor -
H
- move cursor to top of visible page -
M
- move cursor to middle of visible page -
L
- move cursor to bottom of current page -
w
- jump to the beginning of next word -
b
- jump to the beginning of the current word -
e
- jump to the end of current word -
G
- end of file -
gg
- beginning of file -
$
- end line -
0
- beginning of line -
A
- end of line + edit mode
Deletion
-
dd
- delete whole line -
dw
- delete word -
x
- remove character
New line
-
o
- insert new line below -
O
- insert new line above
Undo/reUndo
-
u
- undo -
ctrl + r
- reUndo
Find Word
-
:set hlsearch
- enable highlight search matches -
:nohlsearch
- disable highlight search matches -
:/{Word to match}
-n
navigate forward,N
navigate backward
Copy/paste terminal internally
-
v
select block -
y
copy - Press
P
to paste before the cursor, orp
to paste after
Cut/paste internally
- Position the cursor where you want to begin cutting.
- Press
v
to select characters (or uppercaseV
to select whole lines). - Move the cursor to the end of what you want to cut.
- Press
d
to cut (ory
to copy). - Move to where you would like to paste.
- Press
P
to paste before the cursor, orp
to paste after.
Select
-
V
- whole block -
v
- and navigate (usingh
,j
,k
,l
) to select part of the text
Visual features
-
:set number
- show line number -
:set nonumber
- hide number
Practicing
The most important thing of course, is to practice! At the beginning it was very hard to start, because there is a huge temptation to move back to the UI driven text editor, but with time you will cross this thin line, and then Vim becomes quite intuitive, and is going to be your ‘go to’ editor.
I’m constantly learning, and extending my knowledge in this area, I’m so excited each time, when I notice that it has an feature which I was missing using e.g. Sublime.
More sources to explore Vim
For sure, that someone else created Vim Cheat Sheet before, here you can find quite broad library of shortcuts.
Another interactive way of learning, I didn’t use it, but I believe that is worth mentioning here. It presents the editor in a very easy to digest way!
Yep, I have just mentioned this game in the post.
If you prefer to learn from video, Christopher Okhravi, has a crazy nice YT series about Vim, also I strongly recommend to check his other videos where e.g. he is explaining SOLID principles in a very precise way.
Original post: Link
Top comments (0)