vim复制代码包含注释时格式会乱掉

编程技术  /  houtizong 发布于 3年前   274
转自:http://socol.iteye.com/blog/579503


每次复制代码时,如果代码里有 // 这样的注释就容易让格式乱掉,通过下面的设置就可以避免这种情况。粘贴代码时取消自动缩进VIM在粘贴代码时会自动缩进,把代码搞得一团糟糕,甚至可能因为某行的一个注释造成后面的代码全部被注释掉,我知道有同学这个时候会用vi去打开文件再粘贴上去(鄙人以前就是这样),其实需要先设置一下set paste然后再进入插入模式粘贴,代码就不会被自动缩进。可是敲代码的时候需要自动缩进,又得改回来:set nopaste最方便的方法就是在.vimrc中加一句:set pastetoggle=<F9>以后在插入模式下,只要按F9键就可以切换自动缩进。

中文乱码问题
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936   set termencoding=utf-8   set encoding=utf-8

.vimrc
" An example for a vimrc file."" Maintainer:Bram Moolenaar <[email protected]>" Last change:2000 Jan 06"" To use it, copy it to"     for Unix and OS/2:  ~/.vimrc"      for Amiga:  s:.vimrc"  for MS-DOS and Win32:  $VIM\_vimrc"for VMS:  sys$login:.vimrc" Use Vim settings, rather then Vi settings (much better!)." This must be first, because it changes other options as a side effect.set nocompatible"set fileencodings=gb2312,gb18030,utf-8"set termencoding=utf-8"set encoding=prcset nuset bs=2" allow backspacing over everything in insert modeset noai" always set autoindenting on"set backup" keep a backup fileset viminfo='20,\"50" read/write a .viminfo file, don't store more" than 50 lines of registersset history=50" keep 50 lines of command line historyset ruler" show the cursor position all the time"set nonu"set bdir=~/.vimbackupset term=linuxset nowrapset bg=darkset tabstop=4" 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 formattingmap Q gq" Make p in Visual mode replace the selected text with the "" register.vnoremap p <Esc>:let current_reg = @"<CR>gvdi<C-R>=current_reg<CR><Esc>" 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 hlsearchendif" Only do this part when compiled with support for autocommands.if has("autocmd") " In text files, always limit the width of text to 78 characters autocmd BufRead *.txt set tw=78 augroup cprog  " Remove all cprog autocommands  au!  " When starting to edit a file:  "   For C and C++ files set formatting of comments and set C-indenting on.  "   For other files switch it off.  "   Don't change the order, it's important that the line with * comes first.  autocmd FileType *      set formatoptions=tcql nocindent comments&  autocmd FileType c,cpp  set formatoptions=croql cindent comments=sr:/*,mb:*,el:*/,:// augroup END augroup gzip  " Remove all gzip autocommands  au!  " Enable editing of gzipped files  " set binary mode before reading the file  autocmd BufReadPre,FileReadPre*.gz,*.bz2 set bin  autocmd BufReadPost,FileReadPost*.gz call GZIP_read("gunzip")  autocmd BufReadPost,FileReadPost*.bz2 call GZIP_read("bunzip2")  autocmd BufWritePost,FileWritePost*.gz call GZIP_write("gzip")  autocmd BufWritePost,FileWritePost*.bz2 call GZIP_write("bzip2")  autocmd FileAppendPre*.gz call GZIP_appre("gunzip")  autocmd FileAppendPre*.bz2 call GZIP_appre("bunzip2")  autocmd FileAppendPost*.gz call GZIP_write("gzip")  autocmd FileAppendPost*.bz2 call GZIP_write("bzip2")  " After reading compressed file: Uncompress text in buffer with "cmd"  fun! GZIP_read(cmd)    " set 'cmdheight' to two, to avoid the hit-return prompt    let ch_save = &ch    set ch=3    " when filtering the whole buffer, it will become empty    let empty = line("'[") == 1 && line("']") == line("$")    let tmp = tempname()    let tmpe = tmp . "." . expand("<afile>:e")    " write the just read lines to a temp file "'[,']w tmp.gz"    execute "'[,']w " . tmpe    " uncompress the temp file "!gunzip tmp.gz"    execute "!" . a:cmd . " " . tmpe    " delete the compressed lines    '[,']d    " read in the uncompressed lines "'[-1r tmp"    set nobin    execute "'[-1r " . tmp    " if buffer became empty, delete trailing blank line    if empty      normal Gdd''    endif    " delete the temp file    call delete(tmp)    let &ch = ch_save    " When uncompressed the whole buffer, do autocommands    if empty      execute ":doautocmd BufReadPost " . expand("%:r")    endif  endfun  " After writing compressed file: Compress written file with "cmd"  fun! GZIP_write(cmd)    if rename(expand("<afile>"), expand("<afile>:r")) == 0      execute "!" . a:cmd . " <afile>:r"    endif  endfun  " Before appending to compressed file: Uncompress file with "cmd"  fun! GZIP_appre(cmd)    execute "!" . a:cmd . " <afile>"    call rename(expand("<afile>:r"), expand("<afile>"))  endfun augroup END " This is disabled, because it changes the jumplist.  Can't use CTRL-O to go " back to positions in previous files more than once. if 0  " When editing a file, always jump to the last cursor position.  " This must be after the uncompress commands.   autocmd BufReadPost * if line("'\"") && line("'\"") <= line("$") | exe "normal `\"" | endif endifendif " has("autocmd")set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936set termencoding=utf-8set encoding=utf-8
上一篇:xapian例子
下一篇:c调用c++

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客