Live data from Hacker News

Vim tricks

hillelwayne.com

11–20 of 63 posts

Re: Vim tricks

#11

> U is the same as u except it does the undo as a new change, which is functionally useless. Unless I’m mistaken, this is the default undo behavior for emacs...What horror to only have vim’s forward and backward undo history! Said the emacser on the vimmer’s post.

Maybe misunderstood what you meant, but vim's undo is not linear but rather tree-like. You can undo, make a change, and still get back to the initial state. https://vim.fandom.com/wiki/Using_undo_branches

Edit: this also seems to be in the original post

Re: Vim tricks

#12

> U is the same as u except it does the undo as a new change, which is functionally useless. Unless I’m mistaken, this is the default undo behavior for emacs...What horror to only have vim’s forward and backward undo history! Said the emacser on the vimmer’s post.

vim also has "undo tree" functionality built in, the interface is just different than emacs's.

:help undo-branches http://vimdoc.sourceforge.net/htmldoc/undo.html#undo-branche...

Re: Vim tricks

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

Take a look at `:help 'keywordprg'`.

Re: Vim tricks

#14

Earlier quoted context omitted.

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.

Take a look at `:help 'keywordprg'`.

Can I do things like get `K` to work on python commands? Including modules? Or with other languages?

I see that I can do `set keywordprg=pydoc` but I want modules too.

Re: Vim tricks

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

Re: Vim tricks

#16
post #9

There's a few commands I LOVE but find frequently unmentioned. In insert mode, is a contextual completion. So like the normal or you just do and you can keep hammering the to fill in multiple "words". You can also complete lines, file paths, dictionary words, thesaurus words, tags, spelling, etc. See `help ins-completion`. Seriously, I can't do without this command. needs to be in everyone's daily use. Also in insert…

can you give more examples of in code editing? I have tested that out in vim and its cool but i cant think of times I want to repeat a series in another part of the document, perhaps I'm just very uncreative right now

Thanks

Re: Vim tricks

#17
post #15

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

You have to make a deliberate attempt to learn it. What i would do is when coding I would focus on a single command and do it 5 or 6 times until it was engrained, then I would go to the next one. I spent about 15 days straight fairly intensively learning vim .. taht was 8 years ago. Best decision I have ever made in my entire programmign career. Now I pick up new vim commands like I am multilingual in 20 languages. All the commands I can usually remember without even typing them, they just stick. It definitely has the rolling snowball momentum effect

Re: Vim tricks

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

Re: Vim tricks

#19
One I learned recently transferring some LaTeX over to rST is visual highlight => "gq". This breaks up long lines to multiple lines based on your stored text width. It can also be coupled with motions, e.g., "gq}".

Re: Vim tricks

#20
post #16
post #9

There's a few commands I LOVE but find frequently unmentioned. In insert mode, is a contextual completion. So like the normal or you just do and you can keep hammering the to fill in multiple "words". You can also complete lines, file paths, dictionary words, thesaurus words, tags, spelling, etc. See `help ins-completion`. Seriously, I can't do without this command. needs to be in everyone's daily use. Also in insert…

can you give more examples of in code editing? I have tested that out in vim and its cool but i cant think of times I want to repeat a series in another part of the document, perhaps I'm just very uncreative right now Thanks

Totally. But I will tell you, is a habit built around the other options too. So I just use on any completion (which I frequently use ).

Here's a dumb example (dumb because there's other ways to do it that are better)

Let's say I'm overloading a function.

void foo(int a, int b) {}

I could do v until I fill in the b, then type ", int c)". Now it'd be totally easier to do "v backspace , int c)", but that's a different point.

Maybe this one is a little more useful

"def _" may expand to "def __init__(self" Note that here I'm holding down ctrl and just hitting "xpxp"

Honestly I end up finding a lot of patterns in my code just because I started thinking about it this way. It is more one of those things where once you start thinking about it with it in mind you will find patterns.

It is also an easy habit to develop, if you already use , because when you press ctrl you just also hit x and keep your pinky down on ctrl. I feel like there is just no downside to using because in reality it is just one more keystroke, which is done with the other hand (so even less increase in work).

Post reply on HN