Question

A good while ago, I read an article by the creator of viemu, clearing up a lot of the misconceptions about vi, as well as explaining why it's a good idea (and why it's been very popular for the last 30 years+). The same guy also has a great set of graphical cheat sheets that teach the basics a few bits at a time.

I'm convinced.

I've been convinced for the past 2 years in fact. But I still really haven't gotten around to force myself to learn vi as my primary editor, the learning curve is just too high. When I get down to work, acceptable but immediate productivity (using my current editor) has so far won over tremendous productivity farther down the line (using vi).

Does anybody have any good tips to help get past the learning curve? It can be straight out tips, some other tutorial or article, whatever.

Edit: Note that I'm aware of the vim/gVim, Cream and MacVim (etc.) variants of vi. I kept my question about vi to refer to the vi family as a whole. Thanks for all the great answers.

Update (April 2009)

I've been using Vim (more precisely, MacVim) in my day to day professional life since last December. I'm not going back :-)

Good luck to everyone in their Vim mastery.

Was it helpful?

Solution

First of all, you may want to pick up Vim; it has a vastly superior feature set along with everything vi has.

That said, it takes discipline to learn. If you have a job and can't afford the productivity hit (without getting fired), I'd suggest taking on a weekend project for the sole purpose of learning the editor. Keep its documentation open as you work, and be disciplined enough not to chicken out. As you learn more, become efficient and start relying on muscle memory, it won't be as hard to stick with it.

I've been using Vim for so long that I don't even think about what keys to press to search or navigate or save. And my hands never leave the keyboard. To use Vim is one of the best choices I've made in my programming career.

OTHER TIPS

The first thing I'd do is lay a piece of paper or a book over your arrow keys and your ins/home/end/pgup/down keys. Those aren't needed in Vi.

Next I'd get used to hitting ctrl+[ whenever you're told to hit escape. It's much faster and you won't need to take your hands off the keyboard.

Then I'd watch my screencasts:

http://www.youtube.com/watch?v=FcpQ7koECgk

http://www.youtube.com/watch?v=c6WCm6z5msk

http://www.youtube.com/watch?v=BPDoI7gflxM

http://www.youtube.com/watch?v=J1_CfIb-3X4

Then, just practice practice practice.

edit The reason for avoiding the arrow keys is that they slow you down. One of the largest benefits of Vim is the speed it allows you. The arrow keys also prevent you from really embracing the modal nature, which is very powerful when mastered.

Step 0: learn to touch type. Seriously - if your fingers don't know where the keys are then vim is going to be a pain. And even if you reject vim, touch typing will improve your programming (ask Steve Yegge ) by making the mind to monitor link friction free. There is a lot of software that can help you improve your typing.

Step 1: use vimtutor to get you started. It is in gvim (under the help menu I think) or you can just type 'vimtutor' at the command line. It will take 30-45 minutes of your time and then your fingers will know the basics of vi/vim and you should be able to edit files without wanting to hurl your keyboard out of the window.

Step 2: use vim everywhere. See this question for tips and links for using vim and vi key bindings at the command line, from your web browser, for composing emails, in your IDE ... You need to use vim to embed the key bindings in your muscle memory.

Step 3: learn more about vim. You will only have scratched the surface with vimtutor. You can watch this video or read this article (both about the "Seven habits of effective text editing". You can read about tips and tricks on StackOverflow. You can browse vimtips. Learn a litle often would be my advice - there is so much out there that sticking to bite-size chunks will be the best way to make the knowledge stick.

Step 4: Profit :)

I've been a on-again, off-again user of vim throughout the years (doing the occasional sys admin job). I just recently started spending more time doing my programming work in it. I'd suggest starting with gvim too. It integrates well with most OS environments, and (even better), you can fall back to the mouse when you need to :).

To get going with vim, run through the vimtutor (bundled with gVim) once or twice (takes an hour or so). I can't overstate how helpful it was for me! Especially the first parts about the different ways to move through a document, and how edit actions are recorded with motion commands, etc, etc. After that, things will be MUCH clearer.

Then, start doing quick, minor edits with it (notepad-replacement stuff) 'till you are comfortable enough to do useful editing at a rapid clip. Then try doing your day-to-day work in it. You'll find yourself pining for the "repeat last action" command in other editors in no time!

You asked for good tips to help get past the learning curve on the vi text editor. Many of the previous answers suggest you use no other editors. I think that is good advice. Switching to vi from a more graphical editor requires a change in mindset. It requires thinking in terms of commands, rather than visual changes.

I used nothing but vi for many years and believe the only way you can be productive is to memorize the commands you regularly use. The way I did this was to make a short list of the most common keyboard commands. I grouped and color-coded these commands by function, i.e. Moving the Cursor, Editing, Searching, etc. I was careful to only include the most commonly used commands I did not know. The idea is to create a quick reference that is also an aid in memorization – not to replace the available help screens. Then I printed this list and taped it to the wall behind my monitor so I could see it easily. (The graphical cheat sheets you mentioned might work better for some, but are probably a better reference source than a memorization tool.)

Here's the key. As I became comfortable with one of the commands, I drew a line through it with a pencil. I could still see it if I needed it, but it was symbolic to me that I had mastered that command. That gave me confidence and motivation as I could see regular progress. Once I had most of them crossed off, I removed them and added some of the more rarely used commands. I continued this process until I was satisfied with my command of vi. I knew I had reached that point when I realized I had not crossed off any commands or even looked at the list in a long time.

A couple years ago I had need to work on a UNIX platform where vi was the only editor available. I bought a little pocket reference book on vi, but hardly used it. I ended up making lists and posting them on the wall as I did the first time I used vi. By the end of the first week, I was very comfortable even though it had been five years since I had used vi.

For me VI is a good emergency editor, but not something I want to use if there is any other alternative available. I realize this is not for everyone though, I'm not saying it's horrid or anything, I just personally prefer a discoverable UI.

But you really have to know VI if you do anything significant in Linux!

So just learn the basics: i=insert mode esc=leave insert mode :wq=save and quit :q!=don't save and quit x=when not in insert mode, delete the character. /=search

That will get you through any editing emergency. There is nothing you can't do with those few commands (and navigation of course). The rest you can "Tack on" as you need them.

Keep a reference or book available though--when you NEED to use VI, you probably won't be able to browse the web--but the man page may be somewhat useful.

force yourself not. the path to mastery love is.

You should start with vim (Vi IMproved) and especially its GUI - gVim. The GUI has menus and on Windows you can use the copy, cut and paste shortcuts, so you can replace Notepad immediately. And since the menus display the shortcuts (vim commands) you could learn a lot.

Another thing that you should do from the beginning is to configure vi for your needs. For example, you can transform vim into a Python IDE. By doing this, you'll have no excuse for using another editor, because vi will offer you everything you need.

delete all other text editor apps.

Then you will have to learn it.

The simplest way to force yourself might be just to remove all the other editors from your machine. Get rid of temptation :)

Every time you're doing a complex editing task, keep wondering if there is a more efficient way to do it. Most times, when it's something that you can describe in simple terms (like "swap paragraphs of text" or "delete everything after the X character in commented lines"), it's something you can do in just a couple of keystrokes in vim.

There are some key features that are extremely useful, and you'll end using all the time. The ones I love the most are:

  • Block selection (Ctrl-V)
  • Macro recording (q)
  • Virtual editing (:set ve=all)
  • Regular expressions
  • Piping to external Unix programs
  • Key mappings
  • Autocompletion (C-p, C-x C-p, C-x C-f)
  • The operation+movement combination (this is amazingly powerful)

Ask other programmers what features they find most useful and adopt the ones that fit better your brain. Steal ideas from other people's .vimrcs (here's mine)

EDIT: I've created a flashcard set over at the online spaced repetition site flashcarddb.com, in case you're interested ...

  1. Use a spaced repetition flash card program such as mnemosyne, supermemo, or anki to incorporate learning and retaining new commands into your daily routine. It's not enough to be using vim as your daily editor. To master it, you have to be storing those codes in your head, laying in wait for the time when they're the ideal solution to the task at hand.
  2. Maintain a .vimrc with customizations
  3. Write or edit a vim plugin

I wrote a guide to efficient editing with Vim a while back. You may find it helpful.

I'd step back for a minute and ask yourself "why do I want to learn this editor? What makes me think it'll be faster or better than my current text editor?" Then learn those features that will make Vi(m) indispensable to you.

For instance, Vim's CTags integration is completely indispensable for me. I work with a very, very large codebase, and the ability to jump to a function or class definition in one keystroke (regardless of which file it's in) is an absolutely killer feature, one I have trouble working without.

Use your .vimrc file to make macros that automate common tasks.

Your autopilot editor-chooser will pick the editor that will get the job done quickest and with the least amount of mental effort. A little prep-work will ensure that editor is Vim. :-)

Two things that will greatly improve your vi skills:

  1. Practice, practice, practice
  2. Nethack

My suggestion: start small. Just start by memorizing a small set of most useful commands. When I started vi, these were my top 10:

  • (Esc) to return to command mode (most important!)
  • a to add text after cursor
  • A to add text at end of current line
  • x to delete 1 character
  • dd to delete 1 line
  • R to replace text (overwrite)
  • u to undo
  • :q! (Enter) to quit without saving
  • :w (Enter) to save
  • ZZ to save and quit

A lot of basic editing can be done using only these commands. Once you get comfortable, the rest don't look too difficult.

BTW, I'd like to add that I used to rely on vi for my primary text editor, but now only if I have to. In my case, productivity is better when I use tools like Emacs or Visual Studio (please note: "in my case"). Try more than one tool and choose the one that helps your productivity the most. Good luck!

It sounds silly, but playing roguelike games (such as Nethack or Angband) is a fun way to get comfortable with using the h/j/k/l keys for cursor navigation.

Write down all the short-cuts and features that you use in your current editor while you're using it at work. Then sit down on Saturday morning and using Google and stack overflow find out how to do each one of those in vi. Probably best if you use a sheet (or sheets) of paper for this.

Now disable/delete the other editors at work so that it'll take you longer to find and re-install them than look at your comparison sheet and do it in vi - i.e. you have no choice.

Lastly, publish your list of crossover shortcuts from your old editor to your new one on your blog.

Good luck!

Don't use X11?

$ sudu rm /usr/local/bin/emacs

Change your login shell to vi?

First, force yourself to use ed, then vi will seem like a luxury?

Use the vi key bindings in bash?

Just start using vi all the time?

It seems to me that learning an editor isn't terribly different from learning a language. Immersion works best.

I use vi for really quick edits or when I can't use X11 for some reason, but I live in emacs. Really powerful editors are worth taking the time to learn.

My recommendation is to come up with some simple programs and write them, start to finish, using VI.

Odds are, you will be too frustrated at first by the learning curve to force yourself to use them at work or in any time-sensitive environment.

I've done this before to get familiar with environments/editors, and it works pretty well.

If you are having problems coming up with things to write, I recommend redoing projects you did in school (or anything else that you've done previously). This method has the added bonus of letting you see how much of a better developer you have become. :)

Edit: forgot to mention that you should do this entirely from the console to avoid any temptation to use the mouse!

I remember when I first started learning emacs, it was after I was already very comfortable with Vim, and I was in the same or similar boat that you were, where I knew how to get a lot done in another editor, so as I started using emacs, it was always painfully slow.

However, I think what you'll have to do is just absorb a little bit of the pain, and always, always, ALWAYS make sure that you look up the documentation for doing something that you know you can do in your previous editor, such as moving to the end of a line, or selecting a region of text.

It also helps if you have a local vi-expert on hand that you can ask questions, or if you're like our company, you promote pair programming. That way when you're trying to do something that should be easy, you can simply ask someone, they'll show you how, and if you're using the editor regularly for a few weeks, you shouldn't have to ask more then a couple of times before it becomes second nature.

If you don't have any local resources, there are plenty of books/tutorials/reference sheets online that should be able to answer most of your questions.

Ultimately, learning Vi is like learning other skills, there's no silver bullet, and you'll have to accept that, for a while, you're going to be less productive in it then your current editor. Just keep telling yourself, "Other people have been able to learn Vi, and I'm at least as smart as them" (That's what I tell myself anyway :) )

The main reason for me to use vi is ssh (or Putty on Windows): When you're logged into a Unix server remotely, then vi is always available. And it works with VT100 when neither the cursor keys nor backspace/delete are mapped.

Also having a book like VI Editor Pocket Reference helps greatly.

gVIM has a really good tutorial (link in the Start menu group).

I found working through that helped to get over the initial learning hump; and then switching my Visual Studio to ViEMU helped me hone my VI skills.

Also, the screencasts at http://vimcasts.org/ are great!

You could get your hands on one of the original Happy Hacker keyboards (no arrow keys) and place your (wireless) mouse out of reach each time you start editing.

It's easy to write out a big list of commands/shortcuts, but it's difficult to remember them all without practice.

Focus on one new command at a time. When it becomes automatic, say after using it for a week or two, add another to your repertoire.

You'll be taking the long way around to accomplish certain things in the short term - these are obvious opportunities for new shortcuts to learn.

In my experience it was easier when I tried not to take on too much at once.

My number one suggestion: learn to type fast, without needing to look at the keyboard.

If you can't touch type and are always hunting-and-pecking for the colon or the hjkl or :%s/foo/bar, forget about it. Typing can be faster than using the mouse, but if that's not the case for you, vi's not going to work.

But combine good typing skills, ssh and screen and vi will be natural.

Face the fact that it will create an immediate performance hit. When learning a new tool you need to be able to do something that you know how to do with other tools so the problem isn't your problem. After using the new tool a while it will disappear and you will be only focusing on the underlying problem.

With something like vim (as others have said, vim is vastly superior to vi) it is important to reread and browse the documentation periodically. The interface is completely undiscoverable without it. With each new reading you will see a feature and say, "ah ha, that would have solved this issue I was trying to figure out last week", and will file it away in your brain. Solutions connected to real-world problems that you've had are much easier for you to remember than random shortcuts.

In the end you can use vim with a fairly small subset of it's features, so don't be overwhelmed with all the bells and whistles. Think of all the features in Word, do 99% of the people use them?

ESC gg=G to reindent code and :retab to convert tabs to spaces or spaces to tabs was what hooked me to vim. So actually you don't need to be forced to use it, you just have to learn when it can help you increase your speed.

Go through vimtutor.

Start using vim for simple editing, like config files or html. Learn the commands as you need them.

Search google for a good .vimrc used by someone who uses a toolchain that resembles yours. Turn on syntax highlighting. Find a nice color scheme.

Learn macros because Vim is the best for automated tasks and snippet insertion, like formatting a few words into a complex XML tag or converting a CSV to an HTML table.

You might want to start out with Cream. Cream describes itself as "a modern configuration" of vim. Basically, it is a special version of vim which looks and feels like any other text editor for all practical purposes. But enable the "expert mode" and you have all the power and behavior of vim.

So you can start using Cream as a regular text editor and then experiment with the "expert mode" until you are comfortable enough to fully switch to vim.

Install gVim on all platforms you use.

Then run through the the vimtutor (:help vimtutor or vimtutor at the command line).

Watch the following lecture and follow its advice: 7 Habits For Effective Text Editing 2.0

I say you definitely want to start using it for all your editing. If you fear a loss of productivity then take a weekend to practice it solid (I once did this to switch to dvorak from qwerty and had my productivity high enough by Monday and managed to stick with it after).

It's worth the effort and you won't look back!

Personally, what I had to do was make sure that I could use the Vim key-bindings (or at least, close enough) in several applications. Having to completely switch how I edited text whenever I changed editors made it too hard to get the Vim editing style committed to muscle memory.

In my case, Viemu + vimperator did the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top