Hacker News new | ask | show | jobs
by PaulJulius 3401 days ago
I think one of the most under-mentioned features of vim is that a line is one of its fundamental units.

Suppose you want to move a few lines of code from one function to another in a regular GUI text editor. If you select these lines with a mouse you need to be careful about exactly where you click to start highlighting and where you end highlighting. Do you start from the beginning of the first line or from the end of the previous line? Do you include the new line at the end? (Can you even?) Then, when you paste, where do you paste? Do you just put the cursor on the line you want to paste before and paste? Or do you put the cursor at the end of the line you want to paste after, hit enter and then paste? Oops, you did it wrong and now this the first line isn't indented at all, or now you have two lines of code on one line.

After a while you figure out where you need start and end the selection, and where you need to paste, but it's still easy to mess up.

This isn't an issue in vim. Using Visual Line mode selecting and pasting is super simple. 'V' to enter visual line mode, 'j' and 'k' to highlight everything you want (and 'o' to switch which end of block you're moving!), 'y' to yank (copy) or 'd' to delete. Then put the cursor _anywhere on the line_ that you want to paste after and hit 'p'.

The ease of use is one thing, but I also think it makes more sense to have an entire line be a fundamental unit. When you're editing code, you're usually moving codes around or editing single lines. I rarely copy and paste just one part of a line to another, and I think in most cases it's easier to just paste the line and change the parts I don't want.