views:

45

answers:

2

I want to be able to open Vim and automatically make some commands in normal mode (in this case, open two buffers put a mark in one line on one line, fold another line, and go to the bottom of the file). The closest thing I found would be using the -c or + command line switch, however these execute commands in Ex mode.

For example, I would like to be able to write something like this:

vim -some ":e a<CR>:e b<CR>23Gma55GzfG"

To do all the commands.

A: 

Define this command in your _vimrc file (you can name it something other than Onstart, but it must start with a capital letter)

:command -nargs=1 Onstart <args>

From the command line you should be able to call this:

gvim c:\file.txt -c "Onstart e a<CR>:e b<CR>23Gma55GzfG"

correction

Nope, I was mistaken. You'd just have to pipe the commands:

vim -c "e a | e b | normal!23Gma55GzfG"
Jay
That will throw `E172` («only one filename is allowed» error). And this will never let you execute normal mode commands without an ex mode `normal` command.
ZyX
Two downvotes, really? I'm tempted to delete it for embarrassment, except I think my ultimate answer is superior to the accepted one.
Jay
+1. Pipes does look good to me. I'd have edited the "wrong" part of post.
jeffjose
+2  A: 

Why don't you like normal command? It is not able to execute ex mode commands, but is able to use all other modes:

vim -c 'e a' -c 'e b' -c 'normal! 23Gma55GzfG'

Bang at the end of command is required if you want to be sure that it will not use any mappings.

ZyX
Of course I love the normal command, I just didn't know about it. Thanks!
Martín Fixman