本文永久地址:https://my.oschina.net/bysu/blog/1547768
1.下载:
ftp://ftp.vim.org/pub/vim/pc/vim80-586rt.zip
ftp://ftp.vim.org/pub/vim/pc/gvim80-586.zip
2.把两个压缩文件里面的内容都解压,放到一起(vim),目录结构如下图
3.把目录中的vimrc_example.vim文件重命名为_vimrc,并把下面的配置覆盖进去即可
" An example for a vimrc file. " " Maintainer: Bram Moolenaar <Bram@vim.org> " Last change: 2016 Jul 28 " " 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 " Get the defaults that most users want. source $VIMRUNTIME/defaults.vim if has("vms") set nobackup " do not keep a backup file,use versions instead else set backup " keep a backup file (restore to prevIoUs version) if has('persistent_undo') set undofile " keep an undo file (undo changes after closing) endif endif if &t_Co > 2 || has("gui_running") " Switch on highlighting the last used search pattern. set hlsearch endif " Only do this part when compiled with support for autocommands. if has("autocmd") " Put these in an autocmd group,so that we can delete them easily. augroup vimrcEx au! " For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78 augroup END else set autoindent " always set autoindenting on endif " has("autocmd") " Add optional packages. " " The matchit plugin makes the % command work better,but it is not backwards " compatible. if has('Syntax') && has('eval') packadd matchit endif "==============================去掉启动提示文案:帮助乌干达儿童之类的提示 set shortmess=atI "===============================设置主题 colorscheme darkblue "===============================设置字体大小 set guifont=Consolas:h12 "h12字体大小,bh12中的b表示黑体 "set guifontwide=Microsoft/ YaHei:h12 "=================开启语法高亮提示 Syntax on "==============缩进 set cin nu ts=4 sw=4 sts=4 et acd noswapfile nobackup set bs=eol,start,indent "==================隐藏菜单、工具、滚动条============================ ":set guioptions-=m "remove menu bar ":set guioptions-=T "remove toolbar ":set guioptions-=r "remove right-hand scroll bar ":set guioptions-=L "remove left-hand scroll bar if has("gui_running") au GUIEnter * simalt ~x " 窗口启动时自动最大化 set guioptions-=m " 隐藏菜单栏 set guioptions-=T " 隐藏工具栏 "set guioptions-=L " 隐藏左侧滚动条 set guioptions-=r " 隐藏右侧滚动条 set guioptions-=b " 隐藏底部滚动条 set showtabline=0 " 隐藏Tab栏 endif "==========================中文显示乱码 set encoding=utf-8 set fileencodings=utf-8,chinese,latin-1 if has("win32") set fileencoding=chinese else set fileencoding=utf-8 endif "解决菜单乱码 source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim "解决consle输出乱码 language messages zh_CN.utf-8 "================================符号自动补全 inoremap ' ''<ESC>i inoremap " ""<ESC>i inoremap ( ()<ESC>i inoremap [ []<ESC>i inoremap < <><ESC>i inoremap { {<CR>}<ESC>O inoremap ) <c-r>=ClosePair(')')<CR> inoremap > <c-r>=ClosePair('>')<CR> inoremap } <c-r>=ClosePair('}')<CR> inoremap ] <c-r>=ClosePair(']')<CR> function! ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf "=================================设置跳出自动补全的括号 func SkipPair() let str = getline('.')[col('.')-1] if str == ')' || str == ']' || str == '"' || str == "'" || str == '}' return "\<Right>" elseif strpart(getline('.'),col('.')-1)=~'^\s*$' return "\<Tab>" else return "\<C-N>" endif endfunc " 将tab键绑定为跳出括号 inoremap <TAB> <c-r>=SkipPair()<CR> "=====================小写转换大写 inoremap <C-u> <esc>gUiwea "=====================插入模式移动光标 inoremap <M-k> <Up> inoremap <M-j> <Down> inoremap <M-h> <Left> inoremap <M-l> <Right> inoremap <M-a> <Home> inoremap <M-e> <End> " Rubout word / line and enter insert mode " use <Esc><Right> instead of <C-o> inoremap <C-w> <Esc>dbcl " delete inoremap <C-u> <Esc>d0cl inoremap <C-k> <Esc><Right>C inoremap <C-d> <Esc><Right>s inoremap <C-d> <C-o>de inoremap <M-d> <C-o>de "===================编译java、c、c++、python以及sh脚本 "=======================按F5进行编译运行windows,Linux下需在运行的命令里面加当前目录./ map <F5> :call CompileRunGcc()<CR> imap <F5> <ESC>:call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" exec "cd %:p:h" if &filetype == 'c' exec "!g++ % -o %<" exec "! %<" elseif &filetype == 'cpp' exec "!g++ -std=c++11 -O2 % -o %<" exec "! %<" elseif &filetype == 'java' exec "!javac %<" exec "!java %<" elseif &filetype == 'py' exec "!python %<" elseif &filetype == 'sh' :!./% endif endfunc "======================<F9>gdb调试c或c++ map <F9> :call Debug()<CR> imap <F9> :call Debug()<CR> func! Debug() exec "w" exec "cd %:p:h" if &filetype == 'c' exec "!gcc % -g -o %< -gstabs+" exec "!gdb %<" elseif &filetype == 'cpp' exec "!g++ % -g -o %< -gstabs+" exec "!gdb %<" endfunc "=====================AIT+/进行注释 inoremap <M-/> <Home>// nmap <M-/> <Home>i//<ESC> "=====================复制粘贴 map <C-A> ggVG " 映射全选 ctrl+a map! <C-A> <Esc>ggVGY map <C-c> "+y " 映射复制到系统剪切板 map! <C-c> "+y " 映射复制到系统剪切板 nmap <C-v> "+gp " 映射粘贴 imap <C-v> <Esc>"+gp
4.在环境变量path里面加入vim目录的绝对路径,譬如我的
D:\bysu\Application\vim\
注意:如果path里面还有其他路径,且vim是放在最后面,需要输入分号;然后加上你的路径。如:
;D:\bysu\Application\vim\
5.打开运行(Ctrl+r),输入gvim,回车即可打开gvim编辑器(可以把vim目录的中gvim.exe重命名为vi.exe,然后输入vi,回车即可打开gvim编辑器)
linux的vim配置文件
" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by " the call to :runtime you can find below. If you wish to change any of those " settings,you should do it in this file (/etc/vim/vimrc),since debian.vim " will be overwritten everytime an upgrade of the vim packages is performed. " It is recommended to make changes after sourcing debian.vim since it alters " the value of the 'compatible' option. " This line should not be removed as it ensures that varIoUs options are " properly set to work with the Vim-related packages available in Debian. runtime! debian.vim " Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc. " This happens after /etc/vim/vimrc(.local) are loaded,so it will override " any settings in these files. " If you don't want that to happen,uncomment the below line to prevent " defaults.vim from being loaded. " let g:skip_defaults_vim = 1 " Uncomment the next line to make Vim more Vi-compatible " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous " options,so any other options should be set AFTER setting 'compatible'. "set compatible " Vim5 and later versions support Syntax highlighting. Uncommenting the next " line enables Syntax highlighting by default. Syntax on " If using a dark background within the editing area and Syntax highlighting " turn on this option as well "set background=dark " Uncomment the following to have Vim jump to the last position when " reopening a file "if has("autocmd") " au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif "endif " Uncomment the following to have Vim load indentation rules and plugins " according to the detected filetype. "if has("autocmd") " filetype plugin indent on "endif " The following are commented out as they cause vim to behave a lot " differently from regular Vi. They are highly recommended though. "set showcmd " Show (partial) command in status line. "set showmatch " Show matching brackets. "set ignorecase " Do case insensitive matching "set smartcase " Do smart case matching "set incsearch " Incremental search "set autowrite " Automatically save before commands like :next and :make "set hidden " Hide buffers when they are abandoned "set mouse=a " Enable mouse usage (all modes) " Source a global configuration file if available if filereadable("/etc/vim/vimrc.local") source /etc/vim/vimrc.local endif set shortmess=atI "===============================设置主题 colorscheme darkblue ""===============================设置字体大小 set guifont=Consolas:h12 "h12字体大小,bh12中的b表示黑体 "set guifontwide=Microsoft/ YaHei:h12 ""=================开启语法高亮提示 Syntax on "==============缩进 set cin nu ts=4 sw=4 sts=4 et acd noswapfile nobackup set bs=eol,indent "==================隐藏菜单、工具、滚动条============================ "set guioptions-=m "remove menu bar "set guioptions-=T "remove toolbar "set guioptions-=r "remove right-hand scroll bar ":set guioptions-=L "remove left-hand scroll bar if has("gui_running") au GUIEnter * simalt ~x " 窗口启动时自动最大化 set guioptions-=m " 隐藏菜单栏 set guioptions-=T " 隐藏工具栏 "set guioptions-=L " 隐藏左侧滚动条 "set guioptions-=r " 隐藏右侧滚动条 "set guioptions-=b " 隐藏底部滚动条 "set showtabline=0 " 隐藏Tab栏 endif " ""==========================中文显示乱码 set encoding=utf-8 set fileencodings=utf-8,latin-1 if has("win32") set fileencoding=chinese else set fileencoding=utf-8 endif "解决菜单乱码 "source $VIMRUNTIME/delmenu.vim "source $VIMRUNTIME/menu.vim ""解决consle输出乱码 language messages zh_CN.utf-8 "================================符号自动补全 ""inoremap ' ''<ESC>i ""inoremap " ""<ESC>i ""inoremap ( ()<ESC>i ""inoremap [ []<ESC>i ""inoremap < <><ESC>i ""inoremap { {<CR>}<ESC>O 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 function! ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf "=================================设置跳出自动补全的括号 func SkipPair() let str = getline('.')[col('.')-1]'')]'') if str == ')' || str == ']' || str == '"' || str == "'" || str == '}' return "\<Right>" elseif strpart(getline('.'),col('.')-1)=~'^\s*$' return "\<Tab>" else return "\<C-N>" endif endfunc " 将tab键绑定为跳出括号 inoremap <TAB> <c-r>=SkipPair()<CR> "=====================小写转换大写 inoremap <C-u> <esc>gUiwea ""=====================插入模式移动光标 inoremap <C-k> <Up> inoremap <C-j> <Down> inoremap <C-h> <Left> inoremap <C-l> <Right> inoremap <C-a> <Home> inoremap <C-e> <End> "Rubout word / line and enter insert mode " use <Esc><Right> instead of <C-o> inoremap <C-w> <Esc>dbcl " delete inoremap <C-u> <Esc>d0cl inoremap <M-k> <Esc><Right>C inoremap <C-d> <Esc><Right>s inoremap <C-d> <C-o>de inoremap <M-d> <C-o>de "===================编译java、c、c++、python以及sh脚本 ""=======================按F5进行编译运行windows,Linux下需在运行的命令里面加当前目录./ map <F5> :call CompileRunGcc()<CR> imap <F5> <ESC>:call CompileRunGcc()<CR> func! CompileRunGcc() exec "w" exec "cd %:p:h" if &filetype == 'c' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ -std=c++11 -O2 % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'py' exec "!python %<" elseif &filetype == 'sh' :!./% endif endfunc "======================<F9>gdb调试c或c++ map <F9> :call Debug()<CR> imap <F9> :call Debug()<CR> func! Debug() exec "w" exec "cd %:p:h" if &filetype == 'c' exec "!gcc % -g -o %< -gstabs+" exec "!gdb ./%<" elseif &filetype == 'cpp' exec "!g++ % -g -o %< -gstabs+" exec "!gdb ./%<" endfunc "=====================复制粘贴 map <C-A> ggVG " 映射全选 ctrl+a map! <C-A> <Esc>ggVGY map <C-c> "+y " 映射复制到系统剪切板 map! <C-c> "+y " 映射复制到系统剪切板 "nmap <C-v> "+gp " 映射粘贴 "imap <C-v> <Esc>"+gp
参考:
http://vim.wikia.com/wiki/Hide_toolbar_or_menus_to_see_more_text
https://blog.alswl.com/2012/04/vim-emacs-key-binding/
http://blog.csdn.net/lalor/article/details/7437258
http://www.pythonclub.org/vim/map-basic
https://segmentfault.com/q/1010000004870420
https://www.w3cschool.cn/vim/drcj1pu5.html