vim开发配置

需求:使用vim开发python,可以进行简单配置

cd 到用户宿主目录下
vim .vimrc 粘贴以下内容:

版本一:

set encoding=utf-8
"去掉vi的一致性"
set nocompatible
"显示行号"
set number
set nobackup
set nowb
set noswapfile
set noundofile
set showcmd
" 隐藏滚动条"
"set guioptions-=r
"set guioptions-=L
"set guioptions-=b
"隐藏顶部标签栏"
"set showtabline=0
"设置字体"
"set guifont=Monaco:h13
syntax on "开启语法高亮"
"let g:solarized_termcolors=256 "solarized主题设置在终端下的设置"
set background=dark "设置背景色"
"colorscheme ron
"colorscheme peaksea
set nowrap "设置不折行"
set fileformat=unix "设置以unix的格式保存文件"
set cindent "设置C样式的缩进格式"
set tabstop=4 "设置table长度"
set softtabstop=4
set noexpandtab
set shiftwidth=4 "同上"
set showmatch "显示匹配的括号"
set scrolloff=5 "距离顶部和底部5行"
set laststatus=2 "命令行为两行"
set fenc=utf-8 "文件编码"
set backspace=2
set mouse=c "启用鼠标"
set selection=exclusive
set selectmode=mouse,key
"set matchtime=5
set ignorecase "忽略大小写"
"set incsearch
set hlsearch "高亮搜索项"
"set noexpandtab "不允许扩展table"
set whichwrap+=<,>,h,l
set autoread
"set cursorline "突出显示当前行"
"set cursorcolumn "突出显示当前列"

 
 

" C++ part
set exrc
set secure

 
 

augroup project
autocmd!
autocmd BufRead,BufNewFile *.h,*.c set filetype=c.doxygen
autocmd BufRead,BufNewFile *.hpp,*.cpp set filetype=cpp.doxygen
augroup END

 
 

set makeprg=make\ -C\ -j64
nnoremap <F3> :make!<cr>

 
 

"Vundle
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'Lokaltog/vim-powerline'
Plugin 'scrooloose/nerdtree'
Plugin 'Yggdroot/indentLine'
Plugin 'jiangmiao/auto-pairs'
Plugin 'tell-k/vim-autopep8'
Plugin 'scrooloose/nerdcommenter'
call vundle#end()
filetype plugin indent on

 
 

"按F5运行python"
map <F5> :Autopep8<CR> :w<CR> :call RunPython()<CR>
function RunPython()
let mp = &makeprg
let ef = &errorformat
let exeFile = expand("%:t")
setlocal makeprg=python\ -u
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
silent make %
copen
let &makeprg = mp
let &errorformat = ef
endfunction

 
 

"按F9运行python调试"
map <F9> :Autopep8<CR> :w<CR> :call RunPythonDebug()<CR>
function RunPythonDebug()
let mp = &makeprg
let ef = &errorformat
let exeFile = expand("%:t")
setlocal makeprg=python\ -m\ pdb
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
silent make %
copen
let &makeprg = mp
let &errorformat = ef
endfunction

 
 

"YouCompleteMe
"默认配置文件路径"
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py'
"打开vim时不再询问是否加载ycm_extra_conf.py配置"
let g:ycm_confirm_extra_conf=0
set completeopt=longest,menu
"python解释器路径"
let g:ycm_path_to_python_interpreter='/usr/bin/python'
"是否开启语义补全"
let g:ycm_seed_identifiers_with_syntax=1
"是否在注释中也开启补全"
let g:ycm_complete_in_comments=1
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"开始补全的字符数"
let g:ycm_min_num_of_chars_for_completion=2
"补全后自动关机预览窗口"
let g:ycm_autoclose_preview_window_after_completion=1
" 禁止缓存匹配项,每次都重新生成匹配项"
let g:ycm_cache_omnifunc=0
"字符串中也开启补全"
let g:ycm_complete_in_strings = 1
"离开插入模式后自动关闭预览窗口"
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
"回车即选中当前项"
"inoremap <expr> <CR> pumvisible() ? '<C-y>' : '\<CR>'
"上下左右键行为"
inoremap <expr> <Down> pumvisible() ? '\<C-n>' : '\<Down>'
inoremap <expr> <Up> pumvisible() ? '\<C-p>' : '\<Up>'
inoremap <expr> <PageDown> pumvisible() ? '\<PageDown>\<C-p>\<C-n>' : '\<PageDown>'
inoremap <expr> <PageUp> pumvisible() ? '\<PageUp>\<C-p>\<C-n>' : '\<PageUp>'
"YouCompleteMe clang settings
let g:clang_format#style_options = {
\ "AccessModifierOffset" : -4,
\ "AllowShortIfStatementsOnASingleLine" : "true",
\ "AlwaysBreakTemplateDeclarations" : "true",
\ "Standard" : "C++11"}
let g:clang_format#auto_format=1

 
 

"Nerd tree
"F2开启和关闭树"
map <F2> :NERDTreeToggle<CR>
let NERDTreeChDirMode=1
"显示书签"
let NERDTreeShowBookmarks=1
"设置忽略文件类型"
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
"窗口大小"
let NERDTreeWinSize=25

 
 

"缩进指示线"
let g:indentLine_char='┆'
let g:indentLine_enabled = 1
"autopep8设置"
let g:autopep8_disable_show_diff=1
autocmd Filetype python noremap <buffer> <F8> :call Autopep8()<CR>

 
 

map <F4> <leader>ci <CR>

版本二:

" 高亮当前行
set cursorline
" 将 TAB 设为四个空格的宽度
set tabstop=4
" 自动缩进
set autoindent
" 自动缩进四个空格
set shiftwidth=4
" 使用空格代替 TAB
set expandtab
" 定义 PythonHeader() 函数用于自动插入 Python 文件头
function PythonHeader()
call setline(1, "# -*- coding: utf-8 -*-")
normal G
normal o
normal o
endfunc
" 新建 py 结尾的文件时自动调用 PythonHeader() 函数
autocmd BufNewFile *.py call PythonHeader()
" 按下 F5 自动执行当前 Python 文件
map <F5> :!clear ;python % <CR>


版本三:

"去掉vi的一致性"
set nocompatible
"显示行号"
set number
"隐藏滚动条"
set guioptions-=r
set guioptions-=L
set guioptions-=b
"隐藏顶部标签栏"
set showtabline=0
"设置字体"
set guifont=Monaco:h13
syntax on "开启语法高亮"
let g:solarized_termcolors=256 "solarized主题设置在终端下的设置"
set background=dark "设置背景色"
"colorscheme solarized"
set nowrap "设置不折行"
set fileformat=unix "设置以unix的格式保存文件"
set cindent "设置C样式的缩进格式"
set tabstop=4 "设置table长度"
set shiftwidth=4 "同上"
set showmatch "显示匹配的括号"
set scrolloff=5 "距离顶部和底部5行"
set laststatus=2 "命令行为两行"
set fenc=utf-8 "文件编码"
set backspace=2
set mouse=a "启用鼠标"
set selection=exclusive
set selectmode=mouse,key
set matchtime=5
set ignorecase "忽略大小写"
set incsearch
set hlsearch "高亮搜索项"
set noexpandtab "不允许扩展table"
set whichwrap+=<,>,h,l
set autoread
set cursorline "突出显示当前行"
set cursorcolumn "突出显示当前列"
"按F5运行python"
map <F5> :Autopep8<CR> :w<CR> :call RunPython()<CR>
function RunPython()
let mp = &makeprg
let ef = &errorformat
let exeFile = expand("%:t")
setlocal makeprg=python\ -u
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
silent make %
copen
let &makeprg = mp
let &errorformat = ef
endfunction

猜你喜欢

转载自www.cnblogs.com/fuhai0815/p/9443916.html