I know that you can pass several flags to Vim at startup.

For example: the -w flags enables to records every keystrokes on the file output.

vi -w output 

But I wonder if there is a way of doing this from the vimrc file, without having the -w flag at vim startup.

More generally: how can I specify a vim flag/option from within the vimrc ?

  • Record a macro in a register, with q. Then, paste the register content to a file. :h -w hints to the complex-repeat section, which actually describes the Vim macro system. In general, you read :h starting.txt and hope to find there and indication to the corresponding vimrc option :)
    – VanLaser
    Aug 10, 2015 at 11:54
  • Hello, I saw this it could be a workaround but I don't find it satisfying... Meanwhile I updated my question to make it more generic
    – nobe4
    Aug 10, 2015 at 11:56
  • 4
    As far as I know, you can't. But you can create a shell alias, which has roughly the same effect. Aug 10, 2015 at 12:05
  • I didn't wanted to do so ... but I might find that I have no other choice ... What do you think about creating a script that would reload vim with appropriated flags ?
    – nobe4
    Aug 10, 2015 at 12:06
  • 1
    I'm not sure if that's possible from Vim. You can use ! and system(), but both will leave the original process in place (it doesn't replace the original Vim process). You could do it with a wrapper shell script of course, but that doesn't seem easier than a shell alias. Aug 10, 2015 at 13:27

2 Answers 2


This is not possible.

If the -w or -W flags are given, Vim will set the scriptout variable to a filehandle (main.c, command_line_scan(), around line 2374). This variable is referenced in only 2 other places; getchar.c for writing to the file, and message.c, to work around a problem which causes a character to be recorded twice.

The only viable options I see are either a shell alias, or a wrapper script which calls Vim with the -w flags.


(This solution only works if you want to save your keystrokes to a single file)

You could alias it in your bash_profile, bash_rc, whichever one declares your path variables. This is one I did for ls:

alias ls="ls -pla"

So yours would be

alias vi="vi -w [output]"
  • Thanks for your answer but as discussed in the comments, the solution I wanted should not require an alias.
    – nobe4
    Aug 12, 2015 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.