最近筆記本從13年的X1 carbon換到了mbp 16",操作系統也從ubuntu換成了macOs。一些軟件的快捷鍵也和以前的不一樣,比如以前ctrl C復制,ctrl V黏貼老熟了,但蘋果系統換成了command + 的形式,還好可以把ctrl鍵設置成與command鍵互換,但以前用的idea,pycharm等里面的快捷鍵也和ubuntu/windows里的不太一樣,還是需要適應一下。
今天用vim的時候遇到一個問題,我開了兩個終端,需要從一個終端的vim里拷貝一段文字到另外一個終端。首先我想拷貝一段文字,以前我可以按住shift + 方向鍵選中多行,然后ctrl c,ctrl v就搞定了。在mac這邊按shift選不中多行,那用快捷鍵yy選中多行,然后p總可以了吧。但尷尬的是只能在同一個終端里這樣做,因為yy沒有把內容拷貝到剪切板里。在網上查了一下,我用vim --version查了一下,只要feature clipboard 上有+號就可以
(base) gaoxianghu@gaoxiangs-MacBook-Pro cheap % vim --version VIM - Vi IMproved 8.2 (2019 Dec 12, compiled May 19 2020 22:09:59) macOS version Included patches: 1-800 Compiled by Homebrew Huge version without GUI. Features included (+) or not (-): +acl -farsi +mouse_sgr +tag_binary +arabic +file_in_path -mouse_sysmouse -tag_old_static +autocmd +find_in_path +mouse_urxvt -tag_any_white +autochdir +float +mouse_xterm -tcl -autoservername +folding +multi_byte +termguicolors -balloon_eval -footer +multi_lang +terminal +balloon_eval_term +fork() -mzscheme +terminfo -browse +gettext +netbeans_intg +termresponse ++builtin_terms -hangul_input +num64 +textobjects +byte_offset +iconv +packages +textprop +channel +insert_expand +path_extra +timers +cindent +ipv6 +perl +title -clientserver +job +persistent_undo -toolbar +clipboard +jumplist +popupwin +user_commands +cmdline_compl +keymap +postscript +vartabs +cmdline_hist +lambda +printer +vertsplit +cmdline_info +langmap +profile +virtualedit +comments +libcall -python +visual +conceal +linebreak +python3 +visualextra +cryptv +lispindent +quickfix +viminfo +cscope +listcmds +reltime +vreplace +cursorbind +localmap +rightleft +wildignore +cursorshape +lua +ruby +wildmenu +dialog_con +menu +scrollbind +windows +diff +mksession +signs +writebackup +digraphs +modify_fname +smartindent -X11 -dnd +mouse -sound -xfontset -ebcdic -mouseshape +spell -xim +emacs_tags +mouse_dec +startuptime -xpm +eval -mouse_gpm +statusline -xsmp +ex_extra -mouse_jsbterm -sun_workshop -xterm_clipboard +extra_search +mouse_netterm +syntax -xterm_save system vimrc file: "$VIM/vimrc" user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" user exrc file: "$HOME/.exrc" defaults file: "$VIMRUNTIME/defaults.vim" fall-back for $VIM: "/usr/local/share/vim" Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 Linking: clang -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv -lintl -framework AppKit -L/usr/local/opt/lua/lib -llua5.3 -mmacosx-version-min=10.15 -fstack-protector-strong -L/usr/local/lib -L/usr/local/Cellar/perl/5.30.2_1/lib/perl5/5.30.2/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -L/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/config-3.8-darwin -lpython3.8 -framework CoreFoundation -lruby.2.7
可以看到這個系統自帶的vim是支持剪切板的,網上搜了一下,還要在.vimrc上加上set clipboard=unamed,不過我加上這句后連vim打開就說這行參數錯誤,查了下,改成了set clipboard^=unnamed,unnamedplus, .vimrc配置如下
1 syntax enable 2 set number 3 set cursorline 4 set ruler 5 set shiftwidth=4 6 set softtabstop=4 7 set tabstop=4 8 set clipboard^=unnamed,unnamedplus
這下剪切板的問題解決,現在我每次要復制一段文字,我就先在一個vim終端中按v進入visual模式,然后按向上,向下箭頭選取要拷貝的行,然后yy,vim底下會提示“50 lines yanked”,然后到另外一個vim,不用進入到編輯模式,直接p就復制好了。