使用更高效的 Vim 进行开发

fclb5649 5年前
   <h2>截图</h2>    <p><a href="/misc/goto?guid=4959676867350919467"><img alt="使用更高效的 Vim 进行开发" src="https://simg.open-open.com/show/4e1faaf1a9fa1bfbad0946d091800554.png"></a></p>    <h2>安装</h2>    <p>(你需要一个有Python支持的Vim版本. 请使用 <code>vim --version | grep +python</code> 来检查)</p>    <ul>     <li> <p><strong>依赖</strong>(Debian/Ubuntu 平台)</p> <p><code>sudo apt-get install python vim exuberant-ctags git</code></p> <p><code>sudo pip install dbgp vim-debug pep8 flake8 pyflakes isort</code></p> </li>     <li> <p><strong>依赖</strong>(Mac OS 平台)</p> <p><code>brew install python vim git</code></p> <p><code>wget http://tenet.dl.sourceforge.net/project/ctags/ctags/5.8/ctags-5.8.tar.gz && tar -zxvf ctags-5.8.tar.gz && cd ctags-5.8 && ./configure && make && sudo make install</code></p> <p><code>sudo pip install dbgp vim-debug pep8 flake8 pyflakes isort</code></p> </li>     <li> <p><strong>下载vimrc 文件到用户主目录</strong></p> <p><code>wget https://raw.githubusercontent.com/tao12345666333/vim/master/vimrc -O $HOME/.vimrc</code></p> </li>     <li> <p><strong>打开 Vim</strong></p> <p>打开Vim, 它将会自动安装插件. 请耐心等待它完成. 或者你可以使用下面的命令来自行安装.</p> <p><code>vim -E -u $HOME/.vimrc +qall</code></p> </li>     <li> <p><strong>享受你的Vim并个性化它吧!</strong></p> </li>    </ul>    <h2>支持特性</h2>    <h3>插件管理(Vundle)</h3>    <p>在这份配置中,使用了<a href="/misc/goto?guid=4959639603038445569"><strong>Vundle</strong></a>作为插件管理器. Vundle会自动接管 <code>.vim</code> 文件夹,所有配置好的插件将默认下载至<code>~/.vim/bundle/</code>, 在使用之前请确保<code>.vim</code>文件夹干净. Vundle的插件安装需要触发 <code>git clone</code> 操作,搜索需要 <code>curl</code> 支持.</p>    <p>配置(截取了部分)</p>    <pre>  <code class="language-bash">" let Vundle manage Vundle  Bundle 'gmarik/vundle'    " ============================================================================  " Active plugins  " You can disable or add new ones here:    " Plugins from github repos:    " Python and PHP Debugger  Bundle 'fisadev/vim-debug.vim'  " Better file browser  Bundle 'scrooloose/nerdtree'  " Code commenter  Bundle 'scrooloose/nerdcommenter'  " Class/module browser  Bundle 'majutsushi/tagbar'  " Code and files fuzzy finder  Bundle 'kien/ctrlp.vim'  " Extension to ctrlp, for fuzzy command finder  Bundle 'fisadev/vim-ctrlp-cmdpalette'  " Zen coding  Bundle 'mattn/emmet-vim'  " Git integration  Bundle 'motemen/git-vim'  " Tab list panel  Bundle 'kien/tabman.vim'  </code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>命令</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>:PluginList</td>       <td>列出所有Plugin</td>      </tr>      <tr>       <td>:PluginInstall(!)</td>       <td>安装/更新Plugin</td>      </tr>      <tr>       <td>:PluginSearch(!) foo</td>       <td>搜索foo相关的Plugin</td>      </tr>      <tr>       <td>:PluginClean(!)</td>       <td>清理未使用的Plugin</td>      </tr>      <tr>       <td>:PluginUpdate</td>       <td>更新插件</td>      </tr>     </tbody>    </table>    <h3>工程文件浏览(NERDTree)</h3>    <p>在这份配置中, 使用了<a href="/misc/goto?guid=4958833384981922744"><strong>NERDTree</strong></a>查看文件列表. 你可以在NERDTree中浏览和打开你文件系统中的目录或文件. 还可以进行文件隐藏和过滤, 设置添加书签等. 在NERDTree窗口输入<code>?</code>可获得操作指南. 这份配置中默认过滤掉了<code>.pyc</code>, <code>.git</code>, <code>.hg</code>, <code>.svn</code>等文件或文件夹的显示.</p>    <p>配置</p>    <pre>  <code class="language-bash">" auto open or close NERDTree  autocmd vimenter * if !argc() | NERDTree | endif  autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif    " NERDTree -----------------------------    " toggle nerdtree display  map <F3> :NERDTreeToggle<CR>  " open nerdtree with the current file selected  nmap ,t :NERDTreeFind<CR>  " don;t show these file types  let NERDTreeIgnore = ['\.pyc$', '\.pyo$']</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>F3</td>       <td>打开/关闭NERDTree</td>      </tr>      <tr>       <td>,t</td>       <td>打开NERDTree并选中当前文件</td>      </tr>     </tbody>    </table>    <h3>语法检查</h3>    <p>在这份配置中, 使用<a href="/misc/goto?guid=4958836238115746026"><strong>Syntastic</strong></a>插件进行语法静态检查. 包括但不限于<code>C/C++/Go/Python/Haskell/Ruby/JavaScript</code>等. 在本配置中对JavaScript的静态检查使用<code>eslint</code>,可以支持ES6及JSX等, 细节可以参考<a href="/misc/goto?guid=4959676867525113168">JSLint, JSHint和ESLint的对比及Vim配置</a>, 想要切换检查工具只要修改对应位置即可.</p>    <p>配置</p>    <pre>  <code class="language-bash">" Syntastic ------------------------------    " show list of errors and warnings on the current file  nmap <leader>e :Errors<CR>  " check also when just opened the file  let g:syntastic_check_on_open = 1  " syntastic checker for javascript.  " eslint is the only tool support JSX.  " If you don't need write JSX, you can use jshint.  " And eslint is slow, but not a hindrance  " let g:syntastic_javascript_checkers = ['jshint']  let g:syntastic_javascript_checkers = ['eslint']  " don't put icons on the sign column (it hides the vcs status icons of signify)  let g:syntastic_enable_signs = 0  " custom icons (enable them if you use a patched font, and enable the previous   " setting)  let g:syntastic_error_symbol = '✗'  let g:syntastic_warning_symbol = '⚠'  let g:syntastic_style_error_symbol = '✗'  let g:syntastic_style_warning_symbol = '⚠'</code></pre>    <p>特性</p>    <p>保存时自动进行语法静态检查,方便的错误提示及灵活的可扩展性.</p>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td><code>\e</code></td>       <td>打开错误列表</td>      </tr>     </tbody>    </table>    <h3>Git支持</h3>    <p>在这份配置中, 使用<a href="/misc/goto?guid=4958833384853162113"><strong>vim-fugitive</strong></a>和<a href="/misc/goto?guid=4959676867636765574"><strong>vim-signify</strong></a>做Git方面的支持. 可以进行常用的git操作及优雅的状态提示等(目前支持<code>git</code>和<code>hg</code>).</p>    <p>配置</p>    <pre>  <code class="language-bash">" Signify ------------------------------    " this first setting decides in which order try to guess your current vcs  " UPDATE it to reflect your preferences, it will speed up opening files  let g:signify_vcs_list = [ 'git', 'hg' ]  " mappings to jump to changed blocks  nmap <leader>sn <plug>(signify-next-hunk)  nmap <leader>sp <plug>(signify-prev-hunk)  " nicer colors  highlight DiffAdd           cterm=bold ctermbg=none ctermfg=119  highlight DiffDelete        cterm=bold ctermbg=none ctermfg=167  highlight DiffChange        cterm=bold ctermbg=none ctermfg=227  highlight SignifySignAdd    cterm=bold ctermbg=237  ctermfg=119  highlight SignifySignDelete cterm=bold ctermbg=237  ctermfg=167  highlight SignifySignChange cterm=bold ctermbg=237  ctermfg=227</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>:Git [args]</td>       <td>类似执行<code>git</code>命令一样</td>      </tr>      <tr>       <td>:Gstatus</td>       <td>类似<code>git status</code>.在列表中使用<code>-</code>添加/移除文件</td>      </tr>      <tr>       <td>:Gcommit [args]</td>       <td>类似 <code>git commit</code></td>      </tr>      <tr>       <td>:Gmerge [args]</td>       <td>类似 <code>git merge</code></td>      </tr>      <tr>       <td>:Gpull [args]</td>       <td>类似 <code>git pull</code></td>      </tr>      <tr>       <td>:Gpush [args]</td>       <td>类似 <code>git push</code></td>      </tr>      <tr>       <td>:Gvdiff [revision]</td>       <td>类似 <code>git push</code> 但是会切分窗口</td>      </tr>     </tbody>    </table>    <p>更多详细的操作可以使用 <code>:help fugitive</code></p>    <h3>Tag支持</h3>    <p>在这份配置中,使用了<a href="/misc/goto?guid=4959676867713024793"><strong>Tagbar</strong></a>做Tag支持,可以显示当前文件中定义的类/变量等.</p>    <p>配置</p>    <pre>  <code class="language-bash">" Tagbar -----------------------------    " toggle tagbar display  map <F4> :TagbarToggle<CR>  " autofocus on tagbar open  let g:tagbar_autofocus = 1</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>F4</td>       <td>打开Tag列表</td>      </tr>     </tbody>    </table>    <h3>超全自动补全</h3>    <p>在这份配置中, 使用了<a href="/misc/goto?guid=4959635623959615430"><strong>Neocomplcache</strong></a>作为主要的自动补全插件.</p>    <p>配置</p>    <pre>  <code class="language-bash">" NeoComplCache ------------------------------    " most of them not documented because I'm not sure how they work  " (docs aren't good, had to do a lot of trial and error to make   " it play nice)    " Disable AutoComplPop.  let g:acp_enableAtStartup = 0  " Use neocomplcache.  let g:neocomplcache_enable_at_startup = 1  let g:neocomplcache_enable_ignore_case = 1  " Use smartcase.  let g:neocomplcache_enable_smart_case = 1  let g:neocomplcache_enable_auto_select = 1    let g:neocomplcache_enable_fuzzy_completion = 1  let g:neocomplcache_enable_camel_case_completion = 1  let g:neocomplcache_enable_underbar_completion = 1  let g:neocomplcache_fuzzy_completion_start_length = 1  let g:neocomplcache_auto_completion_start_length = 1  let g:neocomplcache_manual_completion_start_length = 1  " Set minimum syntax keyword length.  let g:neocomplcache_min_keyword_length = 1  let g:neocomplcache_min_syntax_length = 1  let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*'  " complete with workds from any opened file  let g:neocomplcache_same_filetype_lists = {}  let g:neocomplcache_same_filetype_lists._ = '_'  " <TAB>: completion.  inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"  " Define keyword.  if !exists('g:neocomplcache_keyword_patterns')      let g:neocomplcache_keyword_patterns = {}  endif  let g:neocomplcache_keyword_patterns['default'] = '\h\w*'  " Plugin key-mappings.  inoremap <expr><C-g>     neocomplcache#undo_completion()  inoremap <expr><C-l>     neocomplcache#complete_common_string()  " <C-h>, <BS>: close popup and delete backword char.  inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"  inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"  inoremap <expr><C-y>  neocomplcache#close_popup()  inoremap <expr><C-e>  neocomplcache#cancel_popup()</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td><Tab></td>       <td>使用Tab键进行待提示项目选择</td>      </tr>      <tr>       <td><C-g></td>       <td>取消补全</td>      </tr>      <tr>       <td><C-l></td>       <td>完成待补全项中共同的字符串</td>      </tr>      <tr>       <td><C-h></td>       <td>关闭待选项</td>      </tr>      <tr>       <td><C-y></td>       <td>关闭待选项</td>      </tr>      <tr>       <td><C-e></td>       <td>退出待选项</td>      </tr>      <tr>       <td><BS></td>       <td>关闭待选项</td>      </tr>     </tbody>    </table>    <h3>类Tmux的窗口选择</h3>    <p>在这份配置中,使用了<a href="/misc/goto?guid=4959676867832721003"><strong>vim-choosewin</strong></a>进行窗口管理器. 支持类Tmux的操作.</p>    <p>配置</p>    <pre>  <code class="language-bash">" Window Chooser ------------------------------    " mapping  nmap  -  <Plug>(choosewin)  " show big letters  let g:choosewin_overlay_enable = 1</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>-</td>       <td>开启窗口选择</td>      </tr>      <tr>       <td>- [</td>       <td>选择上一个tab的窗口</td>      </tr>      <tr>       <td>- ]</td>       <td>选择下一个tab的窗口</td>      </tr>     </tbody>    </table>    <p>更多操作可以使用 <code>:help choosewin</code></p>    <h3>灵活的Tab管理</h3>    <p>在这份配置中使用了<a href="/misc/goto?guid=4959676867911945062">TabMan</a>进行Tab管理,可以进行灵活切换与管理</p>    <p>配置</p>    <pre>  <code class="language-bash">" TabMan ------------------------------    " mappings to toggle display, and to focus on it  let g:tabman_toggle = 'tl'  let g:tabman_focus  = 'tf'</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>tl</td>       <td>开启/关闭tab管理</td>      </tr>      <tr>       <td>tf</td>       <td>将光标移动到tab管理窗口</td>      </tr>     </tbody>    </table>    <h3>优雅的状态栏</h3>    <p>在这份配置中,使用了<a href="/misc/goto?guid=4959676867988725381"><strong>Airline</strong></a>提供更多状态栏支持.</p>    <p>配置</p>    <pre>  <code class="language-bash">" Airline ------------------------------    let g:airline_powerline_fonts = 1  let g:airline_theme = 'bubblegum'  "let g:airline#extensions#tabline#enabled = 1  "let g:airline#extensions#tabline#left_sep = ' '  "let g:airline#extensions#tabline#left_alt_sep = '|'  let g:airline#extensions#whitespace#enabled = 1    " to use fancy symbols for airline, uncomment the following lines and use a  " patched font (more info on the README.rst)  if !exists('g:airline_symbols')     let g:airline_symbols = {}  endif    let g:airline_left_sep = ''  let g:airline_left_alt_sep = ''  let g:airline_right_sep = ''  let g:airline_right_alt_sep = ''  let g:airline_symbols.branch = ''  let g:airline_symbols.readonly = ''  let g:airline_symbols.linenr = ''</code></pre>    <p>支持特性</p>    <p>可以显示分支,语法静态检查结果等.</p>    <h3>自动插入头部</h3>    <p>在这份配置中写了个小函数根据新建的不同类型的文件,自动插入头部,支持<code>python</code>, <code>ruby</code>, <code>bash</code>等.</p>    <h3>Markdown实时预览</h3>    <p>在这份配置中, 使用了<a href="/misc/goto?guid=4959631165777444515"><strong>vim-instant-markdown</strong></a>和<a href="/misc/goto?guid=4959632626758136489">vim-markdown</a>做Markdown格式的支持,可以支持实时预览等特性.</p>    <p>此功能需要有node环境支持,可以执行 <code>npm -g install instant-markdown-d</code> 进行安装.</p>    <p>配置</p>    <pre>  <code class="language-bash">" Vim-markdown ------------------------------    " Disabled automatically folding  let g:vim_markdown_folding_disabled=1  " LeTeX math  let g:vim_markdown_math=1  " Highlight YAML frontmatter  let g:vim_markdown_frontmatter=1    " Vim-instant-markdown -----------------    " If it takes your system too much, you can specify  " let g:instant_markdown_slow = 1  " if you don't want to manually control it  " you can open this setting  " and when you open this, you can manually trigger preview  " via the command :InstantMarkdownPreview  let g:instant_markdown_autostart = 0</code></pre>    <p>支持操作</p>    <table>     <thead>      <tr>       <th>快捷键</th>       <th>解释</th>      </tr>     </thead>     <tbody>      <tr>       <td>:InstantMarkdownPreview</td>       <td>手动触发markdown文件的预览</td>      </tr>     </tbody>    </table>    <h3>快速文件查找</h3>    <p>在这份配置中, 可以通过使用<code>,R</code>进行全文查找或者<code>,r</code>进行快速查找, 或者在当前字符串上使用<code>,wR</code>以及<code>,wr</code>来进行全文查找或者快速查找.</p>    <h3>快速注释</h3>    <p>使用<a href="/misc/goto?guid=4958836238318316577"><strong>NERDCommenter</strong></a>插件完成快速注释, 可以通过<code>\ci</code>进行快速注释.</p>    <p>Python 支持</p>    <p>完备的Python支持, 可以自动识别当前是系统环境或虚拟环境, 使用<code>:Isort</code>可智能对导入包进行排序, 使用<code>:PymodeLintAuto</code>可自动格式化.</p>    <p><strong>除了上述列出的功能以外, 还有很多方便的特性,可以大大提升效率,在使用中慢慢体会吧!有问题可以在<a href="/misc/goto?guid=4959676868169790939">tao12345666333/vim</a> on github 提issue</strong></p>    <p> </p>    <p> </p>    <p>来自:https://github.com/tao12345666333/vim</p>    <p> </p>    <p> </p>    <p><span style="color:rgb(255, 255, 255)">Save</span></p>