Live data from Hacker News

Vim tricks

hillelwayne.com

41–50 of 63 posts

Re: Vim tricks

#41
post #7
post #3

":, @: ": is the register storing the last executed command. You can write ":p to print it to the buffer. @: reruns the last command. That seems like a mouthful. I use : to run the last command and some more to run the ones before that.

And if you wanted to repeat that 10 times you would...?

Press up ten times. That's still what a lot of us do in terminal (particularly when we're on a machine without fancy shell history fuzzy-searching etc.).

I guess I might press and hold at ten.

Re: Vim tricks

#42
post #2

I’ve discovered q: when trying to quit vim in a hurry. You always keep finding new quirky things to do in vim but I guess the same hold true for other text editors like Emacs

That's how I found `K`. I was surprised the first time I got a man page open. Now I find it pretty useful and wish it extended to more than man pages.

I remap that to query dict in prose contexts. Mostly for mutt:

    au FileType mail set keywordprg=~/bin/dictless

Re: Vim tricks

#43
post #15

The problem is, how do you remember all of this stuff? Tabdo/bufdo is as advanced as it ever gets for me.

Vim is an editing language of actions, contexts, and count, with registers, trees, and buffers. The basic elements are pretty simple but in combination give tremendous power:

https://www.invidio.us/watch?v=wlR5gYd6um0

Unfortunately, this aspect is poorly documented. Thoughtbot's video is among the best I've found. And that's with 30 years' experience.

Re: Vim tricks

#44
post #7
post #3

":, @: ": is the register storing the last executed command. You can write ":p to print it to the buffer. @: reruns the last command. That seems like a mouthful. I use : to run the last command and some more to run the ones before that.

And if you wanted to repeat that 10 times you would...?

Use vim-repeat:

https://github.com/tpope/vim-repeat

Re: Vim tricks

#45
I use gf (mnemonic: go file) all the time -- it will grab the string under the cursor (the cursor doesn't need to be at the start of it), then attempt to open a file with that name. You can look up the details but it uses a path type mechanism so if the name of the file isn't absolute, it will check the path.

Re: Vim tricks

#46
Text objects are crucial to composing vim commands. Vim offers quite a few but honestly, there’s plenty more. I’d recommend using the vim-textobj-user as base to add appealing text objects. Personally, I can’t live without the “entire” text object which allows one to act upon the entire file. Like “indent entire file” etc.

https://github.com/kana/vim-textobj-user

https://github.com/kana/vim-textobj-entire

Re: Vim tricks

#47
post #29

Earlier quoted context omitted.

At my billing rate "15 days straight" is approximately equal to a low end BMW. So I think tabdo/bufdo will have to do for now. At least until I get a salaried job and can learn the rest at my employer's expense. I do think there's Pareto principle at play with all this obscure stuff. Knowing 20% gets you 80% of the benefit, every additional percent gets you exponentially smaller fraction of the remaining 20%. That's…

>At my billing rate "15 days straight" is approximately equal to a low end BMW. So, you’re saying you are making too much money to learn something new?

Oh no, I learn "something new" every day. It's just not related to text editing. Don't get me wrong, I'm pretty good at editing in vim. After all, it's been my editor of choice for the last 15 years or so, and I see no reason why it would not remain in that role indefinitely. I'm just not convincing that learning the more obscure stuff is valuable.

Re: Vim tricks

#48

"Exobrains, on the other hand, stuff Vim full of plugins, functions, and homebrew mappings in a vain attempt to pretend they’re using Emacs." This is disturbingly accurate from my point of view. I keep wondering if I should finally jump ship and stop tweaking vim with questionable results. Spacemacs? Pure emacs + evil? Suggestions welcome.

Spacemacs is peanut butter meets chocolate. Apps like Magit and org-mode with vi's modal editing are truly superior.

Even when I am using Xcode or some ide that requires I use it, I still pop open Magit in Spacemacs. Love it.

The discover ability of Spacemacs is really second to none and makes it much faster to learn and keep learning.

Spacemacs is Nutella to keep the analogy going...

Re: Vim tricks

#49

"Exobrains, on the other hand, stuff Vim full of plugins, functions, and homebrew mappings in a vain attempt to pretend they’re using Emacs." This is disturbingly accurate from my point of view. I keep wondering if I should finally jump ship and stop tweaking vim with questionable results. Spacemacs? Pure emacs + evil? Suggestions welcome.

I tried the switch a couple times. A few times with spacemacs, a few times with trying to write my own config from scratch with evil. Not sure what it is, maybe the way emacs configs are setup but I found vim just so much easier for me to manage with less magic and more predictability.

Re: Vim tricks

#50

I use gf (mnemonic: go file) all the time -- it will grab the string under the cursor (the cursor doesn't need to be at the start of it), then attempt to open a file with that name. You can look up the details but it uses a path type mechanism so if the name of the file isn't absolute, it will check the path.

gf is awesome. Great for navigating scripts that run other scripts and also useful for creating links within a personal wiki of markdown files without a plugin like vim-wiki. While I do use a lot of plugins, I find it's a lot better to select plugins that add to vim's editing language (vim-eunuch, vim-surround, vim-vinegar, vim-exchange, vim-angry, vim-sexp-mappings-for-regular-people, vim-commentary) rather than plugins which agglomerate IDE features onto vim (vim-wiki, nerdtree, etc).

While I do have a few of these IDE-like plugins (undotree, for example), I think it's better to try plugins which embrace the "vim way" first before investing in a full IDE-like plugin. I don't mean to gatekeep by criticizing IDE-like plugins, but just to say that spending the time to learn normal mode as a true language (verbs, nouns, and all) and using plugins that follow this idea is a worthy investment. Then, add IDE-like plugins to work around the frustrating rough edges of vim once you've milked all that you can out of it.

Post reply on HN