From c284486540ca64a65bc9cbad7870321f039ba388 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 18 Feb 2021 00:34:50 +0000 Subject: [PATCH] Make nvim :terminal more consistent with vim Vim's :terminal feels much more ergonomic, adding various mappings to make the experience more similar, mainly by adding a few `` mappings for the most common actions. Additionally, disable vim-tmux-navigators default mappings and setup both normal and terminal mode mappings for `{h,j,k,l}` in addition to the normal mode mappings for `` to make the pane switching experience more consistent across all buffer types. --- plugin/autocmds.vim | 18 +++++++++++++++++- plugin/mappings.vim | 33 +++++++++++++++++++++++++-------- vimrc | 1 + 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/plugin/autocmds.vim b/plugin/autocmds.vim index 2132113..81f82af 100644 --- a/plugin/autocmds.vim +++ b/plugin/autocmds.vim @@ -1,7 +1,7 @@ augroup benieAugroup autocmd! - if $TMUX !=# '' + if tmux#inSession() " [Un]set tmux window option to detect when to change pane. call tmux#setNavigationFlag() au FocusGained * silent call tmux#setNavigationFlag() @@ -28,4 +28,20 @@ augroup benieAugroup " Augment vim-signify by modifying it's autocmds au User SignifyAutocmds call do#signify() + + if has('nvim') + " Start in terminal-insert mode. + autocmd TermOpen term://* startinsert + " Don't show the line number column in terminal-insert mode. + autocmd TermEnter term://* set nonumber | set norelativenumber + " But do show the line number column in terminal-normal mode. + autocmd TermLeave term://* set number | set relativenumber + " Automatically press enter when the terminal process exits. + autocmd TermClose term://* + \ if (expand('') !~ "fzf") && + \ (expand('') !~ "ranger") && + \ (expand('') !~ "coc") | + \ call nvim_input('') | + \ endif + endif augroup END diff --git a/plugin/mappings.vim b/plugin/mappings.vim index 42517ff..8c3bc78 100644 --- a/plugin/mappings.vim +++ b/plugin/mappings.vim @@ -5,6 +5,11 @@ nmap gt (coc-type-definition) nmap sd (coc-diagnostic-info) nmap gr (coc-references) +if has('nvim') + " Make nvim :terminal more like vim :terminal + tnoremap N +endif + " termdebug " TODO: Detecet if termdebug is loaded, if not do the default action. nnoremap :Gdb @@ -59,14 +64,26 @@ nnoremap k gk " Quick write nnoremap w :w! -" Switch panes -nnoremap h -nnoremap j -nnoremap k -nnoremap l - -" Redraw window -nnoremap l +" Switch panes in a tmux aware way +nnoremap :TmuxNavigateLeft +nnoremap :TmuxNavigateDown +nnoremap :TmuxNavigateUp +nnoremap :TmuxNavigateRight +nnoremap h :TmuxNavigateLeft +nnoremap j :TmuxNavigateDown +nnoremap k :TmuxNavigateUp +nnoremap l :TmuxNavigateRight +if has('nvim') + tnoremap h :TmuxNavigateLeft + tnoremap j :TmuxNavigateDown + tnoremap k :TmuxNavigateUp + tnoremap l :TmuxNavigateRight +else + tnoremap h :TmuxNavigateLeft + tnoremap j :TmuxNavigateDown + tnoremap k :TmuxNavigateUp + tnoremap l :TmuxNavigateRight +endif " Quick tabs nnoremap tn :tabnew diff --git a/vimrc b/vimrc index b2c8207..8e72f14 100644 --- a/vimrc +++ b/vimrc @@ -125,6 +125,7 @@ let g:note_directory = '~/Sync/Notes' if !has('win32') " Seemless vim/tmux pane navigation Pack 'christoomey/vim-tmux-navigator' + let g:tmux_navigator_no_mappings = 1 " Enable focus events when in tmux session Pack 'tmux-plugins/vim-tmux-focus-events' endif