【原创】centos7.0下vim配置|【原创】centos7.0下vim配置 分类( Linux --- Cent...)



【原创】centos7.0下vim配置


1、安装vim
sudo apt-get install vim
2、配置文件的位置
在目录 /etc下面,有个名为vimrc的文件,首先把vimrc备份一下。
sudo cp vimrc vimrc_backup
这是系统中公共的vim配置文件,对所有用户都有效。
3、配置文件替换
新建一个文件,名为vimrc,将以下代码贴进去,保存。
把该文件复制到/etc目录下即可。
然后可以用vim编辑一个文件看看格式是否发生变化。


注意问题:
建立文件vimrc后,不要用记事本打开编辑,因为格式可能会很乱。用Notepad++或者Editplus等编辑工具进行编辑,保存。之后在用任何编辑器打开,格式都不会乱(包括记事本)。


vimrc文件内容


" An example for a vimrc file. " " Maintainer: Bram Moolenaar " Last change: 2001 Jul 18 " " 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:.vimrcset encoding=utf-8 set fileencodings=utf-8,gbk,gb2312,gb18030,ucs-bom,latin1set tags=tags; set shiftwidth=4 set ts=4 "set nu set vb t_vb= " 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,startset autoindent" always set autoindenting on set nobackup" do not keep a backup file, use versions instead "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 searchingset nobackup" do not keep a backup file, use versions instead" 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" Make p in Visual mode replace the selected text with the "" register. vnoremap p :let current_reg = @"gvs=current_reg" 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" For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78" 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`\"" | \ endifendif " has("autocmd")if has("cscope") let current = "." let num = 1 while num < 20 if filereadable(current . "/cscope.out") let $CSCOPE_DB = current . "/cscope.out" cs add $CSCOPE_DB break else let current = current . "/.." let num = num + 1 endif endwhile endifsyntax enable syntax on colorscheme desertfiletype plugin indent on set completeopt=longest,menuset cst set csto=1 set cscopequickfix=s-,c-,d-,i-,t-,e-,f- " cs add /home/yangxl/readcode/cscope-kernel/cscope.out " cs add /home/yangxl/readcode/cscope-app/cscope.out let Tlist_Enable_Fold_Column = 0 let Tlist_WinWidth = 30 let Tlist_Show_One_File = 1 let g:miniBufExplMapCTabSwitchBufs = 1 let g:miniBufExplMapWindowNavVim = 1 let g:miniBufExplMapWindowNavArrows = 1 let g:winManagerWindowLayout='FileExplorer|TagList' let g:SuperTabRetainCompletionType=2 nmap wm :WMToggle set tabstop=4 "nmap :cs find d "nmap :cs find c "nmap :cs find t "nmap :cs find e "nmap :cs find f "nmap :cs find i nmap :TlistToggle nmap :cs find c =expand("") nmap :cs find s =expand("") nmap :cs find g =expand("") nmap :cs find f nmap :cn nmap :cp "nmap:cs find t =expand("") "nmap:cs find e =expand("") "nmap:cs find f =expand("") "nmap:cs find i ^=expand("")$ "nmap:cs find d =expand("")" Using 'CTRL-spacebar' then a search type makes the vim window " split horizontally, with search result displayed in " the new window."nmap s :scs find s =expand("") "nmap g :scs find g =expand("") "nmap c :scs find c =expand("") "nmap t :scs find t =expand("") "nmap e :scs find e =expand("") "nmap f :scs find f =expand("") "nmap i :scs find i ^=expand("")$ "nmap :scs find d =expand("")" Hitting CTRL-space *twice* before the search type does a vertical " split instead of a horizontal one"nmap s \:vert scs find s =expand("") "nmap g \:vert scs find g =expand("") "nmap c \:vert scs find c =expand("") "nmap t \:vert scs find t =expand("") "nmap e \:vert scs find e =expand("") "nmap i \:vert scs find i ^=expand("")$ "nmap \:vert scs find d =expand("")set nu set mouse=a set autoindent set cindentfiletype plugin indent on "打开文件类型检测, 加了这句才可以用智能补全 set completeopt=longest,menu""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""新文件标题 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "新建.c,.h,.sh,.java文件,自动插入文件头 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" ""定义函数SetTitle,自动插入文件头 func SetTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"\#########################################################################") call append(line("."), "\# File Name: ".expand("%")) call append(line(".")+1, "\# Author: genglut") call append(line(".")+2, "\# Mail: genglut@163.com") call append(line(".")+3, "\# Created Time: ".strftime("%c")) call append(line(".")+4, "\#########################################################################") call append(line(".")+5, "\#!/bin/bash") call append(line(".")+6, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: genglut") call append(line(".")+2, " > Mail: genglut@163.com") call append(line(".")+3, " > Created Time: ".strftime("%c")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endif if &filetype == 'cpp' call append(line(".")+6, "#include") call append(line(".")+7, "using namespace std; ") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include") call append(line(".")+7, "") endif " if &filetype == 'java' "call append(line(".")+6,"public class ".expand("%")) "call append(line(".")+7,"") " endif "新建文件后,自动定位到文件末尾 autocmd BufNewFile * normal G endfunc """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 显示相关 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "set shortmess=atI" 启动的时候不显示那个援助乌干达儿童的提示 "winpos 5 5" 设定窗口位置 "set lines=40 columns=155" 设定窗口大小" set go=" 不要图形按钮 "color asmanian2" 设置背景主题 "set guifont=Courier_New:h10:cANSI" 设置字体 "syntax on" 语法高亮 " "autocmd InsertLeave * se nocul" 用浅色高亮当前行 "autocmd InsertEnter * se cul" 用浅色高亮当前行 set ruler" 显示标尺 set showcmd" 输入的命令显示出来,看的清楚些 "set cmdheight=1" 命令行(在状态行下)的高度,设置为1 "set whichwrap+=<,>,h,l" 允许backspace和光标键跨越行边界(不建议) "set scrolloff=3" 光标移动到buffer的顶部和底部时保持3行距离 " set novisualbell" 不要闪烁(不明白) set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}"状态行显示的内容 set laststatus=1" 启动显示状态行(1),总是显示状态行(2) set foldenable" 允许折叠 set foldmethod=manual" 手动折叠 "set background=dark "背景使用黑色 " set nocompatible"去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 " 显示中文帮助 if version >= 603 set helplang=cn set encoding=utf-8 endif " 设置配色方案 "colorscheme murphy "字体 "if (has("gui_running")) "set guifont=Bitstream\ Vera\ Sans\ Mono\ 10 "endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "键盘命令 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""nmap w :w! nmap f :find" 映射全选+复制 ctrl+a map ggVGY map! ggVGY map gg=G " 选中状态下 Ctrl+c 复制 vmap "+y "去空行 nnoremap :g/^\s*$/d "比较文件 nnoremap :vert diffsplit "新建标签 map :tabnew "列出当前目录文件 map :tabnew . "打开树状文件目录 map \be "C,C++ 按F5编译运行 map :call CompileRunGcc() func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!./% elseif &filetype == 'py' exec "!python %" exec "!python %<" endif endfunc "C,C++的调试 map :call Rungdb() func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<" endfunc

【【原创】centos7.0下vim配置|【原创】centos7.0下vim配置 分类( Linux --- Cent...)】
原文链接 http://blog.csdn.net/geng823/article/details/41804399



版权声明:本文为博主原创文章,未经博主允许不得转载。
转载于:https://www.cnblogs.com/gengzj/p/4675772.html

    推荐阅读