Sawyer
Sawyer

Reputation: 15917

Vim: copy/delete line from the first none blank character to the last none blank character

Most time when I copy or delete some code in Vim use yy or dd, I also got the indent spaces. Is there a quick command that I can yank a line without leading or trailing spaces?

Upvotes: 6

Views: 405

Answers (2)

Greg Hewgill
Greg Hewgill

Reputation: 992737

There's another way to solve your implied problem. After you yank line(s) into the buffer, you can then paste them using the appropriate indent using ]p or ]P. These paste commands automatically adjust the indent of the pasted line(s) to match the indent of the line where the cursor is.

Upvotes: 6

luqui
luqui

Reputation: 60463

I'm not a wizard, but:

^v$gey

works for me. You can always make an alias.

EDIT: here's a better one that doesn't rely on visual mode.

^yg_

Upvotes: 7

Related Questions