Live data from Hacker News

Vim tricks

hillelwayne.com

51–60 of 63 posts

Re: Vim tricks

#51
post #41
post #7

Earlier quoted context omitted.

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.

Your machine probably has ^r for working through bash history

But that aside, if you’re into arrow pressing, a few lines in your .inputrc can go a long ways

Test this out sometime:

  # Incremental searching with Up and Down and Left and Right
  "\e[A": history-search-backward
  "\e[B": history-search-forward
Now you can type “find” and press up/down arrow to just cycle through history that starts with find

Re: Vim tricks

#52
post #26

"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 particularly prefer doom-emacs [1]. I migrated from Vim to Spacemacs, however doom-emacs is leaner, faster and has better evil integration. For example, Spacemacs has no mapping for evil-numbers, however doom-emacs maps it to Ctrl+A (increase number) and Ctrl+Shift+A (decrease number) [2]. However, you will probably need to do some customizations in doom-emacs. Spacemacs works mostly only using its internal layers,…

I recently moved from Spacemacs to Doom. I second, that it’s so much better, in that it’s faster, leaner, and easier to comprehend. Some of the keybindings could be more thorough. I find myself M-x’ing a lot. I take this as an acceptable trade off, as keybindings are easy to set on one’s own.

Re: Vim tricks

#53

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.

Don't forget about its twin gx. For example on MacOS gx uses the open command to open a file in the default application. Really helpful when you want to open up a website quickly in your browser or you have the url to an image in a markdown file and want to see it. Helpful trick for relativ paths: https://www.reddit.com/r/vim/comments/7xs8x3/opening_local_r...

Re: Vim tricks

#54
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...?

Personally, I would do 9@@ after the first @:

Re: Vim tricks

#55

Earlier quoted context omitted.

Interesting, I don't often use Python but recent project had few 3000+ lines .py files, which make Vim _very_ unresponsive when editing. Other languages weren't so problematic but Python code is what made me look at Emacs direction at the first place.

This surprises me. How does it make vim unresponsive? I frequently open multi-GB sql files without vim choking. Are you using some particular plugins?

I was using/am using:

    Plug 'tmhedberg/SimpylFold'
    "Plug 'python-mode/python-mode', { 'branch': 'develop' }
    "let g:pymode_python = 'python3'
... in different combinations. Deleting any char takes surprising amount of time, so much so that I usually mark block to delete instead of char by char even if it is three char block. Of course I may be using wrong plugins, however that's what I found that should be used in various articles online.

Re: Vim tricks

#56
post #26

"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 particularly prefer doom-emacs [1]. I migrated from Vim to Spacemacs, however doom-emacs is leaner, faster and has better evil integration. For example, Spacemacs has no mapping for evil-numbers, however doom-emacs maps it to Ctrl+A (increase number) and Ctrl+Shift+A (decrease number) [2]. However, you will probably need to do some customizations in doom-emacs. Spacemacs works mostly only using its internal layers,…

Great tip, thanks, trying it now. Seems nicer and easier to tweak than spacemacs, from my perspective.

Re: Vim tricks

#57

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

U is not the same as u, though: u undoes the last change, U undoes all latest changes on one line.

Re: Vim tricks

#58
post #15

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

Anki. It doesn't take long.

Re: Vim tricks

#59
> If you’re constantly tweaking your vimrc, do yourself a favor and add a command for that:

> command! Vimrc :vs $MYVIMRC

I just use marks for this. Capital letter marks work across files, I use 'I (for init.vim, I use neovim).

Re: Vim tricks

#60

Earlier quoted context omitted.

This surprises me. How does it make vim unresponsive? I frequently open multi-GB sql files without vim choking. Are you using some particular plugins?

I was using/am using: Plug 'tmhedberg/SimpylFold' "Plug 'python-mode/python-mode', { 'branch': 'develop' } "let g:pymode_python = 'python3' ... in different combinations. Deleting any char takes surprising amount of time, so much so that I usually mark block to delete instead of char by char even if it is three char block. Of course I may be using wrong plugins, however that's what I found that should be used in vari…

Sorry to hear that. Might be worth reporting to the plugin authors, as I don’t think it’s an inherent issue with vim. When editing the sql files I’m referring, it includes syntax highlighting, etc. so I would assume it should work just fine in other cases. But I’m not really dealing with large py files, in general, so I can’t say specifically.
Post reply on HN