Couple of examples that I encounter quite often.
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.
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.
So the question is how to jump to the end of the selected block after some operation performed on it (pasting, indenting, etc)?
`]
Will move you to the end of yanked or previously changed text.
See
:h `]
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%=
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With