Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

101–110 of 249 posts

Re: Vim Anti-Patterns

#101

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…

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)
The first one originates from recognizing the problem from the antipatterns article: that spamming j j j j to get down to the line you want is dumb. But I choose not to follow the advice of most vim articles I read which is to learn built-in tricks such as typing 10j or :. The milliseconds it takes for me to count the number of lines I want to go down or assess the line number of the line I'm interested in aren't worth it, I'll just tap j if the line is close enough or J if it is five or more lines down. I think it is a good solution.

The even better solution (and I use them both in tandem) is to install easymotion [1] and use it like I show in the second example.

I also use gg and G to get to leap to the top and bottom of the file quite a lot.

---

As to your question about using O to insert above the current line, that should not work that way. Your specific issue sounds very much like a binding has been defined for O. Type :nmap in vim to display a list of bindings and check for lines starting with O. It might be in your .vimrc or some plugin defined something. I would definitely say remove the binding or the plugin rather than put up with that, O is very useful.

[1] https://github.com/easymotion/vim-easymotion

Re: Vim Anti-Patterns

#102

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…

I started combining {} with zt zz zb. I feel like it mimics physical handling of a scroll. This requires some empty lines though. In case I work with dense text, I usually switch to H/M/L also (combined with zt zz zb).

I have to mention that for navigation purposes, f/F is only useful with ;, otherwise you could find yourself looking through the line for a suitable character which slows you down. With ; it's enough to pick a "rare" character on the line which is near to/in the desired object.

Next to c2f, ci" (and ci) etc) could be really useful when you end up being in the middle of a string literal and just want to change the whole thing. Or in the middle of an expression in parens - http://fuckyeahvim.tumblr.com/image/122373002741

Re: Vim Anti-Patterns

#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 (and yes, I sat and tried it for a while in vim to see what it would be like).

I can get from the home row to Escape and back with very little effort, though I understand that is not the case for many people. Perhaps it is due to the fact that I use my ring finger to hit Escape rather than my pinky (which would be a lot more work, I think).

Re: Vim Anti-Patterns

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

Re: Vim Anti-Patterns

#105
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…

Actually hitting escape is one of the things I most disliked, so learning CTRL+[ is great for me!

Re: Vim Anti-Patterns

#106
Movement is an important part of vim, but so is auto-competing. Probably the biggest thing that helped me greatly improve speed in vim was learning the C-x keys and that they are context aware. Having to repeat an entire or similar line/s becomes quick without having to go back to that place. Why move in the file when vim can find the text for you?

Re: Vim Anti-Patterns

#107

Earlier quoted context omitted.

I got some basic muscle memory in Vim, then tried for a long time to learn emacs. Now I've found spacemacs, and couldn't be happier (which uses EVIL mode under the hood). If you haven't tried it, you should check it out.

Unfortunately I'm using windows for my main os, and emacs does not work as smoothly on windows as it does on mac/linux. But now you got a beefy framework with all the bells and whistles from spacemacs, I really like to keep my plugins lean and specific to my needs. also now you need to worry about layers being maintained in spacemacs, which can be a good/bad thing. I have tried it out loved the ease of it, but not th…

I've been using emacs on Windows at work for the last few years (at home I use macOS (nee OS X) and linux). What issues have you found, in particular, that were hard to adapt to with emacs on Windows?

Re: Vim Anti-Patterns

#108

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

I recall reading somewhere that Stallman's keyboard had the CTRL key where the (totally useless) caps-lock key is on modern keyboards, and that's why he used CTRL+ combinations throughout emacs.

The most perfect keyboard ever envisioned (whose name shall not be mentioned) has the CTRL key there. It has no dedicated caps-lock key at all.

Re: Vim Anti-Patterns

#109

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…

Personally, I NOP-ed all arrow keys _and_ hjkl also, after I found myself keeping j pressed to get to an area at the bottom of the window. Which would be an L. Then NOP-ed, bit by bit, many other things which could be done faster. 90% of my movements are search, BWtf{} and some scrolling with zt zz zb. The only case I found the lack of hjkl problematic so far is in block visual mode.

Another anti-pattern I did was Da and dWi, NOP-ed them and forced myself to start using C and cW respectively. Not much of an achievement, but feels better :) Same for x, I deleted whole words with x, then pressed i, I removed the mapping of x.

Conclusion: in case you think you have an anti-pattern, just NOP the mappings. In case one or two turns out to be too much of restriction, you could always remove the NOP mapping later.

Re: Vim Anti-Patterns

#110
post #59

Earlier quoted context omitted.

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

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.
Post reply on HN