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 `<C-w>`
mappings for the most common actions.

Additionally, disable vim-tmux-navigators default mappings and setup
both normal and terminal mode mappings for `<C-w>{h,j,k,l}` in addition
to the normal mode mappings for `<C-{h,j,j,l}>` to make the pane
switching experience more consistent across all buffer types.
This commit is contained in:
Kenneth Benzie 2021-02-18 00:34:50 +00:00
parent 587aeef5d7
commit c284486540
3 changed files with 43 additions and 9 deletions

View File

@ -1,7 +1,7 @@
augroup benieAugroup augroup benieAugroup
autocmd! autocmd!
if $TMUX !=# '' if tmux#inSession()
" [Un]set tmux window option to detect when to change pane. " [Un]set tmux window option to detect when to change pane.
call tmux#setNavigationFlag() call tmux#setNavigationFlag()
au FocusGained * silent call tmux#setNavigationFlag() au FocusGained * silent call tmux#setNavigationFlag()
@ -28,4 +28,20 @@ augroup benieAugroup
" Augment vim-signify by modifying it's autocmds " Augment vim-signify by modifying it's autocmds
au User SignifyAutocmds call do#signify() 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('<afile>') !~ "fzf") &&
\ (expand('<afile>') !~ "ranger") &&
\ (expand('<afile>') !~ "coc") |
\ call nvim_input('<CR>') |
\ endif
endif
augroup END augroup END

View File

@ -5,6 +5,11 @@ nmap <leader>gt <Plug>(coc-type-definition)
nmap <leader>sd <Plug>(coc-diagnostic-info) nmap <leader>sd <Plug>(coc-diagnostic-info)
nmap <leader>gr <Plug>(coc-references) nmap <leader>gr <Plug>(coc-references)
if has('nvim')
" Make nvim :terminal more like vim :terminal
tnoremap <C-w>N <C-\><C-n>
endif
" termdebug " termdebug
" TODO: Detecet if termdebug is loaded, if not do the default action. " TODO: Detecet if termdebug is loaded, if not do the default action.
nnoremap <C-W><C-G> :Gdb<CR> nnoremap <C-W><C-G> :Gdb<CR>
@ -59,14 +64,26 @@ nnoremap k gk
" Quick write " Quick write
nnoremap <leader>w :w!<CR> nnoremap <leader>w :w!<CR>
" Switch panes " Switch panes in a tmux aware way
nnoremap <C-h> <C-w>h nnoremap <silent> <C-h> :TmuxNavigateLeft<CR>
nnoremap <C-j> <C-w>j nnoremap <silent> <C-j> :TmuxNavigateDown<CR>
nnoremap <C-k> <C-w>k nnoremap <silent> <C-k> :TmuxNavigateUp<CR>
nnoremap <C-l> <C-w>l nnoremap <silent> <C-l> :TmuxNavigateRight<CR>
nnoremap <silent> <C-w>h :TmuxNavigateLeft<CR>
" Redraw window nnoremap <silent> <C-w>j :TmuxNavigateDown<CR>
nnoremap <C-w>l <C-l> nnoremap <silent> <C-w>k :TmuxNavigateUp<CR>
nnoremap <silent> <C-w>l :TmuxNavigateRight<CR>
if has('nvim')
tnoremap <silent> <C-w>h <C-\><C-n>:TmuxNavigateLeft<CR>
tnoremap <silent> <C-w>j <C-\><C-n>:TmuxNavigateDown<CR>
tnoremap <silent> <C-w>k <C-\><C-n>:TmuxNavigateUp<CR>
tnoremap <silent> <C-w>l <C-\><C-n>:TmuxNavigateRight<CR>
else
tnoremap <silent> h :TmuxNavigateLeft<CR>
tnoremap <silent> j :TmuxNavigateDown<CR>
tnoremap <silent> k :TmuxNavigateUp<CR>
tnoremap <silent> l :TmuxNavigateRight<CR>
endif
" Quick tabs " Quick tabs
nnoremap <leader>tn :tabnew<Space> nnoremap <leader>tn :tabnew<Space>

1
vimrc
View File

@ -125,6 +125,7 @@ let g:note_directory = '~/Sync/Notes'
if !has('win32') if !has('win32')
" Seemless vim/tmux pane navigation " Seemless vim/tmux pane navigation
Pack 'christoomey/vim-tmux-navigator' Pack 'christoomey/vim-tmux-navigator'
let g:tmux_navigator_no_mappings = 1
" Enable focus events when in tmux session " Enable focus events when in tmux session
Pack 'tmux-plugins/vim-tmux-focus-events' Pack 'tmux-plugins/vim-tmux-focus-events'
endif endif