Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

161–170 of 249 posts

Re: Vim Anti-Patterns

#161

Earlier quoted context omitted.

I have two tricks for better movement, add the following to your .vimrc: " for scrolling up and down quickly nnoremap J 7j nnoremap K 7k vnoremap J 7j vnoremap K 7k and the second (which requires a third party plugin): " easymotion allows us to jump to all places that could have been reached by " (w in this case), and the bd- indicates we want to search backwards too. nmap f (easymotion-bd-w) vmap f (easymotion-bd-w)…

For better scrolling: nmap 3j3 nmap 3k3 (replace "3" with whatever number you like best). These shortcuts will enable you to scroll the text, while keeping the cursor fixed. It's similar to web page scrolling. It helpls you type in code while maintaining an overview on what's going on below and above it. Add these to your .vimrc and use them for some time. You'll thank me later.

I could see using that with J and K because I use c-(hjkl) for moving between open buffers in a tab. Nice tip though.

   map  h
   map  j
   map  k
   map  l

Re: Vim Anti-Patterns

#162

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…

My favorite "secret" vim feature, that no one has mentioned yet:

    set scrolloff=999
That will keep the cursor in the middle of the window always, except at the start and end of the file. Before discovering that I used to `zz` after nearly every movement; that's all gone now, saving a ton of time and frustration.

Re: Vim Anti-Patterns

#163
post #59

Earlier quoted context omitted.

Easier than editing a config file, but not easier than hitting jk or kj. Just take the second to map it.

The reason I'm so reluctant to remap it is that I use vim in a gadjillion different environments, and I don't want to have to worry about managing .vimrc everywhere. Or is it _vimrc? Especially under Windows, when I have cygwin and msys2 both installed, keeping .vimrc synchronized is terrible. I'm more inclined to adopt ^[, since that should work anywhere, even in vi.

This. Hitting that wall when you're hacking on a file and discover after the fact that your fancy keybind remap isn't on this machine and now it's doing something weird...

Customizations are baggage. I try to minimize them as much as I can, even if it means being a little less efficient on my home system. A side effect is that if a program doesn't have sane defaults I'm not likely to use it, even if it can be made to work better with some tweaking.

I don't go much beyond :syntax on and :set si with Vim.

Re: Vim Anti-Patterns

#164

Earlier quoted context omitted.

Of course we do: You can jump by searching for line contents with C-s, you can do an operation a certain number of times with M- , and do an operation four times with C-u , which chains, so you can do an operation 16 times with C-u C-u . If you want to jump to a specific line number, you can use M-g M-g , or (because C-u also provides numerical arguments) C-u M-g M-g. Finally, many motion commands set the mark, so yo…

Wait, how’s this different from Vim? You can use : to go to a line and C-o to return to where you were.

It's really not different, except that we have more, better options for how to go about it. The difference is, you can just use C-n, and nobody will complain that you're doing it wrong. Well, not too much, anyways.

Re: Vim Anti-Patterns

#165

Earlier quoted context omitted.

Of course we do: You can jump by searching for line contents with C-s, you can do an operation a certain number of times with M- , and do an operation four times with C-u , which chains, so you can do an operation 16 times with C-u C-u . If you want to jump to a specific line number, you can use M-g M-g , or (because C-u also provides numerical arguments) C-u M-g M-g. Finally, many motion commands set the mark, so yo…

Wait, how’s this different from Vim? You can use : to go to a line and C-o to return to where you were.

[deleted]

Re: Vim Anti-Patterns

#166
post #4

I have a programmable keyboard, so I just map escape to be right above tab, where tilde usually is.

I use Karabiner + Seil to make my Macbook Pro's Caps Lock be Escape when hit by itself and Control when hit with another key. Unfortunately this doesn't work on Sierra yet so still on El Cap.

They are working on a new version that for sierra: https://github.com/tekezo/Karabiner-Elements. I'm using it. It works, but you have to configure it by editing a json file, and there are some bugs still

Re: Vim Anti-Patterns

#167

Earlier quoted context omitted.

Wait, how’s this different from Vim? You can use : to go to a line and C-o to return to where you were.

It's really not different, except that we have more, better options for how to go about it. The difference is, you can just use C-n, and nobody will complain that you're doing it wrong. Well, not too much, anyways.

Sounds like the options are the same. Note that it isn’t some kind of Vim standard that j shouldn’t be used repeatedly, just this author’s opinion. I do it all the time.

Re: Vim Anti-Patterns

#168

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…

on the O thing: check :nmap and friends to see if you have a 2-letter mapping set up that starts with O. This has caused issues for me in the past when I wanted to use a key that was doing double duty already—vim has to wait just a sec to see if you keep typing and it needs to act on that.

Re: Vim Anti-Patterns

#169
post #104
post #103

"Hitting Escape is usually unnecessary; Ctrl+[ is a lot closer, and more comfortable." I agree with a lot of the things in this article, but wow, I could not possibly disagree with this quote more. Ctrl+[ is WAY more uncomfortable than using the Escape key. Granted, I have many years of vim usage that have made hitting Escape a habit, and that probably plays a big part in it, but Ctrl+[ is downright painful for me (a…

I suggest remapping Caps Lock to CTRL if you haven't remapped it already.

Plug for Karabiner on OS X, which lets you use capslock as a control if you press it with another key, and escape if its released on its own. It has ruined me for other computers that don't have this set up. There's also a way to do it under Linux, but I can't remember what the package is that lets you do that.

Re: Vim Anti-Patterns

#170

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…

I've tried not using the arrow keys, but my problem is that I use the dvorak layout at home, and typing jcvp to maneuver around (what hjkl maps to) confuses me too much. Especially since I use vim at work as well on the normal qwerty layout. Maybe I'll try again soon. In the meantime, I'll try to incorporate *, #, and gi into my muscle memory (for both layouts).

The dvorak layout (and especially switching layouts) saved me from a lot of pain, so I don't plan on ditching it any time soon.

Post reply on HN