Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: from command line, go to end of file and start editing?

I can cause vim to position the cursor at the last line of a file by invoking it with an argument of +:

vi + myfile          # "+" = go to last line of file

How can I do this, and then go into append mode, so that the user can start typing at the end of the file?

Something similar to

emacs myfile --eval "(goto-char (point-max))"
like image 339
Mark Harrison Avatar asked Oct 14 '25 18:10

Mark Harrison


1 Answers

One solution could be to use the + parameter to pass a command to execute after reading the file. Vim can take up to 10 commands this way so you can use:

vim "+norm Go" "+startinsert" myfile
  • The first command norm Go will go to the last line and add a new one.
  • The second command will start insert mode allowing the user to type in the last line.

Note This solution creates a new line at the end of the file. If you want to edit the end of the last line without creating a new one you could use something like that :

vim "+norm G$" "+startinsert" myfile

But If you do this and your last line already contains some text, you will start inserting text before the last character. I don't know an equivalent to startinsert like startappend so I don't know how to solve this.

like image 158
statox Avatar answered Oct 17 '25 15:10

statox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!