I waited so long to write about technology! This is my first technology post and it’s about the best text editor in the world:
- Following is everything I want to write about Vim, so might be a bit long.
- You need to practice multiple times till the commands become your physical memory. Practice makes perfect! Nobody is a genius!
I envy the geeks on YouTube who could just type Vim commands and my eyes couldn’t follow. To be a geek, I have to know Vim first.
My Experience with Vim
I started to use Vim when I took the course Computer Architecture and Systems Programming in my junior year, because the only other option for an editor in terminal is Nano, which I hated a lot. I didn’t seriously wrote my
tmux.conf till the following summer. However, I didn’t improve my Vim skills afterwards, since there weren’t many scenarios to force me to, and I was pretty happy with VSCode and Sublime Text.
When I worked at GS, I used
less more than
Vim. There were few times requiring my Vim skills to edit files on a server, but far from getting more familiar with it. Though I was busy with work, I always wanted to refresh my skills on Vim when I get time.
Now is the time.
Vim or NeoVim?
TBH, essentially both behave mostly the same, but NeoVim gives me a better time. So I will write about NeoVim in the following article. ???
Fun fact: Vim stems from Vi and stands for
Vi IMproved. The prefix “Neo” in “NeoVim” signifies that NeoVim stems from Vim. But why isn’t NeoVim called “Vimim”? However, if were so, how do you pronounce this word? 😬
Note: for NeoVim, you don’t type
neovim to start it, but
nvim. Shorter and cooler, huh?
How to download and install NeoVim
For my Mac, I use
brew install nvim to install NeoVim and
brew upgrade nvim to upgrade it.
If you don’t know a command in Vim, you could always do
:help <Command>, despite your command being a key combination or plain chars.
Start Vim, insert, save, and quit
When you enter Vim with command
vim, the default mode is normal. To start typing, you need to enter the insert mode, and here is how:
o, you can insert at different places:
|a||append||after the current character|
|i||insert||before the current character|
|o||open a new line below|
And here are
|A||append at end of line|
|I||insert at start of line|
|O||open a new line above||opposite from
To go back to normal mode, you just press
In normal mode, press:
- to save,
- to quit,
- to quit w/o saving, press
- to save and quit, press
Enter; or just
Shift + ZZ, w/o “:” to enter command mode
Understand the Modes
Most users are surprised that there are so many modes in Vim: normal, insert, visual, command.
Why does Vim need so many modes while in most other editors you just click with your cursor at the desired spot and start editing? Initially it’s designed for use both from a command-line interface and as a standalone application in a GUI. Without a mouse/cursor, the user needs the normal mode to navigate around the file.
When we go into a file, rather than just editing, more often we read, select, and go to the spot where we want to edit. Thus, we need faster ways to navigate, which is what Vim is good at and why it is still used today after almost 3 decades since its initial release in 1991.
Here are what the four modes are for and how to enter them:
|Mode||Usage||How to enter||Common Commands|
|normal||navigate and enter commands||- default mode when entering vim.
- in other modes, press
|see next section ???|
|insert||edit the document, like any other editor||see last section ???link||also works in shell:
|after selecting, could
How to move your cursor around in normal mode
Again, the default mode of Vim is normal, and normal mode provides us so many cool commands!
Left, Down, Up, Right, and last edit
hjkl becauses they are the keys your right hand could reach the fastest. Once I get used to them by pressing them and moving my cursor around, they are pretty intuitive to me.
Move by one char:
To go to the position of last edit, press
move between words
W (word) moves to the start of next word
E (end) moves to the end of next word
B (back) moves to the start of last word
The difference between the three lowercase and respective capitalized commands above is how you define a word:
- the lowercase command sees a word delimited by non-alphanumeric char
- the capitalized command sees a word delimited by space
So the capitalized commands move faster than the lowercase ones.
Personally, I use
b most often.
move to a char on the current line
f<char>(find) moves to the next <char>
t<char>(till) moves to the char before <char>
Despite search successful or not, could press
; to go to the next and
, to go to the last.
To search for a prev char, could
F<char>, which is equivalent to
move to the start/end of current line
0moves to first char
^moves to first non-whitespace char
To move to the end of current line, could:
$moves to last char
g_moves to last non-whitespace char
Personally, I use
$ most often. To avoid remembering
g_, I would press
0 and then
w to move to the first non-whitespace char, and press
$ and then
b to move to the last non-whitespace char.
move between sentences/paragraphs (not used often)
)to move between sentences
}to move between paragraphs
could use easy-motion …
move to start/end of document and last edit
gggoes to the start of document
Ggoes to the end of document
To go back to position of last edit, could do
Ctrl + O.
move to the head/middle/bottom of a page
On a screen,
H(Head) goes to the head
M(Middle) goes to the middle
L( Low) goes to the bottom
move pages up/down
Move by half page:
Ctrl + U(Up) goes $\uparrow$
Ctrl + D(Down) goes $\downarrow$
Move by full page:
Ctrl + B(Backward) goes $\uparrow$
Ctrl + F(Forward) goes $\downarrow$
zz positions the current line to the middle of screen.