Skip to content

Commit

Permalink
Start using zoom script to auto resize vim splits.
Browse files Browse the repository at this point in the history
  • Loading branch information
boushley committed Nov 16, 2016
1 parent ddddcf0 commit abb4ee1
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 18 deletions.
89 changes: 89 additions & 0 deletions bin/mvim
@@ -0,0 +1,89 @@
#!/bin/sh
#
# This shell script passes all its arguments to the binary inside the
# MacVim.app application bundle. If you make links to this script as view,
# gvim, etc., then it will peek at the name used to call it and set options
# appropriately.
#
# Based on a script by Wout Mertens and suggestions from Laurent Bihanic. This
# version is the fault of Benji Fisher, 16 May 2005 (with modifications by Nico
# Weber and Bjorn Winckler, Aug 13 2007).
# First, check "All the Usual Suspects" for the location of the Vim.app bundle.
# You can short-circuit this by setting the VIM_APP_DIR environment variable
# or by un-commenting and editing the following line:
# VIM_APP_DIR=/Applications

if [ -z "$VIM_APP_DIR" ]
then
myDir="`dirname "$0"`"
myAppDir="$myDir/../Applications"
suspects=(
/Applications
~/Applications
/Applications/vim
~/Applications/vim
$myDir
$myDir/vim
$myAppDir
$myAppDir/vim
/Applications/Utilities
/Applications/Utilities/vim
)
for i in ${suspects[@]}; do
if [ -x "$i/MacVim.app" ]; then
VIM_APP_DIR="$i"
break
fi
done
fi
if [ -z "$VIM_APP_DIR" ]
then
echo "Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app."
exit 1
fi
binary="$VIM_APP_DIR/MacVim.app/Contents/MacOS/Vim"

# Next, peek at the name used to invoke this script, and set options
# accordingly.

name="`basename "$0"`"
gui=
opts=

# GUI mode, implies forking
case "$name" in m*|g*|rm*|rg*) gui=true ;; esac

# Logged in over SSH? No gui.
if [ -n "${SSH_CONNECTION}" ]; then
gui=
fi

# Restricted mode
case "$name" in r*) opts="$opts -Z";; esac

# vimdiff, view, and ex mode
case "$name" in
*vimdiff)
opts="$opts -dO"
;;
*view)
opts="$opts -R"
;;
*ex)
opts="$opts -e"
;;
esac

# Last step: fire up vim.
# The program should fork by default when started in GUI mode, but it does
# not; we work around this when this script is invoked as "gvim" or "rgview"
# etc., but not when it is invoked as "vim -g".
if [ "$gui" ]; then
# Note: this isn't perfect, because any error output goes to the
# terminal instead of the console log.
# But if you use open instead, you will need to fully qualify the
# path names for any filenames you specify, which is hard.
exec "$binary" -g $opts ${1:+"$@"}
else
exec "$binary" $opts ${1:+"$@"}
fi
12 changes: 12 additions & 0 deletions bin/tmux-zoom-out-vim
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e

cmd="$(tmux display -p '#{pane_current_command}')"
cmd="$(basename "${cmd,,*}")"

tmux resize-pane -Z

if [ "${cmd%m}" = "vi" ]; then
sleep 0.1
tmux send-keys C-w =
fi
1 change: 1 addition & 0 deletions git/gitconfig
Expand Up @@ -8,6 +8,7 @@
ui = true
[alias]
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
please = push --force-with-lease
[core]
autocrlf = input
safecrlf = warn
Expand Down
24 changes: 6 additions & 18 deletions tmux/tmux.conf
Expand Up @@ -4,9 +4,6 @@ set -g prefix C-Space
bind Space copy-mode
bind C-Space copy-mode

# Attache to the user's namespace. This lets open work
echo "set -g default-command \"reattach-to-user-namespace -l ${SHELL}\"" >> ~/.tmux.conf

###########################################################################
# General options

Expand All @@ -32,9 +29,6 @@ set -g xterm-keys on
# auto window rename
set-window-option -g automatic-rename

# status bar
set-option -g status-utf8 on

# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
Expand Down Expand Up @@ -73,6 +67,9 @@ bind -n "^\\" last-window
###########################################################################
# Pane management / navigation

# Use custom zoom script to resize vim splits too
bind-key z run-shell 'tmux-zoom-out-vim'

# Horizontal splits with s or ^S
unbind s
unbind ^S
Expand Down Expand Up @@ -130,23 +127,14 @@ bind y run "tmux show-buffer | xsel -i -b"
###########################################################################
# Mouse mode

set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
set -g mouse on

# Toggle mouse on
bind m \
set -g mode-mouse on \;\
set -g mouse-resize-pane on \;\
set -g mouse-select-pane on \;\
set -g mouse-select-window on \;\
set -g mouse on \;\
display 'Mouse: ON'

# Toggle mouse off
bind M \
set -g mode-mouse off \;\
set -g mouse-resize-pane off \;\
set -g mouse-select-pane off \;\
set -g mouse-select-window off \;\
set -g mouse off \;\
display 'Mouse: OFF'

0 comments on commit abb4ee1

Please sign in to comment.