I'm using GVIM on Windows, if it matters.
I often select a block, do something, and then need to do something else with the same block, but of course once I do anything with the block, I'm out of visual mode.
Is there a way to re-select or act on the previously selected visual block?
Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.
Visual mode makes it easier to highlight and manipulate text in Vim. Ansible playbook files are text files in a YAML format. People who work regularly with them have their favorite editors and plugin extensions to make the formatting easier.
To use visual mode operators, first visually select an area of text ( v/V/Ctrl-v + motion), then press a visual-mode operator key. That's it.
Use ctrl+v to select a column of text consisting of the first character of the place you want your new column to go in front of. Use I to go into insert mode, and type one space. Press Esc, and you'll see you have inserted a column of single spaces. Now use ctrl+v again to highlight the column of spaces.
I believe gv
will reselect the previous block...
gv as Joe pointed out does the trick (+1), but an extra tip as well is if you do a :s
with a visual selection, it will automatically populate the marks '<
and '>
and those will persist until you make another visual selection. So, you can do :'<,'>s/foo/bar/
without having to go back into visual mode and it will still apply to the same range. Same thing with anything else that uses those marks.
If you have just pasted a visual block, there is also a way to reselect it easily.
See the following question and answers on SO.
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