1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:40:06 +08:00

feat(layer): add enable_tmux_clipboard option

close https://github.com/SpaceVim/SpaceVim/issues/3670
This commit is contained in:
Wang Shidong 2021-09-25 22:51:01 +08:00 committed by GitHub
parent e1dfadeea5
commit 71d78fae3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 105 additions and 16 deletions

View File

@ -9,13 +9,23 @@
""
" @section tmux, layers-tmux
" @parentsection layers
" Adds integration between tmux and vim panes. Switch between panes
" seamlessly.syntax highlighting, commenting, man page navigation
" `tmux` layer adds integration between tmux and vim panes. Switch between panes
" seamlessly, syntax highlighting, commenting, man page navigation
" and ability to execute lines as tmux commands.
" This layer is not added by default. To include it, add
" `SpaceVim#layers#load('tmux')` to your `~/.SpaceVim.d/init.vim`.
" This layer is not added by default. To include it, add following to spacevim
" configuration file:
" >
" [[layers]]
" name = 'tmux'
" <
" If you are having issues with <C-h> in a neovim buffer, see
" `https://github.com/neovim/neovim/issues/2048#issuecomment-78045837`
"
" https://github.com/neovim/neovim/issues/2048#issuecomment-78045837
"
" @subsection Layer options
"
" `enable_tmux_clipboard`: this option is used to enable or disable tmux
" clipboard, by default this option is `false`.
"
" @subsection mappings
" >
@ -27,12 +37,18 @@
" <C-l> normal Switch to vim/tmux pane in right direction
" <
if exists('s:enable_tmux_clipboard')
finish
endif
let s:enable_tmux_clipboard = 0
function! SpaceVim#layers#tmux#plugins() abort
let plugins = [
\ ['christoomey/vim-tmux-navigator', { 'on_cmd': [
\ 'TmuxNavigateLeft', 'TmuxNavigateDown', 'TmuxNavigateUp',
\ 'TmuxNavigateRight'] }],
\ ]
\ 'TmuxNavigateLeft', 'TmuxNavigateDown', 'TmuxNavigateUp',
\ 'TmuxNavigateRight'] }],
\ ]
call add(plugins, ['tmux-plugins/vim-tmux', {'on_ft' : 'tmux'}])
call add(plugins, ['edkolev/tmuxline.vim', {'merged' : 0}])
return plugins
@ -47,6 +63,11 @@ function! SpaceVim#layers#tmux#config() abort
autocmd FocusLost * set nocursorline | redraw!
augroup END
if s:enable_tmux_clipboard
call s:Enable()
endif
if s:tmux_navigator_modifier ==# 'alt'
nnoremap <silent> <M-h> :TmuxNavigateLeft<CR>
nnoremap <silent> <M-j> :TmuxNavigateDown<CR>
@ -138,13 +159,18 @@ function! SpaceVim#layers#tmux#set_variable(var) abort
let s:tmux_navigator_modifier = get(a:var,
\ 'tmux_navigator_modifier',
\ s:tmux_navigator_modifier)
let s:enable_tmux_clipboard = get(a:var,
\ 'enable_tmux_clipboard',
\ s:enable_tmux_clipboard)
endfunction
function! SpaceVim#layers#tmux#get_options() abort
return ['tmuxline_separators', 'tmuxline_separators_alt', 'tmux_navigator_modifier']
return ['tmuxline_separators',
\ 'tmuxline_separators_alt',
\ 'tmux_navigator_modifier',
\ 'enable_tmux_clipboard']
endfunction
@ -153,3 +179,56 @@ function! SpaceVim#layers#tmux#health() abort
call SpaceVim#layers#tmux#config()
return 1
endfunction
func! s:get_tmux_name() abort
let list = systemlist('tmux list-buffers -F"#{buffer_name}"')
if len(list)==0
return ''
else
return list[0]
endif
endfunc
func! s:get_tmux_buf() abort
return system('tmux show-buffer')
endfunc
func! s:Enable() abort
if $TMUX==''
" not in tmux session
return
endif
let s:lastbname = ''
" if support TextYankPost
if exists('##TextYankPost')==1
" @"
augroup SpaceVim_layer_tmux
autocmd FocusLost * call s:update_from_tmux()
autocmd FocusGained * call s:update_from_tmux()
autocmd TextYankPost * silent! call system('tmux loadb -',join(v:event["regcontents"],"\n"))
augroup END
let @" = s:get_tmux_buf()
else
" vim doesn't support TextYankPost event
" This is a workaround for vim
augroup SpaceVim_layer_tmux
autocmd FocusLost * silent! call system('tmux loadb -',@")
autocmd FocusGained * let @" = s:get_tmux_buf()
augroup END
let @" = s:get_tmux_buf()
endif
endfunc
func! s:update_from_tmux() abort
let buffer_name = s:get_tmux_name()
if s:lastbname != buffer_name
let @" = s:get_tmux_buf()
endif
let s:lastbname=s:get_tmux_name()
endfunc
call s:Enable()

View File

@ -4142,12 +4142,22 @@ MAPPINGS
==============================================================================
TMUX *SpaceVim-layers-tmux*
Adds integration between tmux and vim panes. Switch between panes
seamlessly.syntax highlighting, commenting, man page navigation and ability to
execute lines as tmux commands. This layer is not added by default. To include
it, add `SpaceVim#layers#load('tmux')` to your `~/.SpaceVim.d/init.vim`. If
you are having issues with <C-h> in a neovim buffer, see
`https://github.com/neovim/neovim/issues/2048#issuecomment-78045837`
`tmux` layer adds integration between tmux and vim panes. Switch between panes
seamlessly, syntax highlighting, commenting, man page navigation and ability
to execute lines as tmux commands. This layer is not added by default. To
include it, add following to spacevim configuration file:
>
[[layers]]
name = 'tmux'
<
If you are having issues with <C-h> in a neovim buffer, see
https://github.com/neovim/neovim/issues/2048#issuecomment-78045837
LAYER OPTIONS
`enable_tmux_clipboard`: this option is used to enable or disable tmux
clipboard, by default this option is `false`.
MAPPINGS