0

When I pass the names of multiple files to vim on the command line (e.g. vim foo.txt bar.txt), I almost always want to add the -o option, because I would like them to be visible side-by-side in separate windows. However, I often forget to add -o. I cannot find an appropriate setting, but is there a way to set this as the default? (for example, in my .vimrc?). I know I could probably create a shell alias, but that only works if it is invoked interactively from a shell (not from another program).

6

As a solution to the generalized question How can I apply a command-line option every time I open vim? (there are options that don't have configuration equivalents) one approach is as follows.

  1. Put your personal bin dir (~/bin) ahead of vim's path in your PATH environment variable. If the bin dir is not already in your path you can use this (in .profile, or .bashrc or whatever you use):
    PATH=$HOME/bin:$PATH
    
  2. Create a wrapper shell script named vim in that directory:

    $ cat > ~/bin/vim <<'EOF'
    #!/bin/sh
    
    exec /path/to/vim -o "$@"
    EOF
    

    Per OP's request I'm using -o in this example. Obviously you'll need to change /path/to to actual path.

  3. Make it runnable:

    $ chmod +x ~/bin/vim
    

    Now if you run vim foo bar then "foo" and "bar" each get their own windows.

  • 1
    Thanks @muru that little formatting trick was just what the doctor ordered. – B Layer Jun 26 at 7:10
  • 1
    Thanks. That's reasonable, unfortunately it doesn't quite address scenarios such as diff mode being enabled (which to be fair I didn't ask about, but realised would be an issue once I read the related question!). It would be nicer to have a configuration-based approach. But it's definitely the best answer I've seen so far. – Andrew Ferrier Jun 26 at 10:48
  • Hi @AndrewFerrier I knew this answer wouldn't be what you'd consider ideal but after I came up short on it I become a bit skeptical that there was a configuration solution. Well, at least I could improve on the alias-based solution you mentioned as well as solve the problem generally for all flags with no vimrc analogue. An ideal solution may yet appear and it'll be great if it does. I knew this might be relegated to secondary/alternative status. I'm just glad a number of people seem to have found it useful so far. – B Layer Jun 26 at 15:29
  • BTW, what's the diff mode scenario you mention? If I understand how it breaks down in some scenarios I may be able to improve it a bit. – B Layer Jun 26 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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