最近笔记本从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就复制好了。