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?
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?
- 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.
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.
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.
Wow, how does it work? Why y3aw doesn't fully work for 3 words (it captures space before the word I started with)?
2 words 1 spaces = 3 tokens 3 words 2 spaces = 5 tokens 4 words 3 spaces = 7 tokens ... maybe?
- '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.
Holy shit, thank you. I've been looking for something like this for half a decade and never found it (I don't even know how I missed it!)
But there is nothing surrounding the word! I thought yank was for copying and pasting stuff. I can't understand why ysiwb works :(
They should not overload y for yank. Choose anything else that's not used.
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.
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.
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.
I'd highly recommend another classic response, given here, elaborating on the nature of vim as a language for editing: https://stackoverflow.com/questions/1218390/what-is-your-mos...
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.
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?
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.
There is no reason really, you either hear the call of the wild or you don’t and it’s perfectly fine if you prefer emacs, acme, nano or vscode.
The simple fact that the choice is so large is that people “click” in many interesting ways.
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).
Will it help you program better? nope.
Will it help you be a better programmer? nope.