Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put cursor at the end of selected block after some operation

Tags:

vim

Couple of examples that I encounter quite often.

Indenting some code

E.g. I want to put code block inside if statement:

puts("hello");
puts("world");

I enter if (pid > 0) { before the first line, then press Esc,j,Shift+v,j,>:

if (pid > 0) {
  puts("hello");
  puts("world");

Now cursor is at the beginnig of the first puts and to enter closing bracket I need one extra j to go to the end of the indented block.

Pasting block and adding to end of it

Almost the same example. When extracting some code to function, after pasting it with p I need to append return statement or closing bracket at the end. If I'm lucky there will be empty line after pasted block and I can use } to jump right there, but it's not always the case.

Question

So the question is how to jump to the end of the selected block after some operation performed on it (pasting, indenting, etc)?

like image 486
max taldykin Avatar asked Dec 03 '25 02:12

max taldykin


2 Answers

`]

Will move you to the end of yanked or previously changed text.

See

:h `]
like image 113
Peter Rincker Avatar answered Dec 05 '25 17:12

Peter Rincker


As an alternative behaviour, you could insert the closing } first and then indent the code inside the new scope automatically.

Being at the last line of the new scope in normal mode:

o}ESCv%=

like image 25
bitmask Avatar answered Dec 05 '25 16:12

bitmask



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!