From :h visual-use (emphasis mine):
Using Visual mode consists of three parts:
Mark the start of the text with "v", "V" or CTRL-V.
The character under the cursor will be used as the start.
Move to the end of the text.
The text from the start of the Visual mode up to and including the
character under the cursor is highlighted.
Type an ...
Yes, pressing some keys in Vim could switch the current mode. Still surprised?
This is documented under :h mode-switching. Obviously, here you have even two transitions: one by colon, and another one by enter key.
But, I admit, it's confusing on the first encounter. In Neovim they even invented :h <Cmd> to deal with this. But in plain Vim you have only ...
You can use blockwise Visual mode to select a block of columns and insert text (such as one or two spaces) in front of the block. Likewise, you can also use blockwise Visual mode to delete one or two columns of spaces in order to unindent lines.
To add indentation:
Go to the first line of the block.
Use 0 (or ^) to move to the first column (or first ...
The problem occurred because there is an inconsistency between the spaces and tabs used for indentation in your code. You have probably opened a tab indented code, and started editing it, while vim was set to indent using spaces.
To solve this issue, first, set your tabbing space setting in your ~/.vim/vimrc by
One thought that occurs to me: yank the text (y), and then paste it at the :grep command:
:grep <C-r>" ...
Note that this doesn't work too well for multi-line selections, and you may want something more like
to handle some escape sequences.
I'm making use of the "insert register" keystroke (:...