Mark Harrison
Mark Harrison

Reputation: 304434

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))"

Upvotes: 4

Views: 2925

Answers (2)

Kaiwen
Kaiwen

Reputation: 355

The equivalent to startinsert like startappend is startinsert! according to this site. So the answer could be

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

Upvotes: 1

statox
statox

Reputation: 2886

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.

Upvotes: 6

Related Questions