Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

71–80 of 249 posts

Re: Vim Anti-Patterns

#71

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…

Or, get a keyboard that allows for the thumbs to be used for more than just the spacebar! :)

Something like this: https://ergodox-ez.com/collections/frontpage/products/ergodo...

Re: Vim Anti-Patterns

#72
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 ?

1. place hand on mouse

2. move mouse cursor to desired position

3. click mouse

If you're just looking to put the cursor somewhere you can see, this is actually quite quick.

Re: Vim Anti-Patterns

#73
I never got into the habit of using { and }. I just use H M L (high/medium/low) to get approximately in the right part of the screen, then go line-by-line. You can also do 5H or 10L to get "5 lines from the top" or "10 lines from the bottom". I make pretty good use of vim features, but I like to mix some sloppiness with the precision. I don't often count things before typing commands, because that breaks the second-nature quality of navigation. If something is more than 2 or 3 objects away, I approximate. I do use counting with t, T, f, and F a lot to hop around, including things like c2f). Very frequently that combines well with spamming j.j.j.j.j. I use . with trivial movement (like j or n) at least 10x more than @a. Another way to move fast sloppily is W and B. I guess I'm saying: learn all the cool stuff you can do, but don't feel like you have to find the most precise way to do every little thing. If you're just starting out, relax and don't try too hard. You can always just pick one new thing every couple weeks and try to add it to your habits.

Oh also: he mentions O to insert above the current line. I use that a lot, but on my systems (going back 15 years or so I think) it has always required a pause, like vim is waiting to see if I'm typing O or some longer command. If I type O and immediately start entering text, strange things happen. This doesn't happen with o. Does anyone else experience this? Maybe it's just something weird in my own setup.

EDIT: Some more "moving fast sloppily": 1G goes to the top of the file. G goes to the bottom. Also you can not-move, but scroll the visible area so that your cursor is on the top line (zENTER), middle line (z.), or bottom line (z-). I use that a lot when I am Ctrl-Fing through a file, so I can see more context.

Re: Vim Anti-Patterns

#74

I never got into the habit of using { and }. I just use H M L (high/medium/low) to get approximately in the right part of the screen, then go line-by-line. You can also do 5H or 10L to get "5 lines from the top" or "10 lines from the bottom". I make pretty good use of vim features, but I like to mix some sloppiness with the precision. I don't often count things before typing commands, because that breaks the second-n…

Sounds like you've got something mapped to a key sequence that starts with O.

You can look through :map and try and find it -- not sure if there's an easier way.

Re: Vim Anti-Patterns

#75
post #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.

I agree it is very nice, although you should know one caveat: deleting/yanking with / and ? will do whole lines, so it may go past the match. deleting/yanking with t, T, f, and F will go up to just the char you want, but it won't search onto the next line. I wish there was a way to get a char-by-char multiline search, so I could e.g. cut/yank a whole sentence (something like d/.). But I haven't found it. I wonder if…

You might find vim-sneak useful: https://github.com/justinmk/vim-sneak.

https://github.com/easymotion/vim-easymotion is another plugin that does something slightly different, but also useful.

Re: Vim Anti-Patterns

#77
While these tips are good per se, in retrospect I don't think it's that a good idea to tie your muscle memory that much to a single piece of software. I'd say enjoy the cursor keys. Moving around in insert mode is ok too.

Re: Vim Anti-Patterns

#78

I find that marking my place with "ma" and returning to it with "'a" is a huge productivity boost. Of course the "a" is just a label, you can use any character (this allows multiple marks as well).

if you only browse code use gi, that saves me a ton of time. gi brings you back to last inserted text.

Re: Vim Anti-Patterns

#79

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…

If you look at the Keyboard that Bill Joy developed vi on, the esc keybinding actually makes sense, and the caplocks keybinding is basically what he used.

https://en.wikipedia.org/wiki/Vi#/media/File:KB_Terminal_ADM...

I guess it'd be more like tab, but whatever.

Re: Vim Anti-Patterns

#80
post #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…

Personally I just never use tabs. Things like ctrl-p or the built-in tab completion for :buffer and :edit make switching files so quick I don't really need multiple workspaces.

But I then I pretty much exclusively work with three windows side-by-side, NERDTree, File 1, File 2. I guess if you like switching window layouts a lot then tabs could be very useful.

Post reply on HN