I think your best bet is to use a plugin like vim-indent-object it defines some new text objects to handle indentation levels:
Other alternatives are either:
Creating your own text objects manually as described here which is more or less reimplementing the plugin I mentioned before
Using a library like vim-textobj-user which helps you creating new text ...
Using yank commands from normal mode is actually a common practice.
The alternative is to use getline() to get the contents of a line and then parse it, possibly using regex matches or other Vimscript string functions.
But it's often easier to use normal mode commands, especially when you're matching around the cursor position or when the text you're ...
Use "0p to paste in Visual mode
Note that the numbered register "0 can be really useful here, since a default yank also goes to the "0 register, but the text replaced with a put in visual mode only goes to the unnamed register and doesn't modify "0.
See :help v_p:
The previously selected text is put in the unnamed register. If you want to put the same ...
There's no single "clipboard" in Vim. These things are called registers. Make sure you read the docs about them, it's essential.
This behaviour is documented under :h v_p (as you "put" while being in "visual" mode). "Visual put" consists of two actions: a) put new text from register, and b) delete the old text into a register. Here deleted text is put ...
In step 7 you delete the text you selected in step 6, so it is moved to the unnamed register ("clipboard").
This the normal behavior of Vi(m).
If you want to copy something multiple times, you should put it into a named register, e.g. into register 'a'.
In step 3 you would use "ay and in step 7 you would use "ap.
The unnamed register still changes in ...
Is the clipboard overwritten in Visual Mode each time?
Yes it is.
How do I get "sane" behavior? That is make the clipboard persist after the first paste.
To get "sane" behavior you can remap p and P with:
" now it is possible to paste many times over selected text
xnoremap <expr> p 'pgv"'.v:register.'y`>'
xnoremap <expr> P 'Pgv"'.v:...
In general, visual block selections must be blocks (rectangles). The only "jagged" selections are when you hit <C-v>$ to select to the end of multiple lines.
However, depending on what you want to do, there are often several approaches. In this case, to copy:
" clear register A
let @a = ''
" yank all the words
Using a capital ...
As jecxgo points out, the problem is that the obvious solution of recording a macro that processes a single line and then applying that to the selection of lines with :normal fails because, when the lines are expanded, this messes with the other lines in the range.
jecxgo solves this by not expanding the lines within the macro but instead doing so in a ...