Update Tmux configuration and integrate Vim

This commit is contained in:
Max Bucknell 2019-03-10 11:12:32 +00:00
parent 4017e91a64
commit 00fed56823
2 changed files with 82 additions and 19 deletions

View file

@ -6,6 +6,9 @@ set updatetime=100
call plug#begin() call plug#begin()
" Pane Navigation (Tmux integration)
Plug 'christoomey/vim-tmux-navigator'
" Colours " Colours
Plug 'morhetz/gruvbox' Plug 'morhetz/gruvbox'
@ -116,12 +119,6 @@ set autowrite
set splitbelow set splitbelow
set splitright set splitright
" Just remove an extra keystroke
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Make searches case sensitive only if an upper case character has been typed " Make searches case sensitive only if an upper case character has been typed
set ignorecase smartcase set ignorecase smartcase
@ -190,6 +187,29 @@ set shiftwidth=4
set softtabstop=4 set softtabstop=4
set autoindent set autoindent
" Zoom the current split
function! ZoomOrUnzoom()
if exists('g:is_zoomed')
unlet g:is_zoomed
execute "wincmd ="
else
let g:is_zoomed = 'true'
execute "wincmd _"
execute "wincmd \|"
endif
endfunc
function! HandleResize()
if exists('g:is_zoomed')
execute "wincmd _"
execute "wincmd \|"
else
execute "wincmd ="
endif
endfunc
nnoremap <C-z> :call ZoomOrUnzoom()<cr>
function! RunTypeScript() function! RunTypeScript()
silent !clear silent !clear
execute "!tsc % --outFile /dev/stdout | node" execute "!tsc % --outFile /dev/stdout | node"
@ -234,6 +254,9 @@ augroup vimrcEx
" Automatically enter terminal mode when summoning a terminal " Automatically enter terminal mode when summoning a terminal
autocmd TermOpen term://* startinsert autocmd TermOpen term://* startinsert
" Lay out splits when Vim gets resized
autocmd VimResized * :call HandleResize()<cr>
augroup END augroup END
" Make directories in a filename if they don't exist. " Make directories in a filename if they don't exist.

View file

@ -1,16 +1,56 @@
# pane switching # Reload Tmux configuration
bind C-h select-pane -L bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded"
bind C-j select-pane -D
bind C-k select-pane -U
bind C-l select-pane -R
bind C-\ select-pane -l
# easily toggle synchronization (mnemonic: e is for echo) # Enable Tmux's mouse mode.
bind e setw synchronize-panes on #
bind E setw synchronize-panes off # In iTerm, this mostly does what I want, in that it allows me to click on
# things to bring them into focus (windows, panes). It also handles scrolling
# more elegantly.
set-option -g mouse on
# start a pane in the right fucking folder # Mouse mode isn't perfect. By default, ending a drag cancels the selection,
bind c new-window -c "#{pane_current_path}" # which is a jarring on non-default behaviour. This makes sure this doesn't
bind % split-window -h -c '#{pane_current_path}' # happen anymore.
bind '"' split-window -v -c '#{pane_current_path}' unbind-key -T copy-mode MouseDragEnd1Pane
# Because we cancelled the mouse drag ending a selection, we don't have an
# easy and convenient way to make get back to normal. When using a GUI, a
# single click usually does the trick. This command restores that behaviour.
bind-key -T copy-mode MouseUp1Pane send-keys -X cancel
# Use the Vim yank mnemonic to commit a copy when in copy mode.
# I don't actually hit "y" to copy, though. In iTerm, I have Cmd+C set up
# to send the hexcode for y to the terminal, which means the normal macOS
# copy shortcut does the right thing, so long as I'm in Tmux.
bind-key -T copy-mode y send-keys -X copy-pipe "pbcopy"
# When I delete a window, relabel them automatically.
set-option -g renumber-windows on
# Pane switching. These interface with Vim to ensure that pane switching is
# both consistent and sensible.
#
# Borrowed from Chris Toomey: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
# When zooming a pane in a window, also zoom the vim split
bind-key z if-shell "$is_vim" "resize-pane -Z \; send-keys C-z" "resize-pane -Z"
# All pane and window creations use the same path as the current process,
# which I have found to be a good default.
#
# I don't typically hit <prefix>c to open a new window, I have that bound
# to Cmd+T in iTerm the same way I manage the clipboard. I also add the
# tab traversal shortcuts to move between Tmux windows.
bind-key c new-window -c "#{pane_current_path}"
# Backslash is the unshifted version of |
bind-key \ split-window -h -c '#{pane_current_path}'
# Ditto, hyphen is the unshifted version of _
bind-key - split-window -v -c '#{pane_current_path}'