I am trying to write a command that yanks the whitespace (indentation) at the start of a line as well as yanking some other object.
I have several ideas of how this could be done.
Consider the following example, where we want to make a new command similar to "yiw" which yanks the variable name
hello_world but also yanks the whitespace before
// no indentation on this line double hello_world = 10.0; // there is some indentation on this line
We could either store the current cursor position, go to the start of the line, yank the whitespace, go back to where we were, execute the yiw command and somehow get these 2 yanks to "concatinate".
Or we could execute the yiw command, go to the end of the line, add a new line, put the yank buffer, go back up to the start of the line, yank the whitespace, go down again, put the whitespace at the start of the line, delete-yank the whole line and put it again. (So that the yank buffer contains what we want.)
Or some combination of the above.
Firstly, while not essential, I don't know how to manipulate the yank buffer, or how to "concatinate" to it.
Secondly I do not know how to save the cursor position and then restore it. This is also not essential but the "work around" as described above is messy.
What is the best way of accomplishing a yank and retaining the indentation whitespace?
This is my attempt so far. It works but doesn't seem like a particularly good solution. Also "o" seems like an inefficient combination to put in a command since everything else is done without entering insert mode.
nnoremap <S-y>iw yiwo<ESC>p-0y^<DOWN>PddP