Live data from Hacker News

To Master Vim, Use It Like Language

danielmiessler.com

111–120 of 124 posts

Re: To Master Vim, Use It Like Language

#111
post #43

Earlier quoted context omitted.

Aiming to combat "you don't know what you don't know", here's a list of things to consider. How comfortable are you with: * find/replace/regexes * registers and macros * vim settings (spell, list, highlight, number, wrap) * the plugin ecosystem * editing multiple files simultaneously (splits, buffers, moving between them) * folds Anyone else want to chime in with stuff I've either forgotten or don't know I don't know…

I asked on /r/vim about "Who uses folds?" Didn't get any takers. I always forget they exist and haven't used them in my workflow yet. Tag files would be another good one.

I couldn't live without folds. Whether I'm in C++, Java, Go, Ruby, or a custom ASCII report I've written, I use them extensively. I add fold tags around every method/function implementation, and sometimes an additional one around around groups of them (e.g., classes). I generally set foldlevel to 0, so most files I enter have a few intro lines and then N folds, so that even large (1000+ lines) source files fit into a single page or two. I almost never use searches or tags to find declarations, since I can usually navigate to them directly with a single keystroke.

FWIW, I map to za, so that I can unfold/refold quickly. I also map - to zx to quickly fold up a file I may have drilled some holes in.

Re: To Master Vim, Use It Like Language

#112

This article is well written, but it has nothing to do with mastering Vim. It goes no further than running "vimtutor" at the command line. It has all the same tips and shortcuts as any other vanilla Vim tutorial. This is a common problem among Vim articles and tutorials. Authors title them as if it will give you Vim mastery, but instead it only offers the basics. Mastering Vim means going beyond vanilla movements and…

Article author here. The irony in your comment is that I recommend Drew's book in the primer, and Drew has recommended this primer as well. Maybe they're both good ways to learn Vim.

Then title it "Vim Primer," which is accurate.

Re: To Master Vim, Use It Like Language

#113

Earlier quoted context omitted.

Way more useful (for me anyway) is mapping Capslock to ESC. It works with any vi anywhere as long as you are using your main machine to connect. Also with inoremap don't you have to wait for the letter j to show up until you type your next character? That would drive me crazy. Edit now that I have actually looked at the article: Yes, you can map it to Control but for me it's an awkward place to put a modifier. What i…

I have a similar remapping of Caps: * When I tap Caps, it's ` ` * When I hold Caps OR hit it in combination with any other key, it's ` ` It really feels like the best of both worlds. I primarily develop on OSX, so I use https://pqrs.org/osx/karabiner/ to handle the remapping.

This works great on my Linux machine. On the Mac though I hate that all Mac apps use Command for well, all command-key combinations instead of Ctrl, so I map the Caps-lock to Command instead, but while Karabiner can do the dual "Esc on tap plus other on hold" for Ctrl, Shift and Option keys, it cannot frustratingly do it for the Command key. ITerm can switch caps-lock back to Ctrl, but then I lose the Esc double function. It's maddening.

Re: To Master Vim, Use It Like Language

#114

Earlier quoted context omitted.

Article author here. The irony in your comment is that I recommend Drew's book in the primer, and Drew has recommended this primer as well. Maybe they're both good ways to learn Vim.

Then title it "Vim Primer," which is accurate.

This is hardly a primer. If somebody is using the motions and actions described in the article they may not be a complete wizard in obscure vim features, but they are certainly far beyond being merely "primed" to use vim. I've been an avid vim proponent for years and I still picked up new things from this article.

Re: To Master Vim, Use It Like Language

#115

While a tweaked configuration can be a great productivity boost, it has a major drawback. My main reason for using vim is its ubiquitousness. Whenever I need to ssh into a box to check something out, I can trust that it's there. However, I cannot trust that its configuration has been tweaked like I expect. Hence, I stay away from getting used to non-standard key mappings.

I think this follows the 90/10 rule. Most of my work is on my own machine. Occasionally I will be on a server and attempt to use some configuration from my personal .vimrc but instead have to fall back to slightly slower methods.

The time lost in that 10% is totally worth the cost of the time saved in the 90%.

And since everyone uses their text editors differently, it's not practical to move any one individual's personal configuration choice into vim core.

Re: To Master Vim, Use It Like Language

#116
post #3

> inoremap jk Using two keystrokes instead of ESC to leave insert mode is definitely a personal preference and not necessarily more efficient or comfortable.

I prefer to avoid remappings so that I can use vim at any machine without having to figure things out, so my preference for escape is Ctrl-[. It takes a bit of getting used to but once you get it, left hand never has to reach up anymore.

I wish I could use this, but Dvorak moves that [ just a little too high for this to be practical. :(

Re: To Master Vim, Use It Like Language

#117
post #8

Earlier quoted context omitted.

That's just not what vim is... I don't even really know where to begin, you're just flat out wrong. I'd say you're confusing vim with something else, but I don't even know what else fits that description.

1,$s/a/b/

"Thbt" isn't even a word.

Re: To Master Vim, Use It Like Language

#118
post #64

Earlier quoted context omitted.

Opening a new buffer. Figured I'd try :new, and wound up getting good at splits. Still don't know how to just open up a new, blank buffer in the window I'm in without specifying a filename to :e.

:enew

Just what I needed. Thanks!

Re: To Master Vim, Use It Like Language

#119
post #47

Earlier quoted context omitted.

I barely use the regexps. There are 2 things that vi/vim are quite good at that are very relevant today. I don't know of any alternative that is as good. First, efficiency of bandwidth over an ssh connection. You might think, "Oh but there is tons of bandwidth on the internet today". However, I actually use vim to pair program with people in the UK while I'm in Japan. Vi commands can easily deal with variable latency…

I by no means agree with the guy you're replying to, but I don't think your vocalized example is fair. With vim, your state is in the "sentence" you've written. With a typical editor your selection is in the state of your editor, primarily its selections. It's more like "Do this here." vs. "Look here. Do this." One thing I used to do is visit http://www.vimgolf.com/ and compete with the best solutions there. Aside fr…

We actually have several licenses of Sublime kicking around at work because everybody moved over to Vim. I know several people who are really fond of Sublime, but lack of a text mode put it at a bit of an evolutionary disadvantage in our shop since we do a lot of remote pair programming over SSH. It's a bit of a shame since we are almost a monoculture now (one guy still uses Emacs and 2 are vim/sublime bilingual -- every one else is on vim pretty much exclusively). I think it's nice to have some diversity to keep people thinking of the possibilities. I'm in the process of moving over to Evil mode in Emacs pretty much for that reason.

Probably my example was a bit poor. I wasn't trying necessarily make the argument that Vim is more keystroke efficient than other editors. I used Emacs for 20 years before I switched to Vim and I was quite efficient with it. I was more trying to convey the idea that the way of thinking was different. Instead of concentrating on the immediate motion of the cursor, I'm concentrating on the structure of the document.

Lately I've been thinking it would be nice if someone were to think a bit more about extending the state of the art in modal editors. Vim was a nice extension of vi, but the grammar is still pretty crufty in a lot of places. It would be cool to rethink it from scratch, I think.

Re: To Master Vim, Use It Like Language

#120
post #47

Earlier quoted context omitted.

I by no means agree with the guy you're replying to, but I don't think your vocalized example is fair. With vim, your state is in the "sentence" you've written. With a typical editor your selection is in the state of your editor, primarily its selections. It's more like "Do this here." vs. "Look here. Do this." One thing I used to do is visit http://www.vimgolf.com/ and compete with the best solutions there. Aside fr…

We actually have several licenses of Sublime kicking around at work because everybody moved over to Vim. I know several people who are really fond of Sublime, but lack of a text mode put it at a bit of an evolutionary disadvantage in our shop since we do a lot of remote pair programming over SSH. It's a bit of a shame since we are almost a monoculture now (one guy still uses Emacs and 2 are vim/sublime bilingual -- e…

> I was more trying to convey the idea that the way of thinking was different. Instead of concentrating on the immediate motion of the cursor, I'm concentrating on the structure of the document.

In what way does the multiple selection model not concentrate equally on the structure of the document? It's true that vim has a larger vocabulary than a typical editor, but its grammar is actually weaker. For example, I know of no way to combine two arbitrary motions.

Consider the case where you want to delete all strings containing the word die, where the string grammar is non-trivial. In a selection-based language you can

* select-all-"die", manually checking that they're inside strings

* select-enclosing-block

* delete

If one had a language-aware string token finder (and, frankly, a token-aware editor would be amazing - maybe I should edit Sublime to do that...), one could even

* select-all-string-tokens

* select-all-"die" inside selection

* select-enclosing-block

* delete

This is a very structural approach. I don't know a neat way of doing this with vim. (I'd be happy to learn I'm wrong!) There are other examples, like where one wants to work on some collection of things in lockstep and vim's inability to hold state through selections between commands results in a difficult workflow. The multiple selection model remains semantically unperturbed.

I would very much be interested in a modal editor that doesn't just try to copy vim - working on multiple selections with a large vocabulary and syntax-awareness would be wonderful. I also find some things, like temporarily restricting actions to a subset of selections, needlessly hard in Sublime. There's a lot that can be done!

Post reply on HN