Reputation: 1150
I am very new to Vim and I can't find out the solution to this problem, whereas this seems really simple. I would like to append sthg directly to the end of a specific line of a file, let's say the 12th. I can do it in two commands:
:12
A
Is there a way to do it in a one-liner? I tried :12|A
as suggested here but I get E492: Not an editor command: A
Thanks a lot!
Upvotes: 0
Views: 973
Reputation: 2261
as far i know, you can't. Go to line 12 and append to end of line are two distinct commands and cannot be merged.
A possible trick is open the file to the specific position:
vi example.txt +12
and then append to the end of line.
A personal note: what i think is marvellous about "vi" philosophy is the concatenation of commands as unix pipe pattern. Learn how to go to specific line, append or insert, delete etc. is easier and more flexible to learn one command for each combination. Embrace this concept and you'll love vi forever.
Upvotes: -1
Reputation: 29178
Go in normal mode, 12G
to go to the twelve line, A
to start edition at the end of the line...
<esc>12GAsomething
If you want to add 'something' to every line of the file you can still use regexp:
:%s/$/something/
Or if you want to do just for some lines, you can record a macro
<Esc>qq<Esc>Asomething<Esc>jq
To execute the macro over ten lines just enter:
10@q
If you really want a oneliner, just set a mapping:
inoremap <C-p> <Esc>12GAsomethinga
Then press Ctrlp
<C-p>
Upvotes: 3
Reputation: 196886
You could do:
:12norm Afoo
See :help :normal
.
Or you can do it with a substitution:
:12s/$/foo
Upvotes: 2