Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of learning Vim? [closed]

Tags:

vim

editor

People also ask

Why is it important to learn Vim?

Once you start learning Vim, you'll be more efficient and effective than you ever were with nano. All the power Vim provides allows you to do things quickly. You can even make complex edits fairly quick and easily, once you know how Vim works.

Is learning Vim still worth it?

I will say it again: Learning VIM does not make you a better software engineer. At its core, software engineering is agnostic of what shell/editor/OS you develop on. I believe that too many people implicitly have this notion that you need to use X or Y in order to be a “good” software engineer.

Why should you learn Vim in 2020?

By tuning Vim, you are learning more about what you have in your development environment and how it works. For example, to search for text occurrences, I used ack-grep. Later on, I found that there is a faster approach using ag. Then, there is an even faster alternative called ripgrep.


I've been using vi and vim also for some 20 years, and I'm still learning new things.

David Rayner's Best of Vim Tips site is an excellent list, though it's probably more useful once you have some familiarity with vim.

I also want to mention the ViEmu site which has some great info on vi/vim tips and especially the article Why, oh WHY, do those nutheads use vi? (archived version)


Could I live without it? Easily.

Is it useful? Yes.

Reasons for Learning

  • vi is guaranteed to exist on all Unix systems and exists on most Linux ones as well. That kind of broad coverage makes learning it worth it.

  • It's much quicker to use vi for a sudo edit:

    $ sudo vi

  • Also, GMail uses vi-ish commands for selecting & moving emails around!

You don't have to be a master.

Just learn

The basics:

  • How to switch from command mode to insert mode i
  • How to switch from insert mode to command mode Esc
  • How to navigate up a line in command mode k
  • How to navigate down a line in command mode j
  • How to navigate left a character in command mode h
  • How to navigate right a character l
  • How to save a file :wEnter (write)
  • How to exit without saving (in command mode) :q!Enter
  • How to Undo u
  • How to Redo Ctrl+r
  • You can combine writing and quitting (in command mode): :wqEnter

From there the rest will just make you faster.


Running through vimtutor only took me 30 minutes, which was enough to get familiar with vim. It was worth every second of it.


If you're a programmer who edits a lot of text, then it's important to learn an A Serious Text Editor. Which Serious Text Editor you learn is not terribly important and is largely dependent on the types of environments you expect to be editing in.

The reason is that these editors are highly optimized to perform the kinds of tasks that you will be doing a lot. For example, consider adding the same bit of text to the end of every line. This is trivial in A Serious Text Editor, but ridiculously cumbersome otherwise.

Usually vim's killer features are considered: A) that it's available on pretty much every Unix you'll ever encounter and B) your fingers very rarely have to leave the home row, which means you'll be able to edit text very, very quickly. It's also usually very fast and lightweight even when editing huge files.

There are plenty of alternatives, however. Emacs is the most common example, of course, and it's much more than just an advanced text editor if you really dig into it. I'm personally a very happy TextMate user now after years of using vim/gvim.

The trick to switching to any of these is to force yourself to use them the way they were intended. For example, in vim, if you're manually performing every step in a multi-step process or if you're using the arrow keys or the mouse then there's probably a better way to do it. Stop what you're doing and look it up.

If you do nothing else, learn the basic navigation controls for both vim and Emacs since they pop up all over the place. For example, you can use Emacs-style controls in any text input field in Mac OS, in most Unix shells, in Eclipse, etc. You can use vim-style controls in the less(1) command, on Slashdot, on gmail, etc.

Have fun!


It's definitely worth the effort.

There's one obvious reason that anyone who uses Vi(m) will tell you, and two others that people never seem to mention.

Here's the obvious one:

  1. vi is at once ubiquitous and incredibly powerful, and by learning it once, you gain the ability to exercise that power on pretty much any computer that has a keyboard.

And these are the lesser known reasons to learn Vim:

  1. It's not half as much effort as you think it's going to be. Run through the Vim tutor once (vimtutor at a shell, or in Windows run it from the Vim folder in the Start Menu), and you'll already be well on your way to competence, and it's all downhill from there. I was up to the level where I could use Vim at work without taking any noticeable productivity hit within less than a week's worth of lunchtimes.

  2. It's fun! Editing text is like a game to me now. I actively enjoy it--which is pretty ridiculous, when you think about it.

There's also two good reasons not to learn Vim:

  1. It's addictive, and you'll find yourself wishing you could use Vim commands in all your computing, and cursing whenever you can't. Fortunately, at least for some situations, there's ways to get around this.

  2. Again, it's addictive, and although you won't lose any productivity from actually using Vim, you will waste hours searching for good tips to make your Vim experience even better, and reading the Vim tag on Stack Overflow.


It's definitely worth learning either vim or emacs. It's also worth learning to touch-type. In both cases the reasons are the same: your thinking is no longer interrupted by the mechanical process of getting your code onto the screen.

As to how to start, just dive in and start using vim for everything.

P.S. The emacs-vs-vi debate is endless. I've been using emacs for 26 years. If I started again today I'd learn vim because (a) it's gotten better and (b) there are many fewer modifier keys (Ctl-Alt-V, anyone) and vim users seem to get much less typing injury.


You can get good functionality out of vim by learning the meanings of only 16 keys: ijkdbw9:q!%s/nNEsc. You can do the bare bones with just i:wqEsc.

The first two keys you need to know are: Esc takes you to command mode (the mode you start in), and i takes you to insert mode (normal typing).


To save you need to

  1. get out of typing mode (Esc)
  2. type a colon :
  3. type lowercase w then Enter

To save-and-quit you need to

  1. get out of typing mode (Esc)
  2. type a colon :
  3. type lowercase wq then Enter

To not-save-and-force-quit you need to

  1. get out of typing mode (Esc)
  2. type a colon :
  3. type lowercase q! then Enter

To learn more you can run vimtutor at the command line. It's a medium-length, well-structured lesson.

Beyond i and Esc: you can replicate or surpass some MS Word functionality with only jkwbd3:%s/nN.

  1. b takes you back a word (Ctrl+)
  2. w takes you forward a word (Ctrl+)
  3. 9w takes you forward nine words
  4. db deletes the preceding word (Ctrl+Backspace)
  5. d3b deletes three preceding words
  6. 9j moves down 9 lines
  7. / ornithopter Enter takes you to the next instance of the word "ornithopter", then n and N to the next and previous occurrence of "ornithopter" respectively.
  8. :%s/confounded/dangfangled/ Enter substitutes every "confounded" with "dangfangled" (like find and replace all in MS Word)

Any of those should be run in "command" mode (Esc), not insert mode (i).