May 21, 2024

getting started with Vim

People sometimes claim that vim has a steep learning curve. I both agree and disagree. You can learn enough to get started in well under an hour. To learn all the advanced features could take forever -- you can dig as deep as you like.

The usual obstacle is the modal nature of Vim. If you are used to some other visual editor (such as some form of notepad) this will be a big surprise. Just slow down, have an open mind, and work through the intoductory tutorial.

The vim tutor

First try just typing "vimtutor" at the command line. This should "just work" on any system that has vim properly installed.

If for some reason this does not work, type "vim" at the command line and then type ":h tutor".

If this does not work, you probably need to install vim, and I won't try to give advice on that. There are plenty of online resources that will tell you what to do on your specific system.

Things I learned

I've been using "vi" for over 40 years, but I just ran through the vim tutor and here are some comments.

First, absolutely train yourself to use the hjkl keys to move around. If you have some habit of using the arrow keys, you -could- continue to do that, but your hand will do a lot less moving around if you bite the bullet and learn to use hjkl.

As I worked my way through the tutorial, I realized that I don't even know what I do most of the time to edit text. I just look at the screen, my fingers do some crazy thing, and the desired result appears. This is good, because my up front concious mind stays focused on the code or whatever programming problem I am working on. I don't want to start engaging my concious mind to use vim -- I just want hot and cold running water.

Here is a play by play as I worked through the tutor.

I always use "ZZ" to save and exit vim, I am surprised the tutorial teaches :wq.

I learned about "d$" to delete to the end of a line and "de" to delete to the end of a word. I use "dd" and "dw" all the time. To delete to the end of a line, I use "D".

Original vi had only one level of undo. Typing a second "u" would undo the undo. Somewhere along the line I developed a bad habit (I guess you could call it a bad habit) of just pressing uuuuuu over and over to see my change go back and forth to verify what I had just done. Vim now has infinitely deep history and you can undo forever (or forever for all practical purposes). So my bad habit bites me severely -- I have restored the historical "vi" behavior in my .vimrc to retain my sanity.

I never use the "r" command to replace a single character -- I use the "s" command then type the new character(s) ending with ESC. I do use the "R" command to replace many characters though.

Also I never use the "ce" command, though I do often use "cw" I'll note that "cc" and "c$" are not things I often use. What is the lesson here? There are many ways to skin these cats.

I use 1G to go to the start of a file, not gg. I do use G to go to the end.

Using Ctrl-O to backtrack from a search is new to me. I use ''

Section 5.3 of the tutorial introduces visual mode (which is entirely new to me) without calling it that.

I have never used the online help (via :h or :help), but I hear no end of good things about it and it has already taught me things. Using Ctrl-D and TAB for completion of help topic names is helpful. Use :q to close the help window. Use Ctrl-W Ctrl-W to go back and forth between the two windows.


Have any comments? Questions? Drop me a line!

Tom's vim pages / [email protected]