Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim duplicate with same cursor position

Tags:

vim

I want to duplicate a line with Vim. Every time when I use yyp or any other command, I have to jump the cursor to the position where it was. Is there any trick to duplicate a line and jump the cursor to its position, like maybe using a macro to save current the cursor position, duplicate, and then jump to the required position?

like image 694
challenger Avatar asked Mar 05 '26 07:03

challenger


1 Answers

The only solution I'd see to do what you want, given you only use it for yyp (i.e. copy currentline and paste it below), is to record in a macro:

mmyyp`mj

what that does is:

  • to record a mark m,
  • copy current line
  • paste it
  • jump to col+row location of the mark m
  • move the cursor one line down

ideally what you'd want is a jump to a column, not changing the row. I'm not sure if it's possible, I never needed that before.

like image 93
zmo Avatar answered Mar 07 '26 05:03

zmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!