Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use vim's mark functionality but keep the cursor where it is

Tags:

vim

Vim's mark functionality allows one to apply functions to every line between the current line and the marked line. For example if I mark the below line 3 with k

1 var a = 0;
2 while (a < 10){
3 a++;
4 console.log('Hello');
5 console.log('world');
6 █
7 }

and from the cursor position () issue the command >'k, I will get the following

1 var a = 0;
2 while (a < 10){
3 █  a++;
4    console.log('Hello');
5    console.log('world');
6
7 }

(Note: the cursos might be over the a, but that's not important)

This is the desired effect, but now the cursor has moved all the way back up. For most cases this is desirable, as I usually want to edit from the top. But in this case, I might want to indent again, so I have to navigate once again to the bottom. In cases where I am indenting 20+ lines this becomes a real chore.

How can I temporarily disable this seek back function?

like image 860
puk Avatar asked Dec 28 '22 09:12

puk


2 Answers

The simplest solution is to press `` (i.e. back-tick twice) after your command to jump back to the previous location.

like image 104
Matthew Strawbridge Avatar answered May 18 '23 23:05

Matthew Strawbridge


After you do >'k just hit '' (single quote, single quote) - not back tick, I think - and you'll go back to where you were.

If you do this often then you can map a key to do it in one:

:map >> >'k''

Then whenever you hit >> it'll do that sequence.

like image 21
ams Avatar answered May 18 '23 23:05

ams