Vim基础设置

Vim配置

1. 安装Vundle

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

2. 创建.vimrc

在根目录下创建.vimrc文件,分享一下我的Vim配置

vim .vimrc
"************************************  Plug  *********************************
set nocompatible              " be iMproved, required
filetype off                  " required
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'plasticboy/vim-markdown'
Plugin 'gmarik/vundle'
Plugin 'L9'
Plugin 'scrooloose/nerdtree'
Plugin 'Valloric/YouCompleteMe'
Plugin 'ctrlp.vim'
Plugin 'FuzzyFinder'
Plugin 'taku-o/vim-copypath'
Plugin 'msanders/snipmate.vim'
Plugin 'mhinz/vim-signify'
Plugin 'fatih/vim-go'
Plugin 'bumaociyuan/vim-swift'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'rust-lang/rust.vim'
Plugin 'KeitaNakamura/neodark.vim'
Plugin 'morhetz/gruvbox'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
call vundle#end()
filetype plugin on

"************************************  Setting  *********************************
set nocompatible
syntax on
set autoread

autocmd! bufwritepost vimrc source ~/vimrc

"Go
set rtp+=/usr/local/go/misc/vim
map <C-D-i> <C-x><C-o>
"autocmd FileType go set omnifunc=gocomplete#Complete
augroup filetypedetect
  au! BufRead,BufNewFile *.go setf go
augroup END

"Cache
set hidden
set backup                       " make backup file
set backupdir=~/.cache/vim,/tmp  " where to put backup file
set directory=~/.cache/vim,/tmp  " directory is the directory for temp file
set noswapfile

"indent settings
" set ai ts=2 sw=2  "autoindent shiftwidth softtabstop
" set smarttab
" set expandtab
" set smartindent

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

set noerrorbells
set novisualbell

" store lots of :cmdline history
set history=1000

" display tabs and trailing spaces
"set list
"set listchars=tab:▷⋅,trail:⋅,nbsp:⋅

" 设置编码
set enc=utf-8
" 设置文件编码
set fenc=utf-8

color slate

"show number
set nu

"tab
set guitablabel=%m%t"
set shiftwidth=4
set softtabstop=4
set tabstop=4
set expandtab
set autoindent
%retab

"UI
set guioptions-=T
set guifont=Monaco:h15
map <silent><leader>s :set guioptions+=b<CR>
set scrolloff=3     "光标与顶部和底部始终保持一定行数
set hlsearch        "在查找时,高亮显示全部匹配字符

" vimwiki
let g:vimwiki_use_mouse = 1
let g:vimwiki_list = [{'path': '/Users/xichao/Documents/vimwiki/', 'path_html': '/Users/xichao/Documents/vimwiki/html/', 'html_header': '/Users/xichao/Documents/vimwiki/template/header.tpl',}]

"Other
set nowrap

let g:evervim_devtoken = 'S=s6:U=d393f:E=143b89c65dc:C=13c60eb39dc:P=1cd:A=en-devtoken:H=8639537119120574f37051c5661a3c88'


"************************************  Hotkey  *********************************
let mapleader=";"
" Open vimrc
map <silent> <leader>rc :tabnew ~/.vimrc<CR>
map <silent> <leader>wk :cd ~/Documents/vimwiki<CR>
map <silent><leader>d :q<CR>

"Tab
map <C-T> :tabnew<CR>
map <C-T> :tabnew<CR>
map J :tabnext<CR>
map F :tabpre<CR>
map <D-1> 1gt
map <D-2> 2gt
map <D-3> 3gt
map <D-4> 4gt
map <D-5> 5gt
map <D-6> 6gt
map <D-7> 7gt
map <D-8> 8gt
map <D-9> 9gt
map <D-0> 10gt

" Switch Window
map <silent>m <C-w><C-w>

"Comment
map <D-/> <c-_><c-_>
map <D-.> <c-_><space><%# %><CR>

map <silent>zo zc

"Swich Project
map <silent><leader>1 :cd ~/Codes/Rails/qor<CR>:set title titlestring=Qor<CR>
map <silent><leader>2 :cd ~/Codes/Rails/lacoste<CR>:set title titlestring=Lacoste<CR>
map <silent><leader>3 :cd ~/Codes/Rails/onitsukatiger<CR>:set title titlestring=OT<CR>
map <silent><leader>4 :cd ~/Documents/vimwiki<CR>:set title titlestring=Note<CR>
map <silent><leader>5 :cd /Users/xichao/Codes/go/own/src/bitbucket.org/sunfmin/fanliwuxian<CR>:set title titlestring=Fanliwuxian<CR>

"************************************  Plug Configure  *********************************
"ctrlp
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.jpg,*.jpeg,*.srt,*.ass,*.git     " MacOSX/Linux
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn|png|jpg|jpeg|srt|ass)$'
"let g:ctrlp_custom_ignore = {
"  \ 'dir':  '\v[\/]\.(git|hg|svn)$',
"  \ 'file': '\v\.(exe|so|dll)$',
"  \ 'link': 'some_bad_symbolic_links',
"  \ }
let g:ctrlp_match_window_bottom = 0
"map <D-space> :CtrlP<CR>

" NERDTree
map <leader>o :NERDTreeToggle<CR>

"proj-vim
"Need to make 'File->Print' use other hotkey
map <D-p> :ProjOpen<CR>

"copypath
map <D-C> :CopyPath<CR>

"************************************  Function  *********************************
" reload Snippet
function! ReloadSnippets( snippets_dir, ft )
  if strlen( a:ft ) == 0
    let filetype = "_"
  else
    let filetype = a:ft
  endif

  call ResetSnippets()
  call GetSnippets( a:snippets_dir, filetype )
endfunction
nmap <leader>s :call ReloadSnippets('/Users/xichao/.vim/bundle/snipMate/snippets', &filetype)<CR>

"Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
  " Preparation: save last search, and cursor position.
  let _s=@/
  let l = line(".")
  let c = col(".")
  " Do the business:
  %s/\s\+$//e
  " Clean up: restore previous search history, and cursor position
  let @/=_s
  call cursor(l, c)
endfunction
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()

"************************************  Go  *********************************
"set rtp+=$GOROOT/misc/vim

map <silent><leader>f :Import fmt<CR>
map <silent><leader>F :Drop fmt<CR>
imap <D-Space> <c-x><c-o>

set nobackup
set nowritebackup


"******************************** neocomplcache *****************************
let g:neocomplcache_enable_at_startup = 1
let g:neocomplcache_enable_smart_case = 1
let g:neocomplcache_enable_camel_case_completion = 1
let g:neocomplcache_enable_underbar_completion = 1
let g:neocomplcache_auto_completion_start_length = 2
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'
let g:neocomplcache_max_list = 25
let g:neocomplcache_enable_auto_select = 1
let g:neocomplcache_enable_fuzzy_completion = 1
let g:neocomplcache_fuzzy_completion_start_length = 2
let g:neocomplcache_enable_cursor_hold_i = 0
let g:neocomplcache_cursor_hold_i_time = 300
let g:neocomplcache_enable_insert_char_pre = 0
let g:neocomplcache_enable_prefetch = 1

let g:neocomplcache_dictionary_filetype_lists = {
            \ 'default' : ''
            \ }

if !exists('g:neocomplcache_wildcard_characters')
    let g:neocomplcache_wildcard_characters = {}
endif
let g:neocomplcache_wildcard_characters._ = '-'
let g:neocomplcache_enable_auto_delimiter = 1

inoremap <expr><C-y> neocomplcache#cancel_popup()
inoremap <expr><C-g> neocomplcache#undo_completion()>
" Enable heavy omni completion.
if !exists('g:neocomplcache_omni_patterns')
    let g:neocomplcache_omni_patterns = {}
endif

autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
"autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete

let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::'
let g:neocomplcache_omni_patterns.c = '\%(\.\|->\)\h\w*'
let g:neocomplcache_omni_patterns.cpp = '\h\w*\%(\.\|->\)\h\w*\|\h\w*::'

let g:neocomplcache_omni_functions = {
            \ 'ruby' : 'rubycomplete#Complete',
            \ 'eruby' : 'htmlcomplete#CompleteTags',
            \ }

"******************************** Autotag *****************************
"set tags=tags,./tags,tmp/tags,doc/tags
"map <leader>gt :!ctags --extra=+f -R<CR><CR>

"******************************* vim-signify **************************
let g:signify_mapping_next_hunk = '<D-N>'
let g:signify_mapping_prev_hunk = '<D-P>'
let g:signify_mapping_toggle_highlight = '<leader>gh'
let g:signify_mapping_toggle           = '<leader>gt'

"******************************* go ***********************************
"autocmd BufWritePre *.go :Fmt
autocmd BufWritePre *.go :GoImports
let g:godef_split=0
set completeopt-=preview
let g:ycm_key_list_select_completion = ['<Down>', '<C-N>']

" gomod.vim: Vim syntax file for go.mod file
"
" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
  finish
endif

syntax case match

" match keywords
syntax keyword gomodModule  module
syntax keyword gomodGo      go      contained
syntax keyword gomodRequire require
syntax keyword gomodExclude exclude
syntax keyword gomodReplace replace

" require, exclude, replace, and go can be also grouped into block
syntax region gomodRequire start='require (' end=')' transparent contains=gomodRequire,gomodVersion
syntax region gomodExclude start='exclude (' end=')' transparent contains=gomodExclude,gomodVersion
syntax region gomodReplace start='replace (' end=')' transparent contains=gomodReplace,gomodVersion
syntax match  gomodGo            '^go .*$'           transparent contains=gomodGo,gomodGoVersion

" set highlights
highlight default link gomodModule  Keyword
highlight default link gomodGo      Keyword
highlight default link gomodRequire Keyword
highlight default link gomodExclude Keyword
highlight default link gomodReplace Keyword

" comments are always in form of // ...
syntax region gomodComment  start="//" end="$" contains=@Spell
highlight default link gomodComment Comment

" make sure quoted import paths are higlighted
syntax region gomodString start=+"+ skip=+\\\\\|\\"+ end=+"+
highlight default link gomodString  String

" replace operator is in the form of '=>'
syntax match gomodReplaceOperator "\v\=\>"
highlight default link gomodReplaceOperator Operator

" match go versions
syntax match gomodGoVersion "1\.\d\+" contained
highlight default link gomodGoVersion Identifier


" highlight versions:
"  * vX.Y.Z-pre
"  * vX.Y.Z
"  * vX.0.0-yyyyymmddhhmmss-abcdefabcdef
"  * vX.Y.Z-pre.0.yyyymmddhhmmss-abcdefabcdef
"  * vX.Y.(Z+1)-0.yyyymmddhhss-abcdefabcdef
"  see https://godoc.org/golang.org/x/tools/internal/semver for more
"  information about how semantic versions are parsed and
"  https://golang.org/cmd/go/ for how pseudo-versions and +incompatible
"  are applied.


" match vX.Y.Z and their prereleases
syntax match gomodVersion "v\d\+\.\d\+\.\d\+\%(-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?"
"                          ^--- version ---^^------------ pre-release  ---------------------^^--------------- metadata ---------------------^
"                         ^--------------------------------------- semantic version -------------------------------------------------------^

" match pseudo versions
" without a major version before the commit (e.g.  vX.0.0-yyyymmddhhmmss-abcdefabcdef)
syntax match gomodVersion  "v\d\+\.0\.0-\d\{14\}-\x\+"
" when most recent version before target is a pre-release
syntax match gomodVersion  "v\d\+\.\d\+\.\d\+-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?\.0\.\d\{14}-\x\+"
"                          ^--- version ---^^--- ------ pre-release -----------------^^--------------- metadata ---------------------^
"                         ^------------------------------------- semantic version --------------------------------------------------^
" most recent version before the target is X.Y.Z
syntax match gomodVersion "v\d\+\.\d\+\.\d\+\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?-0\.\d\{14}-\x\+"
"                          ^--- version ---^^--------------- metadata ---------------------^

" match incompatible vX.Y.Z and their prereleases
syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+\%(-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?+incompatible"
"                          ^------- version -------^^------------- pre-release ---------------------^^--------------- metadata ---------------------^
"                         ^------------------------------------------- semantic version -----------------------------------------------------------^

" match incompatible pseudo versions
" incompatible without a major version before the commit (e.g.  vX.0.0-yyyymmddhhmmss-abcdefabcdef)
syntax match gomodVersion "v[2-9]\{1}\d*\.0\.0-\d\{14\}-\x\++incompatible"
" when most recent version before target is a pre-release
syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+-\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\%(+\%([0-9A-Za-z-]\+\)\(\.[0-9A-Za-z-]\+\)*\)\?\.0\.\d\{14}-\x\++incompatible"
"                          ^------- version -------^^---------- pre-release -----------------^^--------------- metadata ---------------------^
"                         ^---------------------------------------- semantic version ------------------------------------------------------^
" most recent version before the target is X.Y.Z
syntax match gomodVersion "v[2-9]\{1}\d*\.\d\+\.\d\+\%(+\%([0-9A-Za-z-]\+\)\%(\.[0-9A-Za-z-]\+\)*\)\?-0\.\d\{14}-\x\++incompatible"
"                          ^------- version -------^^---------------- metadata ---------------------^
highlight default link gomodVersion Identifier

let b:current_syntax = "gomod"
colorscheme gruvbox
let g:airline#extensions#tabline#enabled = 1

3. 安装插件

vim .vimrc之后在Visual模式下执行
:PluginInstall

之后就可以看到插件的可视化安装界面,需要等待一段时间

image-20200729145332278

当出现done的字眼的时候就说明安装完成

image-20200729153313370

4. 解决问题

1. YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support.

该问题可以通过安装依赖去解决

apt install vim-python-jedi

2. The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it. Follow the instructions in the documentation.

编译YCM

cd ~/.vim/bundle/YouCompleteMe && ./install.sh

等待编译完,该问题也就相应的解决了。

posted @ 2021-02-10 00:36  ttlv  阅读(156)  评论(0编辑  收藏  举报