天天看點

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

二,插件安裝

1,安裝
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# 若提醒目錄不存在請先自行建立目錄
# 在.vimrc檔案中添加以下配置
# 版本一中已包含此項内容
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin '你的插件'
call vundle#end()
filetype plugin indent on
2,添加完.vimrc的的配置後,儲存退出,重新打開vim輸入:
:PluginInstall
      

  3,當看到指令行出現Done!就代表所有插件安裝完成啦!

  youcompleteme 插件極難安裝,需要等很久!!!

  4,可以從git下載下傳源碼編譯,python最高3.4,本次編譯耗費不少時間,最好降低python版本為2.7.5後成功。

  

  

  編譯參考文章:https://www.v2ex.com/t/341751