Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

21–30 of 249 posts

Re: Vim Anti-Patterns

#21
post #18

Note that d2wi and c2w are not exactly equivalent: d2w will consume trailing whitespace after the second word, while c2w will not. FAFAIK, there is no exact equivalent of d2wi using c. I usually end up using c2aw, but that will also consume any word characters preceding the cursor (not a problem for me since I usually navigate using b and w).

> d2wi and c2w

There is a nice chart on this page with a few more inferior/superior motion commands:

http://vimcasts.org/episodes/modal-editing-undo-redo-and-rep...

One problem I commonly see with most vim advice articles is they just have too many tips for the reader to consume at once. But if you just make sure to pick up at least one of the tips, you'll at least gain something.

Re: Vim Anti-Patterns

#22
post #8

This is good solid advice -- I have a problem with vim advice that golfs more unusual circumstances to save a keystroke or extensively remaps the keys. (Generally the only thing I remap is F1 to ESC, because I use laptops that place them inconveniently close together.) Devoting too many cognitive resources to text entry is also an anti-pattern!

I highly recommend not using the Esc key, remap to jk or caps lock that you can reach without moving your hands. It makes a pretty big difference.

Re: Vim Anti-Patterns

#23
post #22
post #8

This is good solid advice -- I have a problem with vim advice that golfs more unusual circumstances to save a keystroke or extensively remaps the keys. (Generally the only thing I remap is F1 to ESC, because I use laptops that place them inconveniently close together.) Devoting too many cognitive resources to text entry is also an anti-pattern!

I highly recommend not using the Esc key, remap to jk or caps lock that you can reach without moving your hands. It makes a pretty big difference.

Even easier to use the default Ctrl + [ instead of ESC.

Re: Vim Anti-Patterns

#24
> don’t forget you can yank, delete or change forward or backward to a search result.

Did not know this! (although I've been on vim for ~a month) That's a great trick. Much easier than trying to count words.

Re: Vim Anti-Patterns

#25
post #13
post #3

> "If you have to move more than a couple of lines, moving one line at a time by holding down j or k is inefficient." This very point is actually why I moved from Vim to Emacs years ago. After mastering Vim, I realized that Vim strongly encourages you to think a little too much about exactly how to get there or do that thing in the fewest keystrokes, and that it's incompatible with muscle memory. Even years later, I…

Honest question: How does Emacs help with this particular problem ? I feel like with every editor, it involves repeatedly hitting J, Ctrl+N or down arrow, which is inefficient. Do you have a way to get to a particular line that does not force you to think too much about how to get there ?

> How does Emacs help with this particular problem?

What, inefficiency? Inefficiency wasn't the problem. The problem was having to focus too much of my mind on how to use the editor. Muscle memory is invaluable, and Vim just doesn't let my muscle memory take over if I keep having to think about what's the most "efficient" way to move around or change text. Emacs lets my muscle memory take over easily. I just hit C-n or M-S-] a lot. It's inefficient, sure. But who cares? I never realize I'm doing it, and I never feel blocked having to wait until I get to the line I want to.

Re: Vim Anti-Patterns

#26
These are all good tips but most of the anti-patterns seem to skew towards beginners (e.g. don't use the arrow keys, don't navigate in insert mode). One that I think is more common among intermediate, and even advanced, users is the misuse of tabs, windows, and buffers.

A lot of people have a tendency to think of each tab as corresponding to a single open file. This is very understandable because it closely matches the paradigm of most IDEs but it's actually an anti-pattern in VIM. Tabs are really meant to be more like workspaces where you arrange multiple windows into a desired layouts. You then have one buffer for each file that you're dealing with and view them in your windows. It's perfectly fine for multiple windows to share a single buffer or to switch out the buffer that is being viewed in any given window. This StackOverflow answer [1] and this blogpost [2] both go into a fair bit more detail.

If you're trying out this approach for the first time then you probably want to add `set hidden` to your configuration in order to avoid automatically closing buffers that aren't currently being viewed in a window. Coupling this approach with fzf.vim [3] makes managing very large numbers of files a breeze compared to using one tab per file.

[1] - http://stackoverflow.com/a/26710166

[2] - http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-...

[3] - https://github.com/junegunn/fzf.vim

Re: Vim Anti-Patterns

#27
post #10
post #3

> "If you have to move more than a couple of lines, moving one line at a time by holding down j or k is inefficient." This very point is actually why I moved from Vim to Emacs years ago. After mastering Vim, I realized that Vim strongly encourages you to think a little too much about exactly how to get there or do that thing in the fewest keystrokes, and that it's incompatible with muscle memory. Even years later, I…

Just a question of practice, I found. I was a regular vim user in the past, and this was my criticism of in when first starting out - but after a while I found myself unthinkingly coming up with surprisingly complicated sequences of keypresses. It's possible to get very good at subconsciously sizing up editing operations. These days I use emacs, and I pretty much always move the cursor using the mouse.

Well I got really good at it after like 5 years of using it, and that muscle memory never kicked in for me. So maybe it's possible that it can be done, just not by everyone?

Re: Vim Anti-Patterns

#28

This is a great resource, but the article is pretty strict on the arrow keys. I would recommend `nnoremap`, over `noremap`, because it only disabled the arrow keys in Normal Mode. The author's explains his rationale in the next section, it's to prevent users from living in Insert Mode. Fair enough. But, when making several relatively close edits, the ability to tap a few arrow keys in Insert Mode is far easier and le…

I don't really disagree with your overall point, the arrows keys are not horrible, but I think for beginners removing all arrow keys is the best approach. I used vim for a while just relying on the arrow keys, and it wasn't until I disabled them completely that I really started to use vim. If I left them on in insert mode, I would have just ended up using them that way, just due to muscle memory. I'd also add that if…

Absolutely agree. I completely disabled arrow keys for a short time; ~3 months. It started out after reading a similar recommendation. It was difficult for a few days, but then I completely forgot about my arrow keys and the fact that I disabled them. It wasn't until months later that I was in one of these situations that I wanted to use the arrow keys, but they didn't work. Which was confusing.

This must have been around the time that I started to understand, and manicure, my vimrc because I remember having to learn all the mapping modes to recover arrow keys for Insert Mode.

So, anecdotally, completely disabling arrow keys led me to learn more Vim than just efficient movement.

Today, though, I don't have the makings anymore because it's no longer a problem.

One quick question; I can't answer this because I am currently commuting. Does 'noremap' disable keys in Command Mode? Now, that would be aggregating, to me.

Also, there a remap mode that combines Normal and Visual modes (right?), that would be one better than 'nnoremap'.

Re: Vim Anti-Patterns

#29

I was originally a die hard Emacs user, but I started to feel a bit of strain on the whole holding Ctrl+p, Ctrl+n etc. I was trying to find an editor/plugin that can reduce keystrokes or at least the strain. I ran across EVIL for Emacs which is just a Vim emulation and keybindings for Emacs users. Unfortunately I did not like it at first the entire hjkl felt awkward and all those modes - OMG. But after toying around…

I love vim but admittedly ctrl-backspace-backspace is just as fast as d2b and works in nearly any editor. The stuff i really like is stuff as dt. which will delete until the end of the sentence, ie until the period. Or di( which deletes everything inside the parenthesis.

Re: Vim Anti-Patterns

#30
post #22

Earlier quoted context omitted.

I highly recommend not using the Esc key, remap to jk or caps lock that you can reach without moving your hands. It makes a pretty big difference.

Even easier to use the default Ctrl + [ instead of ESC.

I've somehow gotten in the habit of using ^C for Escape. Guess it feels natural from using it in Bash to restart typing my command or to kill a program.
Post reply on HN