linux:vim setting

basic vim setting:


从VIM 复制到系统:"shift" + "y"

也有:“+y

从系统复制,后粘贴到VIM:shift 加 ctrl 加  v


set clipboard=unnamed,就默认使用windows的剪贴板了


____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

https://my.oschina.net/u/251879/blog/208701

问题描述:在vim写完ACM代码后,需要把代码复制到剪切板中,从而上传到判定网站,但是使用命令

                sudo apt-get install vim

                安装的vim不支持这样的操作。

问题原因:安装vim不支持xtem_clipboard,无法复制到+寄存器

解决方案:安装vim-gnome或者vim-gtk

                sudo apt-get install vim-gnome

                进入vim,使用命令

                ggVG"+y

                即可将全文复制到剪切板。

参考链接:http://blog.fooleap.org/using-vim-with-clipboard-on-archlinux.html

                http://vim.wikia.com/wiki/Accessing_the_system_clipboard

                链接中有关于+和*寄存器的详细描述。


————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

作者:whinc
链接:https://www.zhihu.com/question/19863631/answer/89354508
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Vim 中的复制、删除的内容都会被存放到默认(未命名)寄存器中,之后可以通过粘贴操作读取默认寄存器中的内容。寄存器是完成这一过程的中转站,Vim 支持的寄存器非常多,其中常用的有 a-zA-Z0-9+“。其中:

  • 0-9:表示数字寄存器,是 Vim 用来保存最近复制、删除等操作的内容,其中 0 号寄存器保存的是最近一次的操作内容。
  • a-zA-Z:表示用户寄存器,Vim 不会读写这部分寄存器
    • "(单个双引号):未命名的寄存器,是 Vim 的默认寄存器,例如删除、复制等操作的内容都会被保存到这里。
    • +:剪切板寄存器,关联系统剪切板,保存在这个寄存器中的内容可以被系统其他程序访问,也可以通过这个寄存器访问其他程序保存到剪切板中的内容。

    如果想了解更多寄存器内容,可参vimdoc.sourceforge.net/


    通过下面命令可以查看所有寄存器中的内容,也可以只查看指定寄存器的内容(将寄存器名称作为参数)

    :reg [register_name] 
    

    有了上面的基础知识后,要实现题主"将 Vim 剪贴板里面的东西粘贴到 Vim 之外的地方?"就很明了,只需要将内容复制到剪切板寄存器(+)中即可,其他程序便可以访问到了。


    "+yy  // 复制当前行到剪切板
    "+p   // 将剪切板内容粘贴到光标后面
    "ayy  // 复制当前行到寄存器 a
    "ap   // 将寄存器 a 中的内容粘贴到光标后面
    

    ---------------------------------- 2016-03-05 旧的回答 -------------------------------------------


    Vim 有12个粘贴板依次编号为:0、1、2、...、9、a、"、+,其中 + 号为系统粘贴板,” 为临时粘贴板。系统剪切板中的内容可在其他程序中使用。上面的复制指令都可以配合剪切板进行操作。

    "nyw 复制当前单词到 n 号剪切板(双引号开始)
    "np 粘贴 n 号剪切板内容到当前位置后
    "+Y 复制当前行到系统剪切板
    "+nY 复制当前行往下 n 行到系统剪切板
    "+p 粘贴系统剪切板内容到当前位置后


————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

看了回答怎么试都不行, 原来自己的是ubuntu系统, 默认不支持, 需要先安装一个东西:

`sudo apt-get install vim-gnome`

然后就可以使用`gg"+yG`了

[参考资料](ubuntu vim复制到系统剪切板)


————————————————————————————————————————————————————————————————————————————————————————————————————————————————————




"BASIC SETTINGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  

set nu  
set showmatch           " 高亮显示匹配的括号  
set matchtime=6         " 匹配括号高亮的时间(单位是十分之一秒)  
set scrolloff=11        " 光标移动到buffer的顶部和底部时保持10行距离  
set novisualbell        " 不要闪烁  
set hlsearch            " 高亮搜索  
set nowrapscan          " 查找到文件头或文件尾时停止



set clipboard=unnamedplus             " 共享剪切板    
set showcmd                        " 输入的命令显示出来    
set iskeyword+=_,$,@,%,#,-         " 带有如下符号的单词不要被换行分割    
set noexpandtab                    " 不用空格代替Tab (makefile是会经常用Tab的)    
set tabstop=5                      " Tab 键的宽度    
set shiftwidth=5                   " 行交错宽度    
set mouse=a                        " 鼠标可用    
set autoindent                     " 继承前一行的缩进方式,特别适用于多行注释

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  





"THE FILE OF LULU
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
" Copycat: lulu  
" Version: 4.2.3  
" Install: 在linux和windows下无需改动配置文件的内容,对应配置文件夹是vim_4  
"          在linux下在 ~/ 目录下,配置文件名改成 .vimrc,路径为 ~/.vimrc  
"                        配置文件夹名改成 .vim,路径为 ~/.vim  
"          在windows下在 $(vim)/ 目录下,配置文件名改成 _vimrc,路径为 Vim/_vimrc  
"                            配置文件夹名改成 vimfiles,路径为 Vim/vimfiles  
" NoBugs:  windows下 taglist使用有问题已修复  
" Time:    2013.8.3  
"  

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
" 文本格式和排版  
"  
set formatoptions=tcrqn     " 自动格式化  
set autoindent          " 继承前一行的缩进方式,特别适用于多行注释  
set smartindent         " 为C程序提供自动缩进  
set cindent             " 使用C样式的缩进  
set smarttab            " 在行和段开始处使用制表符  
"set tabstop=4          " 制表符为4  
"set softtabstop=4      " 统一缩进为4  
"set shiftwidth=4  
"set noexpandtab        " 不要用空格代替制表符  
"set nowrap             " 不要换行  
  
    
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
" 搜索和匹配   
"  
set showmatch           " 高亮显示匹配的括号  
set matchtime=5         " 匹配括号高亮的时间(单位是十分之一秒)  
set scrolloff=10        " 光标移动到buffer的顶部和底部时保持10行距离  
set novisualbell        " 不要闪烁  
set hlsearch            " 高亮搜索  
set nowrapscan          " 查找到文件头或文件尾时停止  
"set incsearch          " 边输入边查找  
"set laststatus=2       " 总是显示状态行  
"set ignorecase         " 在搜索的时候忽略大小写  
"set statusline=%F%m%r%h%w\[POS=%l,%v][%p%%]\%{strftime(\”%d/%m/%y\ -\ %H:%M\”)}   
                " 我的状态行显示的内容(包括文件类型和解码)  
                  
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置  
"  
set shortmess=atI       " 启动的时候不显示那个援助索马里儿童的提示`  
set report=0            " 通过使用: commands命令,告诉我们文件的哪一行被改变过  
set noerrorbells        " 不让vim发出讨厌的滴滴声  
set fillchars=vert:\ ,stl:\     " 在被分割的窗口间显示空白,便于阅读 ,stlnc:加了这个wm分割兰有  
set mouse=a             " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)  
set selection=exclusive  
"set selectmode=mouse,key

 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 一般设置  
"
set viminfo+=!          " 保存全局变量  
set history=300         " history文件中需要记录的行数  
set nocompatible        " 不要使用vi的键盘模式,而是vim自己的  
set foldmethod=syntax  
set foldlevel=100       " 启动vim时不要自动折叠代码  
"set nu  
set fileencodings=utf-8,gbk  
set ruler  
set showmatch           " 高亮显示匹配的括号   
filetype on             " 侦测文件类型   
"set nobackup            " 不要备份文件(根据自己需要取舍)   
"set backup  
syntax enable  
syntax on           " 语法高亮   
set magic           " 设置正表达式  
set backspace=indent,eol,start  " 这指明在插入模式下在哪里允许 <BS> 删除光标前面的字符。  
                " 逗号分隔的三个值分别指:行首的空白字符,换行符和插入模式开始处之前的字符。  
set showcmd             " 在 Vim 窗口右下角,标尺的右边显示未完成的命令

 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""



 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" taglist   
"  
let Tlist_Use_Right_Window = 0      " 在左侧显示窗口  
let Tlist_Compart_Format = 1        " 压缩方式  
let Tlist_Exist_OnlyWindow = 1      " 如果只有一个buffer,kill窗口也kill掉buffer  
let Tlist_File_Fold_Auto_Close = 0  " 不要关闭其他文件的tags  
let Tlist_Enable_Fold_Column = 0    " 不要显示折叠树 (鼠标可以点开)  
nmap <silent> <leader>tl :Tlist<cr>  
  
  if has("win32")               
      let Tlist_Ctags_Cmd = '   ctags' "windows下必须空3个字符,否则解析成gs   
      else   
          let Tlist_Ctags_Cmd = '/usr/bin/ctags'  
     endif  

 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GUI  
"  
if has("gui_running")           " 如果是图形界面     
    set guioptions=m        " 关闭菜单栏  
        set guioptions=t        " 关闭工具栏  
        "   set guioptions=L        " 启动左边的滚动条  
        "   set guioptions+=r       " 启动右边的滚动条  
        "   set guioptions+=b       " 启动下边的滚动条  
    set clipboard+=unnamed      " 共享剪贴板  
                if has("win32")  
     colorscheme torte    " torte配色方案  
     set guifont=Consolas:h11 " 字体和大小  
      endif  
  endif   

 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""



http://blog.csdn.net/c_o_o_l_u_l_u/article/details/8020306

this is his total file:


    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " Copycat: lulu  
    " Version: 3.2.3  
    " Install: 在linux和windows下无需改动配置文件的内容,对应配置文件夹是vim_3  
    "          在linux下在 ~/ 目录下,配置文件名改成 .vimrc,路径为 ~/.vimrc  
    "                        配置文件夹名改成 .vim,路径为 ~/.vim  
    "          在windows下在 $(vim)/ 目录下,配置文件名改成 _vimrc,路径为 Vim/_vimrc  
    "                            配置文件夹名改成 vimfiles,路径为 Vim/vimfiles  
    " NoBugs:  windows下 taglist使用有问题已修复  
    " Time:    2012.8.3  
    "  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " 文本格式和排版  
    "  
    set formatoptions=tcrqn     " 自动格式化  
    set autoindent          " 继承前一行的缩进方式,特别适用于多行注释  
    set smartindent         " 为C程序提供自动缩进  
    set cindent             " 使用C样式的缩进  
    set smarttab            " 在行和段开始处使用制表符  
    "set tabstop=4          " 制表符为4  
    "set softtabstop=4      " 统一缩进为4  
    "set shiftwidth=4  
    "set noexpandtab        " 不要用空格代替制表符  
    "set nowrap             " 不要换行  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " 搜索和匹配   
    "  
    set showmatch           " 高亮显示匹配的括号  
    set matchtime=5         " 匹配括号高亮的时间(单位是十分之一秒)  
    set scrolloff=10        " 光标移动到buffer的顶部和底部时保持10行距离  
    set novisualbell        " 不要闪烁  
    set hlsearch            " 高亮搜索  
    set nowrapscan          " 查找到文件头或文件尾时停止  
    "set incsearch          " 边输入边查找  
    "set laststatus=2       " 总是显示状态行  
    "set ignorecase         " 在搜索的时候忽略大小写  
    "set statusline=%F%m%r%h%w\[POS=%l,%v][%p%%]\%{strftime(\”%d/%m/%y\ -\ %H:%M\”)}   
                    " 我的状态行显示的内容(包括文件类型和解码)  
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " 文件设置  
    "  
    set shortmess=atI       " 启动的时候不显示那个援助索马里儿童的提示`  
    set report=0            " 通过使用: commands命令,告诉我们文件的哪一行被改变过  
    set noerrorbells        " 不让vim发出讨厌的滴滴声  
    set fillchars=vert:\ ,stl:\     " 在被分割的窗口间显示空白,便于阅读 ,stlnc:加了这个wm分割兰有  
    set mouse=a             " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)  
    set selection=exclusive  
    set selectmode=mouse,key  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " 一般设置  
    "  
    set viminfo+=!          " 保存全局变量  
    set history=300         " history文件中需要记录的行数  
    set nocompatible        " 不要使用vi的键盘模式,而是vim自己的  
    set foldmethod=syntax  
    set foldlevel=100       " 启动vim时不要自动折叠代码  
    set nu  
    set fileencodings=utf-8,gbk  
    set ruler  
    set showmatch           " 高亮显示匹配的括号   
    filetype on             " 侦测文件类型   
    set nobackup            " 不要备份文件(根据自己需要取舍)   
    "set backup  
    syntax enable  
    syntax on           " 语法高亮   
    set magic           " 设置正表达式  
    set backspace=indent,eol,start  " 这指明在插入模式下在哪里允许 <BS> 删除光标前面的字符。  
                    " 逗号分隔的三个值分别指:行首的空白字符,换行符和插入模式开始处之前的字符。  
    set showcmd             " 在 Vim 窗口右下角,标尺的右边显示未完成的命令  
    " :inoremap ( ()<ESC>i  
    " :inoremap { {<CR>}<ESC>O  
    " :inoremap [ []<ESC>i  
    " :inoremap " ""<ESC>i  
    " :inoremap ' ''<ESC>i  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " GUI  
    "  
    if has("gui_running")           " 如果是图形界面     
        set guioptions=m        " 关闭菜单栏  
        set guioptions=t        " 关闭工具栏  
    "   set guioptions=L        " 启动左边的滚动条  
    "   set guioptions+=r       " 启动右边的滚动条  
    "   set guioptions+=b       " 启动下边的滚动条  
        set clipboard+=unnamed      " 共享剪贴板  
        if has("win32")  
               colorscheme torte    " torte配色方案  
               set guifont=Consolas:h11 " 字体和大小  
        endif  
    endif   
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " taglist   
    "  
    let Tlist_Use_Right_Window = 0      " 在左侧显示窗口  
    let Tlist_Compart_Format = 1        " 压缩方式  
    let Tlist_Exist_OnlyWindow = 1      " 如果只有一个buffer,kill窗口也kill掉buffer  
    let Tlist_File_Fold_Auto_Close = 0  " 不要关闭其他文件的tags  
    let Tlist_Enable_Fold_Column = 0    " 不要显示折叠树 (鼠标可以点开)  
    nmap <silent> <leader>tl :Tlist<cr>  
      
    if has("win32")               
        let Tlist_Ctags_Cmd = '   ctags' "windows下必须空3个字符,否则解析成gs   
    else   
        let Tlist_Ctags_Cmd = '/usr/bin/ctags'  
    endif  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " netrw  
    "  
    let g:netrw_winsize = 35  
    nmap <silent> <leader>fe :Sexplore!<cr>  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " winmanager   
    "  
    let g:winManagerWindowLayout='NERDTree|BufExplorer'  
    "let g:winManagerWindowLayout = 'FileExplorer|TagList'  
    "let g:winManagerWindowLayout = 'FileExplorer'  
    let g:winManagerWidth = 35  
    let g:defaultExplorer = 0  
    nmap wm :WMToggle<cr>  
    nmap <C-W><C-F> :FirstExplorerWindow<cr>  
    nmap <C-W><C-B> :BottomExplorerWindow<cr>  
    autocmd BufWinEnter 
    Buf List
     setl nonumber  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " omnicppcomplete  
    "  
    set nocp  
    filetype plugin on  
    let OmniCpp_DefaultNamespaces = ["std"]     "下面的设置用于当用户预先声明namespace时也能自动补全代码(如使用using std::string)   
      
    "if has("win32")                " 设置代码提示窗口的颜色(默认为粉红色)   
    "   highlight Pmenu ctermbg=13 guibg=LightGray   
    "   highlight PmenuSel ctermbg=7 guibg=DarkBlue guifg=White   
    "   highlight PmenuSbar ctermbg=7 guibg=DarkGray   
    "   highlight PmenuThumb guibg=Black  
    "endif  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " minibufexpl  
    "  
    let g:miniBufExplMapWindowNavVim = 1   
    let g:miniBufExplMapWindowNavArrows = 1   
    let g:miniBufExplMapCTabSwitchBufs = 1   
    let g:miniBufExplModSelTarget = 1   
    "let g:miniBufExplorerMoreThanOne=1         "自动打开  
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""  
    " cscope  
    "  
    if has("cscope")  
        set csto=0  
        set cst  
        set nocsverb  
        if filereadable("cscope.out")       " add any database in current directory       
            cs add cscope.out  
        elseif $CSCOPE_DB != ""         " else add database pointed to by environment         
            cs add $CSCOPE_DB  
        endif  
        set csverb              " 这个必须放在后面,不然windows上找不到cscope.out  
    endif  
      
    nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR> :cw<CR>  
    nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR> :cw<CR>  
    nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR> :cw<CR>  
    nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR> :cw<CR>  
    nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR> :cw<CR>  
    nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR> :cw<CR>  
    nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR> :cw<CR>  
    nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR> :cw<CR>  
    "nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>  
    "nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>  
    "nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>  
    "nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>  
    "nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>  
    "nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>  
    "nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>  
    "nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>    
      
    " Using 'CTRL-spacebar' then a search type makes the vim window  
    " split horizontally, with search result displayed in  
    " the new window.    
    nmap <C-Space>s :scs find s <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space>g :scs find g <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space>c :scs find c <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space>t :scs find t <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space>e :scs find e <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space>f :scs find f <C-R>=expand("<cfile>")<CR><CR>  
    nmap <C-Space>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>  
    nmap <C-Space>d :scs find d <C-R>=expand("<cword>")<CR><CR>    
      
    " Hitting CTRL-space *twice* before the search type does a vertical  
    " split instead of a horizontal one    
    nmap <C-Space><C-Space>s  
        \:vert scs find s <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space><C-Space>g  
        \:vert scs find g <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space><C-Space>c  
        \:vert scs find c <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space><C-Space>t  
        \:vert scs find t <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space><C-Space>e  
        \:vert scs find e <C-R>=expand("<cword>")<CR><CR>  
    nmap <C-Space><C-Space>i  
        \:vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>  
    nmap <C-Space><C-Space>d  
        \:vert scs find d <C-R>=expand("<cword>")<CR><CR>    
      
      
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值