in vim, how to append/insert text with argdo?
Question
There's the ":a" command, but that's multi-line, and argdo asks you for the text again for each file.
The docs mention the global command (g/pat/command) that will use an alternative version of ":a" that is terminated by a newline instead of by "." on a line (you can include newlines by escaping them with "\"). But I couldn't get this to work.
The only way I've seen is to first yank the text-to-be-added into a named register, then use:
:argdo put x " where x is the register
I'm hoping for something like
:argdo append myTextHere
Solution
I'm unclear where you're trying to insert the text in the buffer. If you want it after the current line:
:argdo exe 'normal osometext'
Inserting text with linebreaks in it:
:argdo exe "normal osometext\<CR>anewline"
OTHER TIPS
To append text after line nr 10:
:argdo call append(10, "hello world")
To append text to the line 10:
:argdo call setline(10, getline(10)."textappended")
Yanking a text in vim will put it in the default buffer, which is "
. You can paste that buffer in insert mode for example by typing <C-R>"
. So all you need is argdo put "