树莓派--【vim配置】

【vim配置】

1.效果展示

此配置具有状态栏、自动补全python、C/C++代码、目录树、Taglist、ctrlp搜索等…

树莓派--【vim配置】_第1张图片

树莓派--【vim配置】_第2张图片

2.插件管理

2.1安装bundle

安装Git(因为下面我们选择的插件管理器需要使用到它)
安装其他插件前首先需要选择一个Vim插件管理器,我这里选择的是Vundle,Vundle的工作过程中需要通过Git自动从远程创库同步插件安装包到本地仓库(Vundle的默认本地仓库位置是~/.vim/bundle/) 通过Git下载Vundle安装包:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

安装好后,如果需要安装新插件。进入vim:

:PluginInstall

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WIAJPtf1-1578314823800)(https://i.loli.net/2020/01/06/sxEFuINZm94vwye.png)]

当完成之后,在.vim 在~/.vimrc中添加Vundle的配置内容:

set nocompatible              " be iMproved, required
filetype on                  " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
	"插件安装在此处
call vundle#end()            " required

2.2安装插件

首先,在主目录下新建.vimrc配置文件。命令为:vim .vimrc 。 然后在命令模式下输入 :wq。保存空白文件退出即可。

  • pydiction自动补全插件

    自动补全插件Pydiction是一款好用的Vim Python主动补全插件,首要便利用于在vim中运用tab键主动补全Python代码,支撑输入部分Python关键字、模块名、特点和方法名等,兼容规范的、自定义的和第三方模块和包。

    安装Pydiction:

    cd ~/.vim/bundle
    
    git clone https://github.com/rkulla/pydiction.git
    

    若此步遇到 -bash: git: command not found,没有git命令。 sudo apt-get install git安装即可

    配置Pydiction:

    cp -r ~/.vim/bundle/pydiction/after/ ~/.vim
    
    vim ~/.vimrc
    

    在.vimrc文件添加如下配置:

    filetype plugin on
    let g:pydiction_location = '~/.vim/tools/pydiction/complete-dict'#complete-dict所在目录
    let g:pydiction_menu_height = 3
    
  • vim-airline和vim-airline-themes状态栏插件

    在.vimrc文件添加如下配置:

     Plugin 'vim-airline/vim-airline'
     Plugin 'vim-airline/vim-airline-themes' 
    

    关于airline配置如下:

    set t_Co=256      "在windows中用xshell连接打开vim可以显示色彩
    let g:airline#extensions#tabline#enabled = 1   " 是否打开tabline
    "这个是安装字体后 必须设置此项" 
    let g:airline_powerline_fonts = 1
    set laststatus=2  "永远显示状态栏
    let g:airline_theme='bubblegum' "选择主题
    let g:airline#extensions#tabline#enabled=1    "Smarter tab line: 显示窗口tab和buffer
    "let g:airline#extensions#tabline#left_sep = ' '  "separater
    "let g:airline#extensions#tabline#left_alt_sep = '|'  "separater
    "let g:airline#extensions#tabline#formatter = 'default'  "formater
    let g:airline_left_sep = '▶'
    let g:airline_left_alt_sep = '❯'
    let g:airline_right_sep = '◀'
    
  • nerdtree目录树插件

    在.vimrc文件添加如下配置:

    Plugin 'preservim/nerdtree'
    
    
    " 打开vim时,自动打开NERDTree
    autocmd vimenter * NERDTree 
    " 设置NerdTree打开的快捷键,可自行更改
    map <F2> :NERDTreeMirror<CR>
    map <F2> :NERDTreeToggle<CR>
    
    ""当NERDTree为剩下的唯一窗口时自动关闭
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
    ""修改树的显示图标
    let g:NERDTreeDirArrowExpandable = '+'
    let g:NERDTreeDirArrowCollapsible = '-'
    ""窗口位置
    let g:NERDTreeWinPos='left'
    ""窗口尺寸
    let g:NERDTreeSize=30
    ""窗口是否显示行号
    let g:NERDTreeShowLineNumbers=1
    ""不显示隐藏文件
    let g:NERDTreeHidden=0
    
  • taglist插件

    Plugin 'taglist.vim'
    
    let Tlist_Auto_Hight_tag =1  
    let Tlist_Auto_Open=0  
    let Tlist_Auto_Update=1  
    let Tlist_Display_Tag_Scope=1  
    let Tlist_Exit_OnlyWindow=1  
    let Tlist_Enable_Dold_Column=1  
    let Tlist_File_Fold_Auto_Close=1  
    let Tlist_Show_One_File=1  
    let Tlist_Use_Right_Window=1  
    let Tlist_Use_SingleClick=1  
    nnoremap <silent> <F8> :TlistToggle<CR>
    

3.配色方案

在.vim下新建color文件夹,命令为:

mkdir ~/.vim/color
cd ~/.vim/color

在color文件夹下新建molokai.vim 。 拷贝如下代码:

" Vim color file"

hi clear

set background=dark
if version > 580
    " no guarantees for version 5.8 and below, but this makes it stop
    " complaining
    hi clear
    if exists("syntax_on")
        syntax reset
    endif
endif
let g:colors_name="molokai"

if exists("g:molokai_original")
    let s:molokai_original = g:molokai_original
else
    let s:molokai_original = 0
endif


hi Boolean         guifg=#AE81FF
hi Character       guifg=#E6DB74
hi Number          guifg=#AE81FF
hi String          guifg=#E6DB74
hi Conditional     guifg=#F92672               gui=bold
hi Constant        guifg=#AE81FF               gui=bold
hi Cursor          guifg=#000000 guibg=#F8F8F0
hi Debug           guifg=#BCA3A3               gui=bold
hi Define          guifg=#66D9EF
hi Delimiter       guifg=#8F8F8F
hi DiffAdd                       guibg=#13354A
hi DiffChange      guifg=#89807D guibg=#4C4745
hi DiffDelete      guifg=#960050 guibg=#1E0010
hi DiffText                      guibg=#4C4745 gui=italic,bold

hi Directory       guifg=#A6E22E               gui=bold
hi Error           guifg=#960050 guibg=#1E0010
hi ErrorMsg        guifg=#F92672 guibg=#232526 gui=bold
hi Exception       guifg=#A6E22E               gui=bold
hi Float           guifg=#AE81FF
hi FoldColumn      guifg=#465457 guibg=#000000
hi Folded          guifg=#465457 guibg=#000000
hi Function        guifg=#A6E22E               gui=bold
hi Identifier      guifg=#FD971F
hi Ignore          guifg=#808080 guibg=bg
hi IncSearch       guifg=#C4BE89 guibg=#000000

hi Keyword         guifg=#F92672               gui=bold
hi Label           guifg=#E6DB74               gui=none
hi Macro           guifg=#C4BE89               gui=italic
hi SpecialKey      guifg=#66D9EF               gui=italic

hi MatchParen      guifg=#000000 guibg=#FD971F gui=bold
hi ModeMsg         guifg=#E6DB74
hi MoreMsg         guifg=#E6DB74
hi Operator        guifg=#F92672

" complete menu
hi Pmenu           guifg=#66D9EF guibg=#000000
hi PmenuSel                      guibg=#808080
hi PmenuSbar                     guibg=#080808
hi PmenuThumb      guifg=#66D9EF

hi PreCondit       guifg=#A6E22E               gui=bold
hi PreProc         guifg=#A6E22E
hi Question        guifg=#66D9EF
hi Repeat          guifg=#F92672               gui=bold
hi Search          guifg=#FFFFFF guibg=#455354
" marks column
hi SignColumn      guifg=#A6E22E guibg=#232526
hi SpecialChar     guifg=#F92672               gui=bold
hi SpecialComment  guifg=#465457               gui=bold
hi Special         guifg=#66D9EF guibg=bg      gui=italic
hi SpecialKey      guifg=#888A85               gui=italic
if has("spell")
    hi SpellBad    guisp=#FF0000 gui=undercurl
    hi SpellCap    guisp=#7070F0 gui=undercurl
    hi SpellLocal  guisp=#70F0F0 gui=undercurl
    hi SpellRare   guisp=#FFFFFF gui=undercurl
endif
hi Statement       guifg=#F92672               gui=bold
hi StatusLine      guifg=#455354 guibg=fg
hi StatusLineNC    guifg=#808080 guibg=#080808
hi StorageClass    guifg=#FD971F               gui=italic
hi Structure       guifg=#66D9EF
hi Tag             guifg=#F92672               gui=italic
hi Title           guifg=#ef5939
hi Todo            guifg=#FFFFFF guibg=bg      gui=bold

hi Typedef         guifg=#66D9EF
hi Type            guifg=#66D9EF               gui=none
hi Underlined      guifg=#808080               gui=underline

hi VertSplit       guifg=#808080 guibg=#080808 gui=bold
hi VisualNOS                     guibg=#403D3D
hi Visual                        guibg=#403D3D
hi WarningMsg      guifg=#FFFFFF guibg=#333333 gui=bold
hi WildMenu        guifg=#66D9EF guibg=#000000

if s:molokai_original == 1
   hi Normal          guifg=#F8F8F2 guibg=#272822
   hi Comment         guifg=#75715E
   hi CursorLine                    guibg=#3E3D32
   hi CursorColumn                  guibg=#3E3D32
   hi LineNr          guifg=#BCBCBC guibg=#3B3A32
   hi NonText         guifg=#BCBCBC guibg=#3B3A32
else
   hi Normal          guifg=#F8F8F2 guibg=#1B1D1E
   hi Comment         guifg=#465457
   hi CursorLine                    guibg=#293739
   hi CursorColumn                  guibg=#293739
   hi LineNr          guifg=#BCBCBC guibg=#232526
   hi NonText         guifg=#BCBCBC guibg=#232526
end

"
" Support for 256-color terminal
"
if &t_Co > 255
   hi Boolean         ctermfg=135
   hi Character       ctermfg=144
   hi Number          ctermfg=135
   hi String          ctermfg=144
   hi Conditional     ctermfg=161               cterm=bold
   hi Constant        ctermfg=135               cterm=bold
   hi Cursor          ctermfg=16  ctermbg=253
   hi Debug           ctermfg=225               cterm=bold
   hi Define          ctermfg=81                cterm=bold
   hi Delimiter       ctermfg=241

   hi DiffAdd                     ctermbg=24
   hi DiffChange      ctermfg=181 ctermbg=239
   hi DiffDelete      ctermfg=162 ctermbg=53
   hi DiffText                    ctermbg=102 cterm=bold

   hi Directory       ctermfg=118               cterm=bold
   hi Error           ctermfg=219 ctermbg=89
   hi ErrorMsg        ctermfg=199 ctermbg=16    cterm=bold
   hi Exception       ctermfg=118               cterm=bold
   hi Float           ctermfg=135
   hi FoldColumn      ctermfg=67  ctermbg=16
   hi Folded          ctermfg=67  ctermbg=16
   hi Function        ctermfg=118
   hi Identifier      ctermfg=208
   hi Ignore          ctermfg=244 ctermbg=232
   hi IncSearch       ctermfg=193 ctermbg=16

   hi Keyword         ctermfg=161               cterm=bold
   hi Label           ctermfg=229               cterm=none
   hi Macro           ctermfg=193
   hi SpecialKey      ctermfg=81

   hi MatchParen      ctermfg=16  ctermbg=208 cterm=bold
   hi ModeMsg         ctermfg=229
   hi MoreMsg         ctermfg=229
   hi Operator        ctermfg=161

   " complete menu
   hi Pmenu           ctermfg=81  ctermbg=16
   hi PmenuSel                    ctermbg=244
   hi PmenuSbar                   ctermbg=232
   hi PmenuThumb      ctermfg=81

   hi PreCondit       ctermfg=118               cterm=bold
   hi PreProc         ctermfg=118
   hi Question        ctermfg=81
   hi Repeat          ctermfg=161               cterm=bold
   hi Search          ctermfg=253 ctermbg=66

   " marks column
   hi SignColumn      ctermfg=118" ctermbg=235
   hi SpecialChar     ctermfg=161               cterm=bold
   hi SpecialComment  ctermfg=245               cterm=bold
   hi Special         ctermfg=81  ctermbg=232
   hi SpecialKey      ctermfg=245

   hi Statement       ctermfg=161               cterm=bold
   hi StatusLine      ctermfg=238 ctermbg=253
   hi StatusLineNC    ctermfg=244 ctermbg=232
   hi StorageClass    ctermfg=208
   hi Structure       ctermfg=81
   hi Tag             ctermfg=161
   hi Title           ctermfg=166
   hi Todo            ctermfg=231 ctermbg=232   cterm=bold

   hi Typedef         ctermfg=81
   hi Type            ctermfg=150                cterm=bold "/*数据类型*/
   hi Underlined      ctermfg=244               cterm=underline

   hi VertSplit       ctermfg=244 ctermbg=232   cterm=bold
   hi VisualNOS                   ctermbg=238
   hi Visual                      ctermbg=235
   hi WarningMsg      ctermfg=231 ctermbg=238   cterm=bold
   hi WildMenu        ctermfg=81  ctermbg=16


   hi Normal          ctermfg=252                "基本色
   hi Comment         ctermfg=59
  " hi CursorLine                  ctermbg=244   cterm=none
   hi CursorColumn                ctermbg=244
   hi LineNr          ctermfg=250     "左边行数列
   hi NonText         ctermfg=250     "空白区域
end

​ 在.vimrc中添加如下配置文件:

" Vim color file
set background=dark
set t_Co=256 "告知molokai,终端支持256色
colorscheme molokai 

4.配置文件

完整的配置文件如下:

"使用 utf-8 编码
set encoding=utf-8
"设置行号"
set number
"语法高亮"
syntax on
"底部显示,当前处于模式"
set showmode
"开启文件类型检查
filetype indent on
"打开粘帖模式
set paste
"关闭粘帖模式
"set nopaste
"F3快捷键
set pastetoggle=<F3>
"当前行高亮
set cursorline
"显示状态栏
set laststatus=2
"不创建交换文件
set noswapfile
set hlsearch
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Enable folding
set foldmethod=indent
set foldlevel=99
" 通过空格键快速打开和关闭折叠
nnoremap <space> za
au BufNewFile,BufRead *.py
    \ set tabstop=4 |
    \ set softtabstop=4 |
    \ set shiftwidth=4 |
    \ set textwidth=79 |
    \ set expandtab |
    \ set autoindent |
    \ set fileformat=unix |

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
	Plugin 'VundleVim/Vundle.vim'
	Plugin 'Valloric/YouCompleteMe'
	Plugin 'davidhalter/jedi-vim'
	Plugin 'vim-airline/vim-airline'
	Plugin 'vim-airline/vim-airline-themes'	
	Plugin 'tomasr/molokai'	
	Plugin 'preservim/nerdtree'
	Plugin 'taglist.vim'
	Plugin 'nathanaelkane/vim-indent-guides' 
	Plugin 'octol/vim-cpp-enhanced-highlight'	
	Plugin 'ctrlpvim/ctrlp.vim'
call vundle#end()            " 必须

let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/.ycm_extra_conf.py'
let g:pydiction_location = '~/.vim/bundle/pydiction/complete-dict'
let g:pydiction_menu_height = 3
"===============================Jedi==================================
"if has('python3')
"let g:loaded_youcompleteme = 1 " 判断如果是python3的话,就禁用ycmd。
"let g:jedi#force_py_version = 3
"let g:pymode_python = 'python3'
"n 'taglist.vim'endif
"===============================Jedi===================================
let Tlist_Auto_Hight_tag =1  
let Tlist_Auto_Open=0  
let Tlist_Auto_Update=1  
let Tlist_Display_Tag_Scope=1  
let Tlist_Exit_OnlyWindow=1  
let Tlist_Enable_Dold_Column=1  
let Tlist_File_Fold_Auto_Close=1  
let Tlist_Show_One_File=1  
let Tlist_Use_Right_Window=1  
let Tlist_Use_SingleClick=1  
nnoremap <silent> <F8> :TlistToggle<CR>
   
autocmd FileType python set omnifunc=pythoncomplete#Complete  
autocmd FileType javascrīpt set omnifunc=javascriptcomplete#CompleteJS  
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags  
autocmd FileType css set omnifunc=csscomplete#CompleteCSS  
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags  
autocmd FileType php set omnifunc=phpcomplete#CompletePHP  
autocmd FileType c set omnifunc=ccomplete#Complete  


set t_Co=256      "在windows中用xshell连接打开vim可以显示色彩
let g:airline#extensions#tabline#enabled = 1   " 是否打开tabline
"这个是安装字体后 必须设置此项" 
let g:airline_powerline_fonts = 1
set laststatus=2  "永远显示状态栏
let g:airline_theme='bubblegum' "选择主题
let g:airline#extensions#tabline#enabled=1    "Smarter tab line: 显示窗口tab和buffer
"let g:airline#extensions#tabline#left_sep = ' '  "separater
"let g:airline#extensions#tabline#left_alt_sep = '|'  "separater
"let g:airline#extensions#tabline#formatter = 'default'  "formater
let g:airline_left_sep = '▶'
let g:airline_left_alt_sep = '❯'
let g:airline_right_sep = '◀'

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType python set omnifunc=pythoncomplete#Complete
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件标题""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自动插入文件头 
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.py,*.java exec ":call SetTitle()" 
""定义函数SetTitle,自动插入文件头 
func SetTitle() 
    "如果文件类型为.sh文件 
    if &filetype == 'sh' 
        call setline(1,"\#!/bin/bash") 
        call append(line("."),"\#########################################################################") 
        call append(line(".")+1, "\# File Name: ".expand("%"))
        call append(line(".")+2, "\# Author : zhouzhou")
        call append(line(".")+3, "\# QQ : 2867283770")
        call append(line(".")+4, "\# Email:[email protected]")
        call append(line(".")+5, "\# Created Time: ".strftime("%c"))
        call append(line(".")+6, "\#########################################################################")
        call append(line(".")+7, "")

    elseif &filetype == 'python'
        call setline(1,"\#!/usr/bin/env python")
	call append(line('.'),"#-*-coding:UTF-8 -*-n")
        call append(line(".")+1,"\#########################################################################")
        call append(line(".")+2, "\# File Name: ".expand("%"))
        call append(line(".")+3, "\# Author :zhouzhou")
        call append(line(".")+4, "\# QQ : 2867283770")
        call append(line(".")+5, "\# Email:[email protected]")
        call append(line(".")+6, "\# Created Time: ".strftime("%c"))
        call append(line(".")+7, "\#########################################################################")
        call append(line(".")+8, "")

    else
        call setline(1, "/*************************************************************************") 
        call append(line("."), "    > File Name: ".expand("%")) 
        call append(line(".")+1, "\# File Name: ".expand("%"))
        call append(line(".")+2, "\# Author : zhouzhou  ")
        call append(line(".")+3, "\# QQ : 2867283770")
        call append(line(".")+4, "\# Email:[email protected]")
        call append(line(".")+5, "\# Created Time: ".strftime("%c"))
        call append(line(".")+6, " ************************************************************************/") 
        call append(line(".")+7, "")

    endif
    if &filetype == 'cpp'
        call append(line(".")+8, "#include")
        call append(line(".")+9, "using namespace std;")
        call append(line(".")+10, "")
    endif
    if &filetype == 'c'
        call append(line(".")+8, "#include")
        call append(line(".")+9,"")
    endif
    "新建文件后,自动定位到文件末尾
endfunc 
autocmd BufNewFile * normal G




" 打开vim时,自动打开NERDTree
autocmd vimenter * NERDTree 
" 设置NerdTree打开的快捷键,可自行更改
map  :NERDTreeMirror
map  :NERDTreeToggle

""当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
""修改树的显示图标
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'
""窗口位置
let g:NERDTreeWinPos='left'
""窗口尺寸
let g:NERDTreeSize=30
""窗口是否显示行号
let g:NERDTreeShowLineNumbers=1
""不显示隐藏文件
let g:NERDTreeHidden=0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""vim-cpp-enhanced-highlight""""""""""""""""""""""""""""
let g:cpp_class_scope_highlight = 1
let g:cpp_member_variable_highlight = 1
let g:cpp_class_decl_highlight = 1
let g:cpp_posix_standard = 1
let g:cpp_experimental_simple_template_highlight = 1
let g:cpp_experimental_template_highlight = 1
let g:cpp_concepts_highlight = 1
let g:cpp_no_function_highlight = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""



""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Vim color file
set background=dark
set t_Co=256 "告知molokai,终端支持256色。
colorscheme molokai 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 let g:indent_guides_enable_on_vim_startup = 1 "添加行,vim启动时启用
 let g:indent_guides_start_level = 1           "添加行,开始显示对齐线的缩进级别
let g:indent_guides_guide_size = 1           "添加行,对齐线的宽度,(1字符)
 let g:indent_guides_tab_guides = 0            "添加行,对tab对齐的禁用


你可能感兴趣的:(树莓派--【vim配置】)