diw to delete whole word.
yy then 5p to repeat the line 5 times instead of copy paste.
/ for search is really nice.
gg to go to the top or G to go to the bottom.
These things make it worth using vim for me. I use vim mode on all the editing programs (RStudio and VS Code)
<Ctrl-D><Bksp> to delete a word.
<Ctrl-Shift-D> to duplicate a line. [0]
<Ctrl-F> for search.
<Ctrl-Home/End> to go to the top or bottom.
I'm increasingly unconvinced that vim has much to offer in terms of shortcuts when compared to actual modern editors, rather than some kind of strawman notepad.
[0] No numeric repetition, but I was never convinced by that feature TBH. In most cases, the mental overhead of working out the appropriate number for a situation was greater for me than just spamming a button a few times.
For example, maybe you need to delete the next two words (d2w - delete 2 words). Or maybe you want to delete the next four words, then replace them with something else (c4w - change 4 words). Or maybe you need to change the every letter of the next ten lines to uppercase, until you hit the letter 'a' on each line (qq0gUtaj10@q).
VIMs shortcuts aren't better because they're more powerful, they're better because there's an infinite combination of them.
More generally, my experience of vim is that I'd spend longer working out how to do something with one command than I'd have taken to just use a few simpler actions. And that didn't really get better with time (I used it as my primary editor for a few years), because sufficiently complicated editing tasks just don't arise that often.
And personally, I find Sublime's multiple selections much easier to apply in ad-hoc ways to unusual editing scenarios than vim's vocabulary.
A common scenario I encounter, is that I realise I need to make a change in many matching places, but I don't know immediately whether it applies to the entire file, or whether there are some edge cases. In Sublime, I select one instance, step through adding matching ones to the selection and excluding any I don't want, and then make the edit confident that I'm changing exactly the things I want to.
In vim, my experience was that I'd write a substitution, discover it was too general when it broke something, and then try to work out how to exclude the cases I didn't want, which was often nontrivial. EDIT: Thinking about it now, I guess the vim way to do the above would be to / for the first case, make the change in insert mode and then use /. for the others. Although if it's a complicated edit, it might not be effective to use insert mode, so I'd need a macro maybe? I found those kinda fiddly tbh.
I completely agree that often figuring out how many words I want to apply a command to is too much effort; however of course vim has visual selection like any other editor, so I can just press v to begin selecting, then w a few times to move to the beginning of the next word, and then I can apply any of the verbs in my arsenal to the resulting selection.
I find that having the option of <count> repetition is much more useful with large text objects that I can easily subitize. It's very natural for me to delete 3 paragraphs with `d3}` for instance, moreso than selecting them then deleting them.
I think that my very favorite motion in vim might be the `f` key. You use it like `fj` to move to the next occurrence of 'j' on the current line.
I also agree with you that multiple cursors are a much better solution than regexes to the same edit in a few different nearby places. There are multiple selection plugins for vim, but they don't work very well, and I wish it had better support. On the other hand, regexes scale much much better.
Except those don't make much sense as compositions, because they overload the letters. cap? What does change-append-paste mean? Oh it actually means change-a-paragraph? Okay...
Sure, there are some convenient patterns to vim's shortcuts, but I think the extent to which they're a "language" is overstated. And that's fine, since it's mostly about muscle memory anyway.
>I think that my very favorite motion in vim might be the `f` key.
Yeah I did miss that one for a while.
>On the other hand, regexes scale much much better.
If I want regexes, I can use find and replace with them. And I think the minimal (keyboard driven) GUI is a lot easier to use for that than s/// syntax.
Yes, it hurts my wrist. If I use it continuously for too long it becomes disabling. I use awesome window manager, tmux, vim, vimium browser plugins so that I never have to touch the mouse.
Keyboards hurt my wrists too but it's much more manageable.
I havn't measured actual speed/efficiency, but once I got used to keyboard shortcuts for everything using the mouse feels slow, clunky and inaccurate.
Well that's how I now feel when someone else is editing a file without Vim.
Text editing is not a bottleneck in my development workflow, so I'd say never. This said, I wouldn't change to a different editor, especially one that doesn't have Vi-like modal editing.
> Is using a mouse such a major factor that slows you down or affects you negatively?
Yes and it's also an ergonomics disaster.
Vim isn't great when it comes to IDE-like features but it's a great text editor once you grok the paradigm. If you use it like a "normal" editor, it kinda sucks. Once you can keep your hands on the home row at all times, you don't want to go back.
Vim's killer feature, not found in any other editor I know, is repeat (.) .
I use vim in tmux with a curses debugger and it gets a lot of IDE benefits but is language agnostic. Changing to a different editor/IDE depending on language/target platform/project just sounds awful.
I know, I'm talking about milliseconds (or nanoseconds) here, but when I use vi, it's just, sort of "constant", like playing the piano. I never break my rhythm.
Sure, but who does that?
In any text editor on the Mac its:
- Command-Left to move to the beginning of the line
- Shift-Command-Right to select to the end of the line
- Command-C to copy
- Command-V to paste
One annoying thing about that, though, is that it doesn't copy the newline itself, so if you want to paste the line and the line terminator multiple times, you need to do something more like: - Command-Left to move to the beginning of the line
- Shift-Command-Right to select to the end of the line
- Shift-Right to select the newline
- Command-C to copy
- Command-V to paste
But, of course, most full-featured text editors make that easier. In Sublime and Atom, it's: - Command-L to select the current line
- Command-C to copy
- Command-V to paste - [2] Command-Left to move to the beginning of the line
- [3] Shift-Command-Right to select to the end of the line
- [2] Command-C to copy
- [2] Command-V to paste
Total keypresses: 9Total keypresses for yyp: 3 (4 if you have to esc to normal mode first)
My point being that even the simple and straightforward actions you provided are more complex than they seem.
Secondly, that's just using the minimal set of shortcuts that work anywhere. If you're in an actual editor, it almost certainly has a shortcut like Ctrl-Shift-D for duplicate line.
And I think a lot of vim users might be surprised how simple and straightforward things can be in a modern editor.
Similarly, if I want to change them or delete them the y becomes a c or d.
works with ( and { and ' as well. also, ```ca"``` will do the same but include the " in the change. (change around the ")
not sure if it's built into the stock vim but ```cit``` will do a change inner tag for html and xml tags too.
Neat, I didn't know that - thanks for the tip!
e.g. in Sublime:
>if I want to duplicate a line
Ctrl-Shift-D
>If I want to change the contents of a quoted string
Ctrl-Shift-M selects inside parens. It doesn't do quotes by default, but there might be a way to enable that.
EDIT: I looked this up afterwards, and discovered Ctrl-Shift-Space selects a quoted (or parened) block, although it includes the quotes.
>If I want to change each line from the current line to the next blank line to a continuous quoted string
Okay, this seems a bit contrived, and I'm not convinced the average vim user would bother with this rather than just doing something like I"<Esc>}kA" or whatever.
Unless you're bulk editing, in which case I think Sublime's regex find and replace would be similarly effective, and probably easier to get right than typing the whole command in one.
I will note however that selecting text and pressing a paren key wraps it in parens, and as above it might be possible to make that work for quotes.
Try triple click ;)
After watching Bret Victor's talk https://vimeo.com/67076984, I feel like Vim way of using computers is backward. I am probably wrong because I never got proficient with Vim. Using it only when I SSH to remote server.
d delete
c change
t 'til
f find
a after
i insert
u undo
o open a new line
p paste or put
n next occurance
b back a word
y yank (copy)
v visual
ect.
coupled with an object that are less friendly to learn but there aren't that many of them
w word
e end of word
( sentence
{ paragraph
text blocks are directly what you want to change
" double quotes
' single quotes
( parenthesis
{ curly brackets
t tag
ci( change inside the (
da" deletes around the double quote, etc.
it's easy to compose sentences for editing text.
this person does more to explain why: http://stackoverflow.com/questions/1218390/what-is-your-most...
And yes, after having been using vim 95% of the time for a few years, it really is faster to keep hands on the keyboard instead of using the mouse. MacVim lets you point and click to position the cursor, just like any other text editor. I almost never do, though.
1. The first two weeks were hell. It felt like learning to use a keyboard all over again. I've tried to get started with vim multiple times, leaving because I needed something faster. This time, I just happened to catch a break in work where there was no one breathing down my neck to get stuff out the door yesterday.
After two weeks or so, you start to learn the vim mindset. It's hard to explain, but vim is both a language (via movements and interacting) and a way of thinking (via modes). I'm still adjusting to all of those, but it's gotten to the point where I think of a task, attempt it with the shortcuts I know (the "language"), and 2/3 of the time, it just works.
2. Is there speed over previous IDEs and text editors? It's about the same for me, with the added benefit that I'm no longer tied to a system I have to pay for, it's cross-platform, and pretty available in most sports.
For Mac at least, there are things like MacVIM where I believe they let you use your mouse to click around. I did all of my learning from the Laracasts vim series, and I really like his approach of doing what works for you. MacVIM adds shortcuts like command-S to save instead of :w and stuff. If it works for you, cool. I took the approach that I want to learn the base system (plus plugins) because that is a more common cross-platform interface.
From using an IDE, I don't know if I'm saving time by not using the mouse or not, but I know that I can more quickly get places within the code if I know where I'm going. I assume the benefit of not reaching over to use the mouse is helping, but I can't really tell.
For me, there were other reasons, but I don't regret the switch at all. I'm still quite the novice, but I've switched to using it nearly exclusively for projects. (If I just need to quickly open a file from the Mac Finder, I double-click and something non-vim opens. I'm OK with that, I'm no purist.)
The only place it bites you is when you use vim for a while and then go back to something like Code or SublimeText and you're typing vim commands into the screen as characters. Make sure you double-check your work so that you're not pushing ":w"'s up to production. :)
For example, if you use tab-completion in insert mode, it records the action as what you actually typed rather than the completed text. So if you press . to repeat it somewhere else, it inserts the gibberish you actually typed. (And Sublime's fuzzy matching is really good, so that gibberish can be pretty bad...)
But I never really felt it was more convenient or an improvement over a GUI based text editor or IDE on my development machine. Eg- gedit for simple text editing, Android Studio for android development, Atom for python coding. Everything works out of the box with minimal tweaking required.
Genuine questions:
-At what point on the learning curve do you feel using vim is an advantage for speed of development, if at all?
-The common argument of only keyboard, no mouse when using vim... I don't get. Is using a mouse such a major factor that slows you down or affects you negatively?