在vim和Windows中实现无缝复制粘贴:
而ctrl-c以及ctrl-v用到的是系统剪贴板(system clipboard)。vim寄存器和系统剪贴板不是一个东西。顾名思义,vim寄存器的数据作用域仅限于vim本地,甚至如果开多个vim窗口,每个窗口都有一套自己完整的寄存器,互相不影响。而系统剪贴板作为系统级别的全局变量,两边当然不能混用。所以vim专门提供了"+寄存器作为对系统剪贴板的映射。可以理解成自动把"+寄存器的内容再复制一份到系统剪贴板,前提是你得把clipboard属性设置成打开。有些版本(比如MacOS自带的vim)就不支持这个映射。重装vim就是为了打开这个开关。(如果有简便的直接改设置方法,请纠正我)。打开以后用"+y命令把内容复制到和系统剪贴板关联的寄存器"+上。而y只是复制到默认无名寄存器""上。
作者:胖君
链接:https://www.zhihu.com/question/19863631/answer/442180294
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
- win中内容粘贴到vim中:
ctrl+shift+v
。 - 通过下面的vim配置后,将vim中内容复制到win中:
ctrl+a,ctrl+v
。
- " An example for a vimrc file.
- "
- " To use it, copy it to
- " for Unix and OS/2: ~/.vimrc
- " for Amiga: s:.vimrc
- " for MS-DOS and Win32: $VIM\_vimrc
- " for OpenVMS: sys$login:.vimrc
- " When started as "evim", evim.vim will already have done these settings.
- if v:progname =~? "evim"
- finish
- endif
- " Use Vim settings, rather then Vi settings (much better!).
- " This must be first, because it changes other options as a side effect.
- set nocompatible
- " allow backspacing over everything in insert mode
- set backspace=indent,eol,start
- if has("vms")
- set nobackup " do not keep a backup file, use versions instead
- else
- set backup " keep a backup file
- endif
- set history=50 " keep 50 lines of command line history
- set ruler " show the cursor position all the time
- set showcmd " display incomplete commands
- set incsearch " do incremental searching
- "==========================================================================
- "My Setting-sunshanlu
- "==========================================================================
- vmap <leader>y :w! /tmp/vitmp<CR>
- nmap <leader>p :r! cat /tmp/vitmp<CR>
- "语法高亮
- syntax enable
- syntax on
- "显示行号
- set nu
- "修改默认注释颜色
- "hi Comment ctermfg=DarkCyan
- "允许退格键删除
- "set backspace=2
- "启用鼠标
- set mouse=a
- set selection=exclusive
- set selectmode=mouse,key
- "按C语言格式缩进
- set cindent
- set autoindent
- set smartindent
- set shiftwidth=4
- " 允许在有未保存的修改时切换缓冲区
- "set hidden
- " 设置无备份文件
- set writebackup
- set nobackup
- "显示括号匹配
- "set showmatch
- "括号匹配显示时间为1(单位是十分之一秒)
- set matchtime=5
- "显示当前的行号列号:
- set ruler
- "在状态栏显示正在输入的命令
- set showcmd
- set foldmethod=syntax
- "默认情况下不折叠
- set foldlevel=100
- " 开启状态栏信息
- set laststatus=2
- " 命令行的高度,默认为1,这里设为2
- "set cmdheight=2
- " 显示Tab符,使用一高亮竖线代替
- "set list
- "set listchars=tab:\|\ ,
- "set listchars=tab:>-,trail:-
- inoremap jk <ESC>
- map <C-a> ggVG
- map <C-c>: "+y
- let g:netrw_winsize=25
- let g:newtrw_browse_split=3
- "侦测文件类型
- filetype on
- "载入文件类型插件
- filetype plugin on
- "为特定文件类型载入相关缩进文件
- filetype indent on
- " 启用自动补全
- filetype plugin indent on
- "设置编码自动识别, 中文引号显示
- filetype on "打开文件类型检测
- "set fileencodings=euc-cn,ucs-bom,utf-8,cp936,gb2312,gb18030,gbk,big5,euc-jp,euc-kr,latin1
- set fileencodings=utf-8,gb2312,gbk,gb18030
- "这个用能很给劲,不管encoding是什么编码,都能将文本显示汉字
- "set termencoding=gb2312
- set termencoding=utf-8
- "新建文件使用的编码
- set fileencoding=utf-8
- "set fileencoding=gb2312
- "用于显示的编码,仅仅是显示
- set encoding=utf-8
- "set encoding=utf-8
- "set encoding=euc-cn
- "set encoding=gbk
- "set encoding=gb2312
- "set ambiwidth=double
- set fileformat=unix
- "设置高亮搜索
- set hlsearch
- "在搜索时,输入的词句的逐字符高亮
- set incsearch
- " 着色模式
- set t_Co=256
- "colorscheme wombat256mod
- "colorscheme gardener
- "colorscheme elflord
- colorscheme desert
- "colorscheme evening
- "colorscheme darkblue
- "colorscheme torte
- "colorscheme default
- " 字体 && 字号
- set guifont=Monaco:h10
- "set guifont=Consolas:h10
- " :LoadTemplate 根据文件后缀自动加载模板
- "let g:template_path='/home/ruchee/.vim/template/'
- " :AuthorInfoDetect 自动添加作者、时间等信息,本质是NERD_commenter && authorinfo的结合
- ""let g:vimrc_author='sunshanlu'
- ""let g:vimrc_email='sunshanlu@baidu.com'
- ""let g:vimrc_homepage='http://www.sunshanlu.com'
- "
- "
- " Ctrl + E 一步加载语法模板和作者、时间信息
- ""map <c-e> <ESC>:AuthorInfoDetect<CR><ESC>Gi
- ""imap <c-e> <ESC>:AuthorInfoDetect<CR><ESC>Gi
- ""vmap <c-e> <ESC>:AuthorInfoDetect<CR><ESC>Gi
- map <c-]> g<c-]>
- " ======= 引号 && 括号自动匹配 ======= "
- "
- ":inoremap ( ()<ESC>i
- ":inoremap ) <c-r>=ClosePair(')')<CR>
- "
- ":inoremap { {}<ESC>i
- "
- ":inoremap } <c-r>=ClosePair('}')<CR>
- "
- ":inoremap [ []<ESC>i
- "
- ":inoremap ] <c-r>=ClosePair(']')<CR>
- "
- ":inoremap < <><ESC>i
- "
- ":inoremap > <c-r>=ClosePair('>')<CR>
- "
- "":inoremap " ""<ESC>i
- "
- ":inoremap ' ''<ESC>i
- "
- ":inoremap ` ``<ESC>i
- "
- ":inoremap * **<ESC>i
- " 每行超过80个的字符用下划线标示
- ""au BufRead,BufNewFile *.s,*.asm,*.h,*.c,*.cpp,*.java,*.cs,*.lisp,*.el,*.erl,*.tex,*.sh,*.lua,*.pl,*.php,*.tpl,*.py,*.rb,*.erb,*.vim,*.js,*.jade,*.coffee,*.css,*.xml,*.html,*.shtml,*.xhtml Underlined /.\%81v/
- "
- "
- " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
- " let &guioptions = substitute(&guioptions, "t", "", "g")
- " Don't use Ex mode, use Q for formatting
- map Q gq
- " This is an alternative that also works in block mode, but the deleted
- " text is lost and it only works for putting the current register.
- "vnoremap p "_dp
- " Switch syntax highlighting on, when the terminal has colors
- " Also switch on highlighting the last used search pattern.
- if &t_Co > 2 || has("gui_running")
- syntax on
- set hlsearch
- endif
- " Only do this part when compiled with support for autocommands.
- if has("autocmd")
- " Enable file type detection.
- " Use the default filetype settings, so that mail gets 'tw' set to 72,
- " 'cindent' is on in C files, etc.
- " Also load indent files, to automatically do language-dependent indenting.
- filetype plugin indent on
- " Put these in an autocmd group, so that we can delete them easily.
- augroup vimrcEx
- au!
- " For all text files set 'textwidth' to 80 characters.
- autocmd FileType text setlocal textwidth=80
- " When editing a file, always jump to the last known cursor position.
- " Don't do it when the position is invalid or when inside an event handler
- " (happens when dropping a file on gvim).
- autocmd BufReadPost *
- \ if line("'\"") > 0 && line("'\"") <= line("$") |
- \ exe "normal g`\"" |
- \ endif
- augroup END
- else
- set autoindent " always set autoindenting on
- endif " has("autocmd")
- " 增加鼠标行高亮
- "set cursorline
- "hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
- " 设置tab是四个空格
- set ts=4
- set expandtab
- " 主要给Tlist使用
- let Tlist_Exit_OnlyWindow = 1
- let Tlist_Auto_Open = 1
- "配置vim的内置终端
- noremap <C-i> :belowright term ++rows=8<CR>
- ""NerdTree插件的配置信息
- ""打开vim时,自动打开NERDTree
- "autocmd vimenter * NERDTree
- ""将F2设置为开关NERDTree的快捷键
- "map <F2> :NERDTreeMirror<CR>
- "map <f2> :NERDTreeToggle<cr>
- "设置Ctrl+n为开关NERDTree的快捷键
- map <C-n> :NERDTreeMirror<CR>
- map <C-n> :NERDTreeToggle<cR>
- ""修改树的显示图标
- let g:NERDTreeDirArrowExpandable = '+'
- let g:NERDTreeDirArrowCollapsible = '-'
- ""窗口位置
- let g:NERDTreeWinPos='left'
- ""窗口尺寸
- let g:NERDTreeSize=30
- ""窗口是否显示行号
- let g:NERDTreeShowLineNumbers=1
- ""不显示隐藏文件
- let g:NERDTreeHidden=0
- "ctags"
- set tags=tags;
- set autochdir
- "========================="
- set tags+=~/.vim/systags
- "========================="
- if has("cscope")
- set csto=0
- set nocsverb
- " add any database in current directory
- if filereadable("cscope.out")
- "cs add cscope.out
- cs add $PWD/cscope.out $PWD
- else "子目录打开,向上查找
- let cscope_file=findfile("cscope.out", ".;")
- let cscope_pre=matchstr(cscope_file, ".*/")
- if !empty(cscope_file) && filereadable(cscope_file)
- exe "cs add" cscope_file cscope_pre
- endif
- endif
- set csverb
- "set cst 这两句会将cscope当作tag,当找不到时会卡住,因此注释掉
- "set cscopetag
- endif
- nmap zs :cs find s <C-R>=expand("<cword>")<CR><CR>
- nmap zg :cs find g <C-R>=expand("<cword>")<CR><CR>
- nmap zc :cs find c <C-R>=expand("<cword>")<CR><CR>
- nmap zt :cs find t <C-R>=expand("<cword>")<CR><CR>
- nmap ze :cs find e <C-R>=expand("<cword>")<CR><CR>
- nmap zf :cs find f <C-R>=expand("<cfile>")<CR><CR>
- nmap zi :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
- nmap zd :cs find d <C-R>=expand("<cword>")<CR><CR>