Mac 下配置 Vim vundle 代码补全 YouCompleteMe 等
来源:互联网 发布:mac怎么下载idea 编辑:程序博客网 时间:2024/05/29 14:45
确定 Vim 版本满足支持
如果你用的是 Mac OS X 自带的 vim 的话,那么肯定是不能满足需求的。
使用brew安装一个7.4版本的 vim
通过brew 来安装
安装独立的vim替换掉OSX默认
brew install mercurial brew install vim
打开高亮渲染
在
~/.vimrc
中配置set nonusyntax on
修复 mac 下 vim 无法使用delete删除文本的问题
在
~/.vimrc
中配置" fix mac vim delete error, so as set backspace=indent,eol,startset backspace=2
安装 mvim 代替vi
本文还是使用独立的vim,所以后面没介绍mvim的相关配置
brew install macvim
使用 MacVim 替换系统自带的 Vim
alias vim='mvim -v'
安装 Vundle
它的使用方法很简单,安装一个插件只需要在.vimrc按照规则中添加 Plugin 的名称,某些需要添加路径,之后在 Vim 中使用:PluginInstall既可以自动化安装。
- git 克隆 Vundle 工程到本地
git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
- 修改.vimrc配置 Plugins。在.vimrc文件中添加如下内容
set nocompatible " be iMproved, requiredfiletype off " required" set the runtime path to include Vundle and initializeset rtp+=~/.vim/bundle/Vundle.vimcall vundle#begin()" alternatively, pass a path where Vundle should install plugins"call vundle#begin('~/some/path/here')" let Vundle manage Vundle, requiredPlugin 'VundleVim/Vundle.vim'" The following are examples of different formats supported." Keep Plugin commands between vundle#begin/end." All of your Plugins must be added before the following linecall vundle#end() " requiredfiletype 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
保存后进入
vim
运行命令:PluginInstall
vundle 命令
# 安装插件:BundleInstall# 更新插件:BundleUpdate# 清除不需要的插件:BundleClean# 列出当前的插件:BundleList# 搜索插件:BundleSearch
注意
插件配置不要在
call vundle#end()
之前,不然插件无法生效
如果配置错误,需要重新配置后,在vim中运行:PluginInstall
安装 YouCompleteMe
使用 Vundle 安装 YouCompleteMe
- 在
.vimrc
中添加如下内容 位置在call vundle#begin()
和call vundle#end()
之间Bundle 'Valloric/YouCompleteMe'
在vim中运行命令
:BundleInstall
编译 YouCompleteMe
编译过程需要CMake
brew install CMake
- 带 C-family languages 语义支持的版本
cd ~/.vim/bundle/YouCompleteMe ./install.sh --clang-completer
- 不带 C-family languages 语义支持的版本
cd ~/.vim/bundle/YouCompleteMe./install.sh
- 带 C# 语义支持的版本
cd ~/.vim/bundle/YouCompleteMe./install.sh --omnisharp-completer
- 带 Go 语言语义支持的版本
cd ~/.vim/bundle/YouCompleteMe./install.sh --gocode-completer
配置 YCM
在.vimrc中添加配置
" 自动补全配置set completeopt=longest,menu "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228)autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" "回车即选中当前项"上下左右键的行为 会显示其他信息inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"inoremap <expr> <PageUp> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>""youcompleteme 默认tab s-tab 和自动补全冲突"let g:ycm_key_list_select_completion=['<c-n>']let g:ycm_key_list_select_completion = ['<Down>']"let g:ycm_key_list_previous_completion=['<c-p>']let g:ycm_key_list_previous_completion = ['<Up>']let g:ycm_confirm_extra_conf=0 "关闭加载.ycm_extra_conf.py提示let g:ycm_collect_identifiers_from_tags_files=1 " 开启 YCM 基于标签引擎let g:ycm_min_num_of_chars_for_completion=2 " 从第2个键入字符就开始罗列匹配项let g:ycm_cache_omnifunc=0 " 禁止缓存匹配项,每次都重新生成匹配项let g:ycm_seed_identifiers_with_syntax=1 " 语法关键字补全nnoremap <F5> :YcmForceCompileAndDiagnostics<CR> "force recomile with syntastic"nnoremap <leader>lo :lopen<CR> "open locationlist"nnoremap <leader>lc :lclose<CR> "close locationlistinoremap <leader><leader> <C-x><C-o>"在注释输入中也能补全let g:ycm_complete_in_comments = 1"在字符串输入中也能补全let g:ycm_complete_in_strings = 1"注释和字符串中的文字也会被收入补全let g:ycm_collect_identifiers_from_comments_and_strings = 0nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> " 跳转到定义处
ctags
用来遍历源代码文件生成tags文件,这些tags文件能被编辑器或其它工具用来快速查找定位源代码中的符号(tag/symbol),如变量名,函数名等
Install Ctags
brew updatebrew install ctags-exuberant
Config ctags
vi ~/.profile# addexport PATH="/usr/local/bin:/usr/local/sbin:$PATH"source ~/.profile
Use ctags
ctags --helpctags --versionctags –R *
-R
表示递归创建,也就包括源代码根目录(当前目录)下的所有子目录*
表示所有文件- 这条命令会在当前目录下产生一个
tags
文件,当用户在当前目录中运行vi/vim
时,会自动载入此tags文件taglist
taglist是一个用于显示定位程序中各种符号的插件,例如宏定义、变量名、结构名、函数名这些东西 我们将其称之为符号(symbols),而在taglist中将其称之为tag。显然,要想将程序文件中的tag显示出来,需要事先了解全部tag的信 息,并将其保存在一个文件中,然后去解析对应的tag文件。taglist做的仅仅是将tag文件中的内容解析完后显示在Vim上而已。tag扫描以及数 据文件的生成则是由ctags(Exuberant Ctags)这一工具完成的,所以在使用taglist之前,你的电脑需要装有ctags。
Bundle 'taglist.vim'let Tlist_Ctags_Cmd='ctags'let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的let Tlist_WinWidt =28 "设置taglist的宽度let Tlist_Exit_OnlyWindow=1 "如果taglist窗口是最后一个窗口,则退出vim"let Tlist_Use_Right_Window=1 "在右侧窗口中显示taglist窗口let Tlist_Use_Left_Windo =1 "在左侧窗口中显示taglist窗口
快捷键
跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
o 在一个新打开的窗口中显示光标下tag显示光标下tag的原型定义u 更新taglist窗口中的tags 更改排序方式,在按名字排序和按出现顺序排序间切换x taglist窗口放大和缩小,方便查看较长的tag打开一个折叠,同zo将tag折叠起来,同zc打开所有的折叠,同zR= 将所有tag折叠起来,同zM[[ 跳到前一个文件]] 跳到后一个文件q 关闭taglist窗口
NERDTree
NERDTree是一个用于浏览文件系统的树形资源管理
它可以让你像使用finder一样在VIM中浏览文件系统并且打开文件或目录" NERDTreeBundle 'scrooloose/nerdtree'
配置
let NERDTreeWinPos='right'let NERDTreeWinSize=30map <F2> :NERDTreeToggle<CR>
额外插件推荐
" original repos on githubBundle 'kien/ctrlp.vim'Bundle 'sukima/xmledit'Bundle 'sjl/gundo.vim'Bundle 'jiangmiao/auto-pairs'Bundle 'klen/python-mode'Bundle 'Valloric/ListToggle'Bundle 'SirVer/ultisnips'Bundle 'Valloric/YouCompleteMe'Bundle 'scrooloose/syntastic'Bundle 't9md/vim-quickhl'" Bundle 'Lokaltog/vim-powerline'Bundle 'scrooloose/nerdcommenter'".................................." vim-scripts reposBundle 'YankRing.vim'Bundle 'vcscommand.vim'Bundle 'ShowPairs'Bundle 'SudoEdit.vim'Bundle 'EasyGrep'Bundle 'VOoM'Bundle 'VimIM'
作者:泛原罪
链接:http://www.jianshu.com/p/58e2d78744a2
來源:简书
- Mac 下配置 Vim vundle 代码补全 YouCompleteMe 等
- vim代码补全:YouCompleteMe\Vundle\python
- Mac 下配置 Vim 代码补全:YouCompleteMe
- Vim + Vundle + YouCompleteMe 配置
- 【环境配置】VIM 安装YouCompleteMe自动补全插件(MAC)
- mac vim 下安装自动补全插件YouCompleteMe
- Windows下Vim代码补全YouCompleteMe设置指南
- Vim代码补全插件:YouCompleteMe
- VIM插件: YouCompleteMe[代码自动补全]
- vim配置补全插件YouCompleteMe
- Mac 安装Vim自动补全插件(YouCompleteMe)
- Ubuntu下vim配置:自动补全YouCompleteMe安装与配置
- VIM 自动补全YouCompleteME
- Vim代码补全插件——YouCompleteMe安装说明
- Vim代码补全插件——YouCompleteMe使用指南
- Vim代码补全插件YouCompleteMe的自动化安装[转]
- Vim自动补全插件----YouCompleteMe安装与配置
- Vim自动补全插件----YouCompleteMe安装与配置
- 项目报错:Duplicate files copied in APK META-INF/LICENSE
- 杭电ACM OJ 1027 Ignatius and the Princess II 全排列的第N个 康托展开
- 使用centOS 7配置nodeJS开发环境
- 文字——弹幕?
- C++——黑白棋(基础模块)
- Mac 下配置 Vim vundle 代码补全 YouCompleteMe 等
- 51nod 1094 和为k的连续区间
- 单点登录
- 关于栈对齐的反汇编代码
- 熬夜写了道题
- 使用FireBug插件辅助采集网页动态加载数据
- 关于JavaScript函数柯里化问题探索
- Redis-Jedis连接Redis
- Safe-splash页面(1)