vim 剪下和貼上在 Stretch / Debian 9 中不起作用

vim 剪下和貼上在 Stretch / Debian 9 中不起作用

此處將一些 VM 伺服器升級到 Debian 9。

現在使用時ssh,我們無法在遠端終端之間複製和貼上。

遊標似乎正在移動,並標記文本,儘管以比通常更有趣/不同的方式,但在執行命令 C / 命令 V 或複製並貼上到相應選單時,沒有任何內容被複製到剪貼簿。

我們也嘗試使用 Shift 和其他鍵盤組合來移動滑鼠,但沒有取得正面的結果。

這種情況發生在 OS/X 中,即 Sierra 和 El Capitan,以及 Windows 中,也使用 mobaXterm 終端機。

這種情況是由於 vim 對滑鼠的感知造成的。

根據 Stack Overflow 中的其他問題,我使用/etc/vim/vimrc.local並建立set mouse="r"set mouse="v;效果並不好。

set mouse=""最後在同一個文件中進行設置,並取得了一些成功。

然而,它也不是 100% 的時候都能很好地工作。還可以做什麼?

答案1

解決方法:改成mouse=amouse=r本地的.vimrc.

/usr/share/vim/vim80/defaults.vim如已接受的答案所述,設定此選項的問題是它會在每次更新時被覆蓋。我找了很久,最後找到了這個: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=864074

本地解決方案(有缺陷):
第一個解決方案是使用本地 .vimrc 檔案並將其設定在那裡。 因此,您可以為每個使用者建立一個本地 .vimrc ( ~/.vimrc) 並在那裡設定您的選項。或者創建一個,/etc/skel以便為您創建的每個新用戶自動創建它。

但是當您使用本機.vimrc文件時,您必須在那裡設定所有選項,因為如果有本機文件.vimrc,則defaults.vim根本不會載入!如果沒有本地文件,.vimrc您的所有設定都會被覆蓋defaults.vim

全球解決方案(優選):
我想要為所有用戶提供全域配置,它會載入預設選項,然後使用我的個人設定新增或覆寫預設值。幸運的是,Debian 中有一個選項:/etc/vim/vimrc.local將在/etc/vim/vimrc.因此,您可以建立此文件並載入預設值,防止它們再次載入(在最後),然後新增您的個人選項:

請建立以下文件:/etc/vim/vimrc.local

" This file loads the default vim options at the beginning and prevents
" that they are being loaded again later. All other options that will be set,
" are added, or overwrite the default settings. Add as many options as you
" whish at the end of this file.

" Load the defaults
source $VIMRUNTIME/defaults.vim

" Prevent the defaults from being loaded again later, if the user doesn't
" have a local vimrc (~/.vimrc)
let skip_defaults_vim = 1


" Set more options (overwrites settings from /usr/share/vim/vim80/defaults.vim)
" Add as many options as you whish

" Set the mouse mode to 'r'
if has('mouse')
  set mouse=r
endif

(請注意,$VIMRUNTIME上面程式碼片段中使用的值類似於/usr/share/vim/vim80/defaults.vim。)

如果您還想啟用“舊的複製/貼上行為”,請在該文件的末尾添加以下行:

" Toggle paste/nopaste automatically when copy/paste with right click in insert mode:
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"

inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()

function! XTermPasteBegin()
  set pastetoggle=<Esc>[201~
  set paste
  return ""
endfunction

答案2

使 vim 脫離滑鼠感知的一種方法似乎是註解掉有關滑鼠的配置。

/usr/share/vim/vim80/defaults.vim我註解掉了滑鼠特定的檢測,如下所示:

" In many terminal emulators the mouse works just fine.  By enabling it you
" can position the cursor, Visually select and scroll with the mouse.
"if has('mouse')
"  set mouse=r
"endif

(在這些 vim 設定檔中,「 正在發起註解)。

這項變更使我們可以毫無問題地再次複製和貼上。

我確實同意這些評論,這不是理想的解決方案,因為除非配置文件受到保護(或轉移),否則確實會被覆蓋到任何更新中。當時,由於軟體包版本或我曾經工作的伺服器配置的具體情況,它是唯一有效的。因此,我將這個答案留在這裡,並且它只能用作最後的解決方案

答案3

mouse該選項的 Vim 文檔

按住 Shift 鍵,仍然可以使用 xterm 對滑鼠按鈕的處理。

答案4

很多人建議:set mouse=a,但我發現只能:set mouse=r在 Debian 9 上的 Vim 中啟用複製和貼上。

相關內容