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
vim開發配置