views:

377

answers:

3

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
+1  A: 

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 "

soulmerge
Thanks, I was hoping for something that didn't involve setting up registers. Something like: :argdo append myTextHere I'll clarify the question.
13ren
+3  A: 

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"
Brian Carper
hey that's pretty cool. I've seen "normal" before but not used it. BTW I found this also worked: :argdo normal osometext
13ren
I should have answered your request for clarity: sometimes I'd want to insert it at the same line in each of the files (eg. line 2); sometimes after a certain pattern. I probably wouldn't want to do it in terms of the current line, because it might be different in the different files. But I think your approach is easily powerful enough to be adapted to this, by going to a line or searching for a pattern, before inserting.
13ren
+1  A: 

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")
Maxim Kim
thanks, that seems workable. It's looking like one needs to switch to a different level to do this (using either your "call" or Brian's "normal")
13ren