Avoiding Scattered Vim Windows in MacVim


Problem:

I open too many windows in vim, which get buried in the clutter on my Mac OS X desktop.

Solution:

Open files in MacVim in an existing window using a tab

mvim --remote-tab new_file_to_open.rb

Open files in MacVim in an existing window using a split

mvim --remote-send ":split `pwd`/new_file_to_open.rb<CR>"

I packaged this in a zsh script called spvim. It will only handle relative paths for now, which in 99% of what I’m trying to open, anyway.

for i in $*
do
  mvim --remote-send ":split `pwd`/$i<CR>"
done

Open files in MacVim in an existing windows using a vertical split:

mvim --remote-send ":vsplit `pwd`/new_file_to_open.rb<CR>"

I packaged this in a zsh script called vspvim:

for i in $*
do
  mvim --remote-send ":vsplit `pwd`/$i<CR>"
done

Sources/Learning More:

(I believe most of these options are available in vim as well… I actually have gvim aliased to mvim because I'm still in the habit of calling gvim).

usage: vim [arguments] [file ..]       edit specified file(s)
   or: vim [arguments] -               read text from stdin
   or: vim [arguments] -t tag          edit file where tag is defined
   or: vim [arguments] -q [errorfile]  edit file with first error

Arguments:
   --           Only file names after this
   -g           Run using GUI (like "gvim")
   -f  or  --nofork Foreground: Don&#039;t fork when starting GUI
   -v           Vi mode (like "vi")
   -e           Ex mode (like "ex")
   -E           Improved Ex mode
   -s           Silent (batch) mode (only for "ex")
   -d           Diff mode (like "vimdiff")
   -y           Easy mode (like "evim", modeless)
   -R           Readonly mode (like "view")
   -Z           Restricted mode (like "rvim")
   -m           Modifications (writing files) not allowed
   -M           Modifications in text not allowed
   -b           Binary mode
   -l           Lisp mode
   -C           Compatible with Vi: &#039;compatible&#039;
   -N           Not fully Vi compatible: &#039;nocompatible&#039;
   -V[N][fname]     Be verbose [level N] [log messages to fname]
   -D           Debugging mode
   -n           No swap file, use memory only
   -r           List swap files and exit
   -r (with file name)  Recover crashed session
   -L           Same as -r
   -A           start in Arabic mode
   -H           Start in Hebrew mode
   -F           Start in Farsi mode
   -T <terminal>    Set terminal type to <terminal>
   -u <vimrc>       Use <vimrc> instead of any .vimrc
   -U <gvimrc>      Use <gvimrc> instead of any .gvimrc
   --noplugin       Don&#039;t load plugin scripts
   -p[N]        Open N tab pages (default: one for each file)
   -o[N]        Open N windows (default: one for each file)
   -O[N]        Like -o but split vertically
   +            Start at end of file
   +<lnum>      Start at line <lnum>
   --cmd <command>  Execute <command> before loading any vimrc file
   -c <command>     Execute <command> after loading the first file
   -S <session>     Source file <session> after loading the first file
   -s <scriptin>    Read Normal mode commands from file <scriptin>
   -w <scriptout>   Append all typed commands to file <scriptout>
   -W <scriptout>   Write all typed commands to file <scriptout>
   -x           Edit encrypted files
   --remote <files> Edit <files> in a Vim server if possible
   --remote-silent <files>  Same, don&#039;t complain if there is no server
   --remote-wait <files>  As --remote but wait for files to have been edited
   --remote-wait-silent <files>  Same, don&#039;t complain if there is no server
   --remote-tab[-wait][-silent] <files>  As --remote but use tab page per file
   --remote-send <keys> Send <keys> to a Vim server and exit
   --remote-expr <expr> Evaluate <expr> in a Vim server and print result
   --serverlist     List available Vim server names and exit
   --servername <name>  Send to/become the Vim server <name>
   --startuptime <file> Write startup timing messages to <file>
   -i <viminfo>     Use <viminfo> instead of .viminfo
   -h  or  --help   Print Help (this message) and exit
   --version        Print version information and exit

One response to “Avoiding Scattered Vim Windows in MacVim”

%d bloggers like this: