Skip to main content
1 of 3

Command line ranges can be use to select a specific line that needs to be edited. Then substitute pattern can be used to perform the edit (append).

For example, to append text "hi" at the begining of line 3:

vim -c "3 s/^/hi/" -c "wq" file.txt

To append text "hi" at the end of line 3:

vim -c "3 s/$/hi/" -c "wq" file.txt

To find more options and explanations:

vim -c "help cmdline-range"