Ubuntu下vim的外掛配置方法和問題彙總
1 安裝vim
sudo apt-get install vim
2 建立屬於自己的vim配置檔案.vimrc
vim ~/.vimrc
3 為你的命令列,tmux和vim安裝powerline外掛
3.1 安裝python3-pip
sudo apt-get install python3-pip
3.2 安裝git
sudo apt-get install git
3.3 安裝powerline
pip3 install git+git://github.com/Lokaltog/powerline
3.4 安裝powerline在ubuntu中的字型
#在下載字型 wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf #下載配置檔案 wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf #將字型移動到你的字型目錄下,可能是/usr/share/fonts/ 或者 /usr/local/share/fonts mv PowerlineSymbols.otf /usr/share/fonts/ #更新系統的字型 fc-cache -vf /usr/share/fonts/ #講配置檔案移動到字型配置檔案下 mv 10-powerline-symbols.conf /etc/fonts/conf.d/
3.5 檢視powerline安裝的位置
$ pip3 show powerline-status
>>
Name: powerline-status
Version: 2.7.dev9999-git.b-393ff7119fec64e201abfd2b251b402c7a533b09-
Summary: The ultimate statusline/prompt utility.
Home-page: https://github.com/powerline/powerline
Author: Kim Silkebaekken
Author-email: [email protected]
License: MIT
Location: /home/simileciwh/.local/lib/python3.6/site-packages
Requires:
根據location可知安裝位置為:/home/simileciwh/.local/lib/python3.6/site-packages(記住這個,後面配置很重要)
3.6 為bash配置powerline
vim ~/.bashrc
配置如下:
# Powerline setting
5 export TERM='xterm-256color'
6 powerline-daemon -q
7 POWERLINE_BASH_CONTINUATION=1
8 POWERLINE_BASH_SELECT=1
#第九行為自己的安裝powerline位置/powerline/bindings/bas h/powerline.sh
#注意開頭為--->>.空格/home/simileciwh/.....
9 . /home/simileciwh/.local/lib/python3.6/site-packages/powerline/bindings/bas h/powerline.sh
3.7 為tmux配置powerline
vim ~/.tmux.conf
#source 這一行需要改動,和之前3.6節一樣的方法
source /home/simileciwh/.local/lib/python3.6/site-packages/powerline/bindings/tmux/powerline.conf
set-option -g default-terminal screen-256color
3.8 為vim配置powerline
vim ~/.vimrc
"POWERLINE SETTING
5 set rtp+=/home/simileciwh/.local/lib/python3.6/site-packages/powerline/bindings/vim
6 set laststatus=2
7 set t_Co=256
8 let g:Powerline_symbols= "fancy"
3.9 最終效果如下圖所示:
圖1 terminal的變化
圖2 vim的變化
圖3 執行tmux
圖4 tmux bash的變化
3.10 關於我的tmux,vim,bash的powerline配置檔案在這裡可以下載參考:
link: https://download.csdn.net/download/simileciwh/10752995
4 vim的外掛
給vim安裝外掛有很多方式,我採用的是比較簡單容易的Vundle
下載安裝:https://github.com/VundleVim/Vundle.vim
set nocompatible " be iMproved, required
2 filetype off " required
3
10
11 """"""""""""""""""""""""""""""""""""""
12 " set the runtime path to include Vundle and initialize
13 set rtp+=~/.vim/bundle/Vundle.vim
14
15 call vundle#begin()
16
17
18 "Plugins
19 Plugin 'VundleVim/Vundle.vim'
20 Plugin 'scrooloose/nerdtree'
21 Plugin 'vim-airline/vim-airline-themes'
22
23 "Plugin 'vim-sensible/sensible.vim'
24 "Plugin 'nerdtree/nerdtree.vim'
25
26
27 call vundle#end() " required
28
29 filetype plugin indent on " required
30 "
31 " Brief help
32 " :PluginList - lists configured plugins
33 " :PluginInstall - installs plugins; append `!` to update or just
34 ":PluginUpdate
35 " :PluginSearch foo - searches for foo; append `!` to refresh local cache
36 " :PluginClean - confirms removal of unused plugins; append `!` to
37 "auto-approve removal
這是vundle的大體框架,只需要知道你要安裝的外掛在github上的名字和倉庫的名字即可,只需要在
call vundle#begin()
call vundle#end() 之間的Plugin '倉庫名/外掛名'即可
儲存退出後,
在vim commond-line中輸入:PluginInstall即可,完成下載安裝。
非常容易使用。
5 scrooloose/nerdtree 外掛的使用
效果如下圖所示:
在.vimrc檔案下設定如下,通過快捷建ctrl+f開啟左側Nerd Tree file manager即可。
" Nerd Tree file manager
let g:NERDTreeWinSize=60
map <C-f> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
let NERDTreeQuitOnOpen=1 " closes upon opening a file in nerdtree
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
6 terryma/vim-multiple-cursors 外掛
快捷鍵如下:
- "u can use <C-n>to select the var with samename
- "<C-x> to skip current var
- "<C-p> move to previous var
- "<A-n> sele all var with same name match current line
- "<Esc> to escape
效果如下:
7 python-mode/python-mode 外掛
主要是在vim中配置python的編譯環境
在.vimrc中的設定如下:
"python-mode setting
let g:pymod_python = 'python'
let g:pymode = 1
"include python pkg path
let g:pymode_paths = ['/home/simileciwh/catkin_new/devel/lib/python2.7/dist-packages', '/home/simileciwh/ROS_Library/cartographer/install_isolated/lib/python2.7/dist-packages', '/home/simileciwh/catkin_ws/devel/lib/python2.7/dist-packages', '/opt/ros/melodic/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/simileciwh/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/wx-3.0-gtk3']
let g:pymode_options = 1
let g:pymode_options_colorcolumn = 1
let g:pymode_quickfix_minheight = 3
let g:pymode_quickfix_maxheight = 6
let g:pymode_indent = 1
let g:pymode_folding = 0
let g:pymode_motion = 1
let g:pymode_doc = 1
let g:pymode_doc_bind = 'K'
"let g:pymode_virtualenv = 1
"run python with ";+r"
let g:pymode_run = 1
"bind keys of run
let g:pymode_run_bind = '<leader>r'
" set breakpoin with ";+b"
let g:pymode_breakpoint = 1
"bind keys of breakpoint
let g:pymode_breakpoint_bind = '<leader>b'
" mannually set breakpoint cmd
let g:pymode_breakpoint_cmd = ''
" turn on code checking
let g:pymode_lint = 1
"check code on every save if file has been modified
let g:pymode_link_on_write = 1
"check code when editing
let g:pymode_lint_on_fly = 0
"show error message if cursor placed st the error line
let g:pymode_lint_message = 1
"default code checkers
let g:pymode_lint_checkers = ['pyflakes','pep8','mccabe']
"skip errors and warnings
"let g:pymode_lint_ignore = ["W"]
"go to definition with ";+g"
"let g:pymode_rope_goto_definition_bind = '<leader>g'
" turn on pymode syntax
let g:pymode_syntax = 1
"enable all python highlights
let g:pymode_syntax_all = 1
let g:pymode_syntax_print_as_function = 0
"turn on code completion support
let g:pymode_rope_completion = 1
let g:pymode_rope_completion_on_dot = 1
"keymap for autocomplete
let g:pymode_rope_completion_bind = '<C-Space>'