Vim打造屬於自己的IDE

從此一張.vimrc 的conf文件走天下。

  1. 配置 .vimrc 文件 = vim常規配置 +個性化插件配置;
  2. 避免單個文件太大, 利於後面閱讀, 分爲兩部分。

1. .vimrc general Settings

將自己配置貼上來,vim常規配置 . 註釋使用英文, 便於複製黏貼無亂碼.
慢慢按需添加, 而不是隨便從網上貼一份過來.

" ```````````````````````````````````````````````
" General Setting of Vim
" ..............................................
set number
set nowrap
set nocompatible
" Backup cancel
set nobackup  
set nowb  
set noswapfile
set ignorecase

set ruler
set tabstop=4 
set paste
autocmd! bufwritepost $HOME/.vimrc source %

syntax on
filetype off
filetype plugin indent on

2. Settings of plugins in Vundle

Vundle 安裝的插件的一些設置

" ----------------------------------------------
"  Plugins Content & Plugins settings                            
" .............................................
set rtp+=~/.vim/bundle/Vundle.vim/

call vundle#begin()
Plugin 'VundleVim/Vundle.vim'

" Bottom Line
Plugin 'Lokaltog/vim-powerline'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'Xuyuanp/nerdtree-git-plugin'
" NerdTree
autocmd vimenter * NERDTree
map <C-n> :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
let g:NERDTreeShowIgnoredStatus = 1
let g:nerdtree_tabs_open_on_console_startup=1
"let g:NERDTreeIndicatorMapCustom = {
"    \ "Modified"  : "✹",
"    \ "Staged"    : "",
"    \ "Untracked" : "✭",
"    \ "Renamed"   : "",
"    \ "Unmerged"  : "═",
"    \ "Deleted"   : "",
"    \ "Dirty"     : "✗",
"    \ "Clean"     : "✔︎",
"    \ 'Ignored'   : '☒',
"    \ "Unknown"   : "?"
"    \ }
let g:NERDTreeDirArrowExpandable = '+'
let g:NERDTreeDirArrowCollapsible = '-'


" Powerline
set rtp+=~/.vim/bundle/vim-powerline/plugin/Powerline.vim                     
set laststatus=2
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'

" Theme
Plugin 'altercation/vim-colors-solarized'
Plugin 'tomasr/molokai'
Plugin 'vim-scripts/phd'

" Coding
" Plugin 'Valloric/YouCompleteMe'

" Web Front-end
" Emmet
Plugin 'mattn/emmet-vim'
let g:user_emmet_leader_key='<Tab>'
let g:user_emmet_settings = {
         \ 'javascript.jsx' : {
            \ 'extends' : 'jsx',
         \ },
      \ }

" html 5
Plugin 'othree/html5.vim'

" css 3
Plugin 'hail2u/vim-css3-syntax'
Plugin 'ap/vim-css-color'

augroup VimCSS3Syntax
  autocmd!

  autocmd FileType css setlocal iskeyword+=-
augroup END

" JavaScipt
Plugin 'pangloss/vim-javascript'
let g:javascript_plugin_jsdoc = 1
let g:javascript_plugin_ngdoc = 1
let g:javascript_plugin_flow = 1
set foldmethod=syntax
let g:javascript_conceal_function             = "ƒ"
let g:javascript_conceal_null                 = "ø"
let g:javascript_conceal_this                 = "@"
let g:javascript_conceal_return               = ""
let g:javascript_conceal_undefined            = "¿"
let g:javascript_conceal_NaN                  = ""
let g:javascript_conceal_prototype            = ""
let g:javascript_conceal_static               = ""
let g:javascript_conceal_super                = "Ω"
let g:javascript_conceal_arrow_function       = ""
let g:javascript_conceal_noarg_arrow_function = " "
let g:javascript_conceal_underscore_arrow_function = " "
set conceallevel=1

" Prettier
Plugin 'prettier/vim-prettier', {
  \ 'do': 'yarn install',
  \ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql'] }
let g:prettier#config#bracket_spacing = 'true'
let g:prettier#config#jsx_bracket_same_line = 'false'
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql PrettierAsync

" Markdown
Plugin 'suan/vim-instant-markdown'

call vundle#end()

3. 問題排錯:

問題 1.
通過 Xshell 連接遠程的機器, 看不到 Powerline 或者 Airline 的酷炫彩色效果.

原因:
和Xshell 等這類虛擬終端有關.因爲是遠程連接, 配色上的傳輸和虛擬終端的配置有關.

解決:
暫時不管色彩問題, 實際上你的配置已經生效了. 如果是在自己本地上機器看的話, 效果是有的.

問題 2:
CentOS安裝插件 NerdTree並啓用之後, 能夠看到左側的目錄樹, 但是會出現三角形符號亂碼, 並且這些目錄都打不開.

原因:
初步估計是和系統字符編碼有關.
首先, 頁面上覆制過來顯示正常的三角形符號一旦粘帖到 .vimrc 文件中就出現亂碼, 類似 v3/4 這些個玩意兒, 導致該目錄解析不正常, 以致顯示和解析不是正常的目錄名稱, 從而打不開.

解決:
1. 更新編碼支持. 具體實現沒有嘗試, 這裏先挖坑吧.

問題 3:
安裝 YCM 後啓動 Vim,Vim 底部提示The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it.

原因:
這是需要編譯 YCM

解決:
1. 安裝 cmake, 具體命令我就不多說了.簡單
2. 進入到 YCM 插件的目錄下, 找到 install.py, 執行命令"./install.py";
3. 重啓 vim.

問題 4 :
YCM 報錯:YouCompleteMe unavailable: requires Vim 7.4.1578+.
Info: You appear to be running the default system Vim on macOS. It reports as patch 8056, but it is really older than 1578. Please consider MacVim, homebrew Vim or a self-built Vim that satisfies the minimum requirement.

原因:
Mac 上的Vim的版本低於 YCM 的要求. 所以要更新 vim 到高級版本.

解決:
1. 使用 Brew 安裝 vim. 命令: "brew install vim --with-lua --with-override-system-vi --with-python";
2. 關鍵: 注意退出 shell , 重進 shell. 原因是環境變量問題.

或者:
升級Mac 系統系統版本到最新版, 升級地方是到 App Store 上.

4. 總結

1. 用好 Github 以及對應插件官方倉庫上對插件的使用說明, 配置說明;
2. 插件只是輔助, 內功更要看 vim的基礎操作.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章