I commonly find myself inserting a tab before some text. This is easy in insert mode, I'll just type a tab, but I would also like to be able to do it in visual mode. The issue is, if I press >
in visual mode, it will indent the whole line. Instead I only want to insert a tab
at the start of the visual selection and then re-select that text. Here is what I have so far:
vnoremap <leader>] <Esc>`<i<tab><Esc>gv
What this tries to do is:
<Esc>
Escape the visual selection`<
Go to the start of the previous visual selection and enter insert mode<tab>
Add a tab<Esc>
Escape insert modegv
And again go into visual mode and reselect the visual selection
The issue is, it seems that gv
is no longer valid after entering in the tab
. So what would be the best way to do this?
:h tabstop
setting, I suppose... but would not work if changing to another buffer. But it depends on what you exactly want: keep the exact same selection size? Select the new tab? Please explain more precisely what behaviour you'd expect and what's happening instead.tab
, whatever text was there before. For example, ifThis is <v>the text<v>
and I add a tab at the start of the visual selection, it would look like this:This is <v>the text<v>