Editing like a Vi person

Fang Jin
4 min readAug 19, 2022

Ok, this is the second one in the series, following Move around like a Vi person. There’s no way we can call it an editor without putting new characters to the screen, so let’s stopping moving around and try to edit the existing paragraph.

Photo by Nubelson Fernandes on Unsplash

Enter the INSERT mode

Notice we have been moving around with commands, so we are in the command mode, or NORMAL mode. To edit, we need to switch to a INSERT mode. Type the letter i , voilà now you can start to type like without Vi.

I love typing, so I type type type.
^ start here
I love typing, so I type type type.
_ switch to insert
I love typing, so I type type type.
_ add a space

Notice your cursor shape changes from a solid shape to a flashing line, indicating you can type. And in this INSERT mode, you are set to be free. What does that mean? You can do whatever you do with your keyboard before, type some characters, and hit RETURN, they all work again. Amazing?

Exit the INSERT mode

In the INSERT mode, sooner than later you will discover a small catch. You can’t move around as before using the commands, such as j. But you might revert back to use the arrow keys, since you find those keys actually work.

If you want to get back to the NORMAL mode, you can hit a special key ESC. Now your j works again, you can move around with all you have learned in Moving around like a Vi person.

Now you officially enter the Vi kingdom. Switching back and forth between NORMAL and INSERT, is basically what Vi is about. You might be thrilled about two modes being superior than one mode, but you will soon to discover the cost of switching in between. Therefore I wouldn’t say this will be an exciting journey, but it will be an interesting one.

More ways to enter INSERT

Normally these are the brutal forces to switch between INSERT and NORMAL mode:

i
enter INSERT mode from NORMAL mode
ESC
exit INSERT mode back to NORMAL mode

Why I say the above are brutal force is that, there’re other soft ways entering the INSERT mode from the NORMAL mode depending on the situations:

i
insert before the cursor
I (shift+i)
insert at the start of the line
a
insert after the cursor
A (shift+a)
insert after the end of the line
o
insert a new line below the current line
O (shift+o)
insert a new line above the current line
ea
insert at the end of the current word

You can do A to append to the end of the line, which is really common. The capitalized O is also quite often, if you want to start a line above the current line. If you do lower letter o instead, it will insert the line below. Both are quite handy to do insert quickly. Last but not least, ea is an eye-opener, it’s actually the combination of e and a where e moves to the end of a word similar to w and a inserts after the cursor. This is where you can see the emerging of combos. You might discover more when you are using Vi.

More ways to exit INSERT

When we are done with the editing, we want to go back to the NORMAL mode, we do a ESC. However there’s not many variations to exit than enter. I don’t know why yet.

We do have some alternatives, but more or less they are just replacement for Esc:

Ctrl-[
enter NORMAL mode
Ctrl-c
enter NORMAL mode
jk
remap the commands

To avoid the travel time by the left hand, instead of hitting Esc, we can hit CTRL, then we have two other commands to help us to enter NORMAL mode. One is c, and another one is [ . The former uses the left hand, while the latter uses the right hand. Both are not as intimidating as ESC , however not as dramatic as ESC as well. So I guess it’ll be your style to use whichever.

There’s a third way which I’ll go in more detail in the future, that is, the remapping of the commands. For instance, we can remap the combo of j and k to simulate the ESC. What does that mean? It means if you hit j and k quickly in a row, you can pull the trick of doing Esc. Of course this requires some settings changes.

Hitting Esc might be fun if you do couple of times a day, but when you have to do this one hundred or one thousand a day, it starts to become painful. To keep it sane, you really should give yourself a reason before switching from one mode to another mode, for instance, can you at least reduce the number of times switching between modes? This is a question

Summary

Now you can move like a Vi person and edit like a Vi person, you are literally a Vi person. Please have some fun, keep in mind, it’s all about practice and explore the best way you can to make it work for you. Once it does, it makes you cool.

--

--

Fang Jin
Fang Jin

Written by Fang Jin

Front-end Engineer, book author of “Designing React Hooks the Right Way” and "Think in Recursion"

No responses yet