Can someone please explain to me why I should learn vim? I've made several attempts in my lifetime because I thought there would be some magical "ah-ha" moment, but it never came.
Separate modes for command & insert just feels inherently clumsy and slow to me. Is there some other killer feature that can't or hasn't been reproduced by modern editors?
In vim, most commands take the form "[count] operator [count] motion". When you learn a new operator, you can use it with any motion that you know and vice versa; and you can add a count to either. To give a few examples:
- gqip to format (gq) a paragraph (ip).
- g?g? to ROT13 a line (doubling the operator makes it operate on the current line — in this case, g?? also works).
- y2w to copy (y) the next two words (2w) — this requires you to be at the start of the word, but you could use y2aw if you were in the middle of a word.
- dj to delete (d) two lines (j); see ":h linewise".
- dt. to delete (d) until a period (t.), not including the period.
- y% to copy (y) until the matching parentheses (%). If you aren't already on one, vim searches until a "(", which means that you can use this to copy a C-like function call.
Additionally, a subset of these operators and motions are available in plain vi, which is available on any POSIX system (Linux, macOS, *BSD, ...)
It should be possible to do this with a "regular" type of editor, where you have a keyboard shortcut to, for instance, select to the matching parentheses; there just aren't any editors (that I know of) with the same range of motions and operators as vim.
Not moving to the arrow keys or using ctrl-, alt- far outweighs the cost of switching between insert and normal mode.
I appreciate the tutorial, but I probably do already "know" vim, but it's not part of my muscle-memory. Context switching to something like writing an email or filling out a web form really makes it not worth getting too comfortable with all these esoteric shortcuts. Do you write all of your emails in vim and browse the web on the command line as well?
From reading the rest of the replies, it sounds like the real answer is "because it's everywhere", which isn't really satisfying. I don't work on lots of machines that aren't my own (embedded/mobile space, which don't have vi installed!), so I don't actually encounter it everyday despite living on the command line.
Sorry — I never know when to assume a large amount of knowledge or a small amount of knowledge. The worst for me is "ctrl-w" to delete a word backward in Insert mode, and to delete a tab in the web browser :) Vim is in my muscle memory and it's faster for me, so that's why I use it. It might be faster for you and it might not be faster for you, and if you don't need the portability for POSIX machines it's probably not worth the time.
CTRL+W messes me up sometimes. when i'm in split screen mode with two panes i'll often tap CTRL+W twice to switch panes. very confusing when you forget to exit insert mode.
> Do you write all of your emails in vim and browse the web on the command line as well?
Yes! I use mutt + vim. Composing emails in a textarea is a terrible experience by comparison. (Respect to emacs mail mode users, that’s a great option too.)
I also use w3m for browsing technical stuff, and use tmux for copy & paste into vim.
Playing around with this, [count]iw seems to have some really strange behavior — I need to do 3iw to select two words, 5iw to select three words, etc.? I'm not sure if I'm missing something. (I normally don't use many text objects; bdw is in my muscle memory instead of daw, for example.)
Higher precision in intent for many standard operations. These aren't perfectly Vim commands, but from the Vim-like 'evil mode' for emacs, I have some examples of common idioms I use frequently:
- 'I want to change the name of this variable. <cw> (Change Word)'
- 'I want to copy the contents of this braced block. <yi{> (Yank Inside Matching-braces)'
- 'I want to surround this word in parentheses. <vaws(> (Visual-mode (region selection) Around Word Surround-with Matching-parens)'
You get used to the separate modes fairly quickly. Your existing editor already works that way when switching between 'region' and 'insert' modes; it's just the command mode that throws people off initially. It's not that rough, especially if you have a reasonably placed key to return to command mode.
I believe that this is just an arbitrary choice that doesn't collide with other keys and is fairly consistent with the other keybindings — cs for changing delimiters, ds for deleting delimiters, and ys for creating delimiters.
Do you know what plugin it is? I will try to search for an evil version (Or I could just write my own, but my task list is large and my energy very low these days)
Having worked both as a sysadmin and a developer, vim is more a benefit to the former by virtue of its ubiquity. Learn vim if you know you will be encountering vim.
> Separate modes for command & insert just feels inherently clumsy and slow to me.
Interesting, I have the opposite experience. In normal mode, I can do a lot using very few keystrokes. In editors without modes, there's always a lot of keyboard shortcuts which are difficult to remember and hard to execute.
Modern editors often implement a vi mode, so technically everything already has been reproduced in modern text editors.
Aside from just decades of experience in efficient editing of plain text files over slow connections plus all the modern stuff on top, I'd say text objects, which is one of the first things you learn about vim. And it's not a web browser.
For me, it's mostly the key bindings rather than the program itself. I use vim key bindings on whatever the latest $editor is rather than learning its keyboard navigation. I got introduced to vim very early on though.
The thesis of vim is that editing is more fundamental to the act of writing than inputting text. The default mode, normal mode, is entirely shortcuts to do editing tasks better and easier. Moving around the document, and moving or deleting text are the primary concern.
What's more, as several other commenters have alluded to, vim thinks of editing as a language. There are verbs like cut or copy or paste, and there are nouns like [this] sentence or [this] word or one word backwards or from here until the letter j. Once you start building sentences of editing commands (e.g. copy from here to the 3rd next instance of the a line starting with 'Hello' namely <y3/^Hello>) the flexibility it offers is unparalleled. This is all done from your default context without fingers leaving the keyboard. Once you achieve fluency (admittedly not a trivial task) there is no context switching for any editing task, it becomes reflexive and subconscious.
Other stuff, like macros and registers, or easy access to regexes and ex commands help extend this, but the core reason why vim is still used today is this strength.
Because the text motions, once learned, are extremely powerful and will cause your relationship to textual data to fundamentally change. All while avoiding wrist injury, because some critical keys (f, t, g, j, q) are so lettered due to the location on the keyboard. Think of your keyboard as more like a piano than an alphabet.
If you live and breath the command line it's a great skill to have because it's available everywhere and it's a very powerful editor. If you're not a heavy command line user, you are probably fine sticking with whatever you already know.
there is no reason you "should" other than in some environments you may encounter vi so it is worth knowing the basics.
There are many advantages, however, clumsy and slow is a common reaction. From what I've seen, some people get so put off by the different way of editing that they struggle, they find vim a very slow way to do what they were doing before vim - character based editing, moving around with arrow keys, highlighting, inserting, and deleting maybe with some block commands for things like selecting a word or more by using the shift key or ctrl key. Maybe with the help of the mouse to highlight things and edit. The thing with vi/m is there is a language that allows you to do similar editing but has many many combo effects, once you understand how things combo together, all kinds of things can be done really quickly.
There's no real killer feature though, there's lots of cool features, one that often doesn't get mentioned much is that you can filter text through external programs, this combos with all the motion commands and other things, so very quickly you could write a snippet of markdown and change it into html by running it through pandoc, or write your own command line tools that do custom things, like querying things from your own apis / databases etc. Its powerful, because it combos with the rest of the vi/m language so you can use it in really creative ways.
If you work a lot on the command line on UNIX and Linux systems, vi is the best choice for many because it is extremely widely available and it is also very powerful once you have mastered it.
Sorry, but this is the same non-answer I have heard my entire life.
I do primarily work on the command line and I can assign $EDITOR to anything I want. So what makes it so much more powerful than the plethora of other editors in the space?
Vim removes mental load while typing. It won’t make you significantly faster, or even really a better programmer in any measurable way. What it does is make the experience of writing text, and especially writing code, far more pleasant.
If I ever have to write something nowadays without vim, everything feels clumsy and imprecise. If I want to go back a couple of words and change something, I feel like I’m playing a timing minigame. I have to hold the left arrow key exactly the right amount of time. Most of the time I overshoot a couple of characters, and have to tap the right arrow key to get to the right spot. Now repeat the same timing minigame holding backspace. Ah crap I deleted too much better undo a couple of times. Now I can finally make my change.
All of this is just unnecessary friction between your brain and the computer that anyone who hasn’t learned vim accepts as a fact of life, but it becomes completely intolerable after spending the time to learn.
Because it is full-featured editor running fully in text mode (so you can run it on the remote server or over a serial line) and uses short commands for most text edit needs. In comparison nano provides only very basic feaures (like Notepad) and emacs (according to Stallman) is like an operating system with more complicated keyboard shortcuts. Of course you can run VisualStudio Code over VPN but that would waste too much network traffic and the input would lag more.
I equate it to touch-typing. Do you think about each keystroke or do you just type? It’s the same way with editing when you’ve learned it. I don’t know that it has to be vim but that’s what clicked with me.
Speed of editing files (especially code, but not just code) is unparalleled. Anytime I have to use something besides vim, it feels like trying to run in knee-deep water - so sluggish.
> Can someone please explain to me why I should learn vim? I've made several attempts in my lifetime because I thought there would be some magical "ah-ha" moment, but it never came.
It's faster. I've been using vim motions for almost 9 years at this point, 8 years in vim, vi, ex-vi, neovim, etc. Most recently I've moved to Doom Emacs (Which feels like an editor I'll be using in whatever forms it takes, for the next 20+ years). The experience of when you get used to it is essentially that you are so practiced with the motions that they become sub-concsious, muscle-memory. I don't have to think about where to place the cursor, figure out where the mouse cursor is, deal with a bunch of weird pasting tricks. To delete a line I just have to will myself to delete it (using 'dd'), just like I don't have to think about the complex action of getting up off the bed, I just do it (At least, on days when Mr Depresso isn't visiting). Eventually, it feels like the editor is part of you. And at this point I can't give up vim motions. Editing in anything else is uncomfortable and painful because the ease and speed with which vim allows me to do complex motions and actions is so convenient.
I can't speak for your experience, but for me I had to struggle through it a bit until I found the 'ah-ha' -- that might not come for you, or maybe you haven't found it yet, unfortunately.
I would look into using more motions, don't see it as a replacement for Gedit, or Atom, or any of the mouse+keyboard text editors -- it's not. Trying to use it like those will lead nowhere.
The trick that worked for me is to find motions that are convenient, and move ESCAPE to a more palatable key -- I swapped it with CAPS LOCK, since I pretty much never, ever have to use that key (I can always highlight 2 words with `v2w` and press `~`, which will swap the case of it, anyway). The 'finding of the motions' is important. I spend 90% of my time in a text editor moving, and cutting text, rather than typing. A motion like `}` allows me to move the cursor down a paragraph, `d}` will delete said paragraph, `v}y` will copy it, etc. Often I find myself deleting `t`o a place. So I can do `dt#` to delete to the comment at the end of a line. ^O will go to my previous cursor position, etc.
I would also recommend looking up Practical Vim -- it's probably the best Vim handbook out there (Easily accessible via genlib if you want to try before you buy), and there are still things in there I haven't learned and integrated into my workflow yet (For example, `vi)` to fast-edit bracket sequences, that I haven't bothered with much).
---
Regardless of all of that you need to decide if that effort is worth it for you. I know an extremely skilled programmer who writes and deals with extremely complex code just using Gedit (previously Geany).
Separate modes for command & insert just feels inherently clumsy and slow to me. Is there some other killer feature that can't or hasn't been reproduced by modern editors?