In vim, how to visually select previously inserted text

Usually I visually select a block and copy / cut it somewhere else, then I found that it always formats the inserted text, so there is a way to quickly visually select the text again.

+6
source share
3 answers

Each command that has changed the buffer (and yanks) will set the labels '[ and '] around the changed area. This way you can reformat your inserted block with:

 `[v`]= 

Some people go so far as to use the following mapping to reselect the last modified piece of text:

 nnoremap <expr> gV '`[' . getregtype()[0] . '`]' 

With this mapping, you can simply make gV= and format the text just inserted.

However, if you have the unimpaired.vim plugin and you insert linewise, you can use the =p command that it provides. This inserts and then reformatts the text at a time. It also provides some other alternative insert >p commands, for example, inserts one level of indentation deeper.

+5
source

The way I use is straightforward. The cursor is at the beginning of the pasted text after pasting. Press V to go to visual selection, press '] to go to the end of the insert.

These are 3 keystrokes. If it is too long, you can do a mapping for p

 map p pV'[ map P PV'[ 
0
source

For visual mode, gv is the standard way to re-select the previous area.

If you want to switch between the start and end positions of the area, just press o .

As mentioned in other answers, you can apply the standard = command in this re-selected area.

It works well after inserting p or p .

The advantage is that you do not need any custom mapping.

0
source

Source: https://habr.com/ru/post/982231/


All Articles