打造超級溫馨的Go開發環境之VIM配置

最近博主已經從VIM遷移到了EMACS做爲主要生產工具,目的是爲了學習Lisp和體驗EMACS操做系統之美,哈哈,不要被我弄的技術焦慮,沒錯,我就是換了個吃飯的盤子。寫下這篇博客也是爲了記念我順利的「從VIM畢業了」。html

在閱讀本文以前,你須要:node

  • 準備一個UNIX like的操做系統
  • 一個能夠跨過山和大海的代-理

話很少說,開始吧~python

(1)下載必要的Go工具鏈

go get -v github.com/mdempsky/gocode
go get -v github.com/ramya-rao-a/go-outline
go get -v github.com/acroca/go-symbols
go get -v github.com/uudashr/gopkgs
go get -v golang.org/x/tools/cmd/guru
go get -v golang.org/x/tools/cmd/gorename
go get -v github.com/sqs/goreturns
go get -v github.com/rogpeppe/godef
go get -v golang.org/x/tools/cmd/godoc
go get -v golang.org/x/lint/golint
go get -v github.com/derekparker/delve/tree/master/cmd/dlv
go get -v github.com/fatih/gomodifytags
go get -v github.com/haya14busa/goplay
go get -v github.com/josharian/impl
go get -v github.com/tylerb/gotype-live
go get -v github.com/cweill/gotests
go get -v github.com/sourcegraph/go-langserver
go get -v github.com/davidrjenni/reftools/tree/master/cmd/fillstruct

(2)安裝VIM

macOS用戶可能須要安裝一下macvim:git

brew install macvim

(3)主題配置

爲了實現相似於Atom的Onedark和Onelight模式,咱們可能須要安裝兩個主題:github

  • onedark.vim(只支持黑暗模式):https://github.com/joshdick/onedark.vim.git
  • one.vim(同時支持):https://github.com/rakr/vim-one.git

.vim目錄下建立三個目錄:autoload,bundle,colors,將兩個倉庫克隆到本地,而後將autoload目錄的one.vim或者onedark.vim拷貝到autoload目錄,將colors目錄的one.vim或者onedark.vim拷貝到colors目錄。golang

配置主題,修改~/.vimrc文件:npm

colorscheme one
set background=dark

當你想要將主題更改成Onelight的時候,只要將dark替換爲light便可。編程

(4)插件配置

首先要安裝插件管理器Vundle:vim

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

而後配置~/.vimrc文件:bash

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

爲了支持多種編程語言,咱們採用YouCompleteMe插件,macOS用戶使用以下命令:

brew install cmake python python3 mono go nodejs

若是你已經使用nvm做爲Node.js版本管理器,或者已經經過PKG方式安裝了Python3.x版本,那麼只須要PATH能夠識別到命令,另外nvm用戶須要安裝npm:

brew install npm

接下來須要進行編譯:

cd ~/.vim/bundle/YouCompleteMe
python3 install.py --all

因爲YouCompleteMe插件使用Vundle安裝可能致使失敗,所以經過手動安裝的方式實現,其餘插件都可以經過Vundle安裝:

Plugin 'fatih/vim-go'
Plugin 'Tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

寫到.vimrc文件中,而後打開vim,進入命令模式,使用以下命令安裝:

:PluginInstall

vim-go插件須要下載一些工具包,若是使用Vundle安裝失敗,能夠進入vim使用以下命令:

:GoInstallBinaries

配置完成後的整個.vimrc文件以下:

set nocompatible              " be iMproved, required
filetype off                  " required
syntax on
colorscheme one
let g:one_allow_italics = 1
set background=dark
set nu
let NERDTreeWinSize=50
let NERDTreeShowLineNumbers=1
let NERDTreeAutoCenter=1
let NERDTreeShowHidden=1
let g:go_gopls_enabled = 0

set laststatus=2 "始終顯示狀態欄
set tabstop=2 "一個製表符的長度
set softtabstop=2 "一個製表符的長度(能夠大於tabstop)
set shiftwidth=2 "一個縮進的長度
set expandtab "使用空格替代製表符
set smarttab "智能製表符
set autoindent "自動縮進
set smartindent "只能縮進
set ruler "顯示位置指示器
set ignorecase "檢索時忽略大小寫
set hls "檢索時高亮顯示匹配項
set helplang=cn "幫助系統設置爲中文
set foldmethod=syntax "代碼摺疊

set guifont=PowerlineSymbols\ for\ Powerline
set nocompatible
set t_Co=256
let g:Powerline_symbols = 'fancy'

" let g:nerdtree_tabs_open_on_console_startup=1

"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
  if (has("nvim"))
    "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
    let $NVIM_TUI_ENABLE_TRUE_COLOR=1
  endif
  "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
  "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
  " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
  if (has("termguicolors"))
    set termguicolors
  endif
endif

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'Valloric/YouCompleteMe',{'do':'python3 install.py --all'}
Plugin 'Tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line

let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
相關文章
相關標籤/搜索