Hacker News new | ask | show | jobs
by overgard 3979 days ago
Here's the thing: when you're coding, how much time is spent on reading vs writing? For me it's probably 90/10. Since most my time is spent concentrating on understanding code, the last thing I want is an editor that forces me to consciously think about text operations. "d[downkey]4" might be theoretically more efficient, but I spend way less cognitive energy holding down the shift key and pressing the down arrow 4 times.

The other thing is efficient navigation within one file isn't super useful to me. I spend most my time doing find-in-files or jump-to-definition or rename-across-this-project. Vim kind of sucks for all those use cases. There are plugins of course, but that just brings it up to par with popular IDE's, except with a clunkier interface.

I say this as a person that knows vim well. If I'm SSH'd into a server and I need to edit a config file, vim is the first thing I'll reach for, but for coding, I'm pretty much only using it if I'm using a language that doesn't have a nice IDE already.

5 comments

>Since most my time is spent concentrating on understanding code, the last thing I want is an editor that forces me to consciously think about text operations. "d[downkey]4" might be theoretically more efficient, but I spend way less cognitive energy holding down the shift key and pressing the down arrow 4 times.

The point is well taken, but don't forget that for most people that downside of increased cognitive pressure goes away after a few days or weeks of regular vim usage. I've been using it for about a year and all the combos I normally use are second nature to me (and have been for months). Don't underestimate the human brain's ability to grow and adapt and for incredibly complicated things to quickly turn into routine.

For the record, I almost never use vim's much touted hit a number key then an action to do it n times feature. I have modified it so j and k do the normal down/up one line and J K go down/up seven lines or so for scrolling. [1] If I'm doing something like deleting a line and have to delete a bunch (common case), then I'll "dd" to delete line and then hit "." (which repeats the last action) three or four times until satisfied. Way easier than counting the number of lines to delete then typing "4dd" imo.

[1] Note for anyone who wants to duplicate this: it was still unbearably slow to just hold down J or K to scroll because the default delay between depressing a key and when OSX decides you are actually holding it down and not just pressing it once is too long. Decrease it in the native settings of your OS for a smoother experience.

I used it as my primary editor for two months, which IMO is more than enough time to give to a project like that. I was efficient in it, but none of the supposed productivity gains came about. On the other hand, in my IDE I can control-click on a method name to jump to it, or hit ctrl-r to rename something across the entire project, or hit alt-enter to automatically import a symbol when I know the name of a class I want but I can't quite remember the namespace it's in. Those things really do save me a lot of time; but the efficiency comes from the development environment being able to understand the code structure, not from being able to stack key commands.

If someone wants to use vim I'm not saying they shouldn't, I just think it's vastly overhyped.

I found I had to go a bit beyond the settings that OSX's native manager allow for to get the key repeat that I was after. Karabiner has a setting for adjusting it properly in ms (so you ~ match other machines). would recommend.

https://pqrs.org/osx/karabiner/

After using vim for a while, you don't think about text operations consciously, it's all subconscious / muscle memory. It's possible to do something like "shift+press the down arrow 4 times, backspace" in Vim by the way: "Vjjjd" or "dd...". In fact, as I was typing this comment I couldn't even remember what the right key strokes were and had to open Vim, delete 4 lines and try to consciously pay attention to which keys my fingers were hitting! So even if you have to think consciously about text operations in the beginning, don't let that scare you off as it will almost certainly become muscle memory after some practice.
I think your example is somewhat badly chosen.

If I had to delete four lines, I'd most likely mash dd until done, or maybe Vjjjd. It would be completely automatic and not require reaching for numbers or the arrow keys, making it significantly faster and more comfortable as well.

I find that vim is extremely good for reading code, since navigating around a file is very easy (and I am in no danger of accidentally editing code while not in insert mode.).

Not having to reach for the arrow keys while navigating is a huge plus as well, since it keeps my fingers on the same position whether I am typing or navigating.

EDIT: Vjjjd, not Vjjjjd. Drives home the point that it's automatic, since I can't get it right if I think about it...

And in true TMTOWTDI fashion, I'd add that depending on what the four lines were (in relation to my cursor and their content and, frankly, whatever pops into my head first), I'd probably do 4dd, or d4j, or d] or d} (if the final line was the end of my current sentence or paragraph) or d2] if it was two sentences.

My favourite bit is that I use which one pops into my head first. If I think "until the next occurrence of 'nded?'" then that's what I do, with d/nded?<RET>. If I think "up to line 438" then I can do d438g. It reduces the number of decisions I have to make, which increases my mental stamina.

Great point about reading the file. I feel paranoid when using a text editor like sublime now just arrow key-ing or scrolling around a file since hitting practically any key will insert or delete a character!
This is why any decent text editor or IDE has an UNDO method.
"""an editor that forces me to consciously think about text operations"""

"""I say this as a person that knows vim well."""

These two phrases don't go together.

Would you say you knew how to play a piano well if you were still consciously thinking about where each note was?

If you don't use vim to the level that it's subconscious and "in your fingers" it might not seem all that useful...

Fwiw "ag" and the various plugins around it make your use case pretty trivial.

> These two phrases don't go together

Sure they do. VIM has such a culture of minimizing keystrokes that pretty much anything you do, you start wondering if you could have done it with fewer key strokes, or if you could have done it better. It's hard NOT to think that way because that's the entire point of getting into VIM in the first place.

Speaking of minimizing keystrokes in vim, you might enjoy this puzzle from the 2012 MIT Mystery Hunt

http://www.mit.edu/~puzzle/2012/puzzles/william_s_bergman/in...

(because it's about minimizing keystrokes in vim!).

Edit: I didn't know about vim golf, which is a slightly different take on a similar phenomenon.

The goal is to be able to FLUENTLY edit text. Lowering the number of keystrokes can aid that but is ancillary.

Fluency comes after learning it well enough that you aren't thinking about it anymore.

Yes you should occasionally reevaluate where you are on that scale but I don't see that as what you are saying.

Enjoy your ide if you have it figured out to your satisfaction.

Cheers

As someone who uses vi mostly for reading and not writing, its almost no mental load. pgup, pgdn to scroll; ? and / to search; and G :0 to goto bottom/top. I use these without even thinking.