Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

211–220 of 249 posts

Re: Vim Anti-Patterns

#211
post #29

Earlier quoted context omitted.

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.

I decided one year that I would force myself (a vi die-hard) to use emacs for everything for an entire year, to see if I ever got used to it. One thing that never stopped driving me crazy was that there's no efficient way to duplicate a line like yyp in vim. The closest I could ever get in emacs was ctrl+k k ctrl+y ctrl+y (that is, delete the line and then paste it back twice). Looking online for a solution leads me…

You could use C-S- C-y C-y, which uses kill-whole-line (C-S-) instead of kill-line twice (C-k C-k).

I think that's reasonably short (same number of non-modifier keys as vi!). Of course, if you find yourself doing it a lot, you can configure Emacs however you want.

Re: Vim Anti-Patterns

#212
post #13

Earlier quoted context omitted.

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…

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

IME, you do develop muscle memory in terms of using more "efficient" ways of navigation and text manipulation after using vim for a while. I guess it's sort of like learning how to drive a vehicle equipped with a manual transmission. At first, you're thinking more about how to shift through the gears and use the clutch. After a while, you don't really think about it too much while you're still doing it. After driving a bit longer, you start to get a feel about which gear to choose for a given traffic situation.

So, similarly, you get a feel about which keybinding to use to change certain types of text or do certain movements without having to think too much about it.

Re: Vim Anti-Patterns

#213

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…

> If something is more than 2 or 3 objects away, I approximate

set number + set relativenumber is pretty awesome for line counting. This marks all lines with relative numbers, except the current one.

Re: Vim Anti-Patterns

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

Well, I've been using vi and it's brethren since about 2002 and I've pretty much always used the arrow keys; after some point it becomes muscle memory... I never really understood what the problem with this was; I rarely actually use them (esc|capslock /str,ctrl+f|b etc) is usually how I move around and if I'm wanting to move a few chars my little finger is not moving very far (at least, on apple keyboards)... Is thi…

> Do you see any big advantage of using a lot of buffers/tabs/splits over running multiple vims inside tmux?

I think my personal benefit is that I don't have to make a bunch of new SSH connections every time I want to split files in vim, I can just open up a new buffer.

Re: Vim Anti-Patterns

#215
post #178

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)…

Ahg, no I couldn't do that, I need to keep J as Join lines. That's pretty useful to me. Kinda the inverse of gq.

I use that a lot as well, along with K to look up the current word in the man page.

Re: Vim Anti-Patterns

#216
post #207

While it's unarguably fun, I can't believe the effort required to become actually good at vim (as opposed to just using a few of the easier features) will ever pay itself off. (These days, at least - if you spend your days editing code in a terminal over a dialup connection, then it's absolutely worth it!) Maybe there are scenarios where the busywork of text editing really is on your critical path, but even as a flue…

It's not really about adding up time saved, it's about staying in the flow. I think you can probably achieve that by being really good at almost any editor, but vim probably does it a little better than most and it has the advantage that it's everywhere (including IDEs).

Re: Vim Anti-Patterns

#217
post #207

While it's unarguably fun, I can't believe the effort required to become actually good at vim (as opposed to just using a few of the easier features) will ever pay itself off. (These days, at least - if you spend your days editing code in a terminal over a dialup connection, then it's absolutely worth it!) Maybe there are scenarios where the busywork of text editing really is on your critical path, but even as a flue…

For me, it is definitely worth the effort. But I didn't try to learn it all at once, so it didn't feel like that much of an effort. I got good enough at first, then as I kept using it and found something I was doing repeatedly, I'd figure out the easier "vim way" to do it. Over the years all those little improvements has made me able to edit code far more quickly than I could possibly do with another editor.

I agree that we spend far more time thinking about code than we do editing it, but being fluent in vim means that when I have the code in my mind, or I decide how I want to refactor something, I can get those ideas out with very little effort. If you reduce the friction of translating thoughts into code, it means you can spend more time thinking about the code instead of futzing about with an editor. Once you get good with vim, it _reduces_ your cognitive load. I know that from the outside all these tricks and tips seem like random jibberish, and impossible to remember, but when you live inside the vim bubble it really does make sense. You find the tricks that fit your mind and your work the best. They quickly become muscle memory and you don't think about the keys at all.

That said, it _is_ a cult. I've seen cool features in other editors, and I've tried to use them, but it always feels like I'm typing with mittens on my hands. And I come crawling back to vim.

Re: Vim Anti-Patterns

#218

Earlier quoted context omitted.

Well, I've been using vi and it's brethren since about 2002 and I've pretty much always used the arrow keys; after some point it becomes muscle memory... I never really understood what the problem with this was; I rarely actually use them (esc|capslock /str,ctrl+f|b etc) is usually how I move around and if I'm wanting to move a few chars my little finger is not moving very far (at least, on apple keyboards)... Is thi…

> Do you see any big advantage of using a lot of buffers/tabs/splits over running multiple vims inside tmux? I think my personal benefit is that I don't have to make a bunch of new SSH connections every time I want to split files in vim, I can just open up a new buffer.

[deleted]

Re: Vim Anti-Patterns

#219
post #145

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?

Pretty funny. I found myself asking "What does C-x do when autocompleting?" I took the 'x' literally, instead of realizing you meant C-n, C-p. xD

x is literal. For context aware auto complete of a word try C-x C-n/p. For a line try C-x C-l. For a directory do C-x C-f. And remember that this is context aware, you can hammer C-x C-n C-x C-n or C-x C-l C-x C-l. Stuff is really powerful. Changed the way I program and I never see enough articles mention it.

Re: Vim Anti-Patterns

#220
post #207

While it's unarguably fun, I can't believe the effort required to become actually good at vim (as opposed to just using a few of the easier features) will ever pay itself off. (These days, at least - if you spend your days editing code in a terminal over a dialup connection, then it's absolutely worth it!) Maybe there are scenarios where the busywork of text editing really is on your critical path, but even as a flue…

  Any extraneous cognitive load just takes focus away from what I'm actually meant to be doing.
And Vim is the tool to do just that. It saves your cognitive load spent to edit text so you have more for thinking.
Post reply on HN