用VIM打造专属IDE

先看代码后BiBi

set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

Plugin 'scrooloose/nerdtree' " 显示目录结构

Plugin 'scrooloose/nerdcommenter' " 注释

Plugin 'Valloric/YouCompleteMe' " 提示

Plugin 'vim-airline/vim-airline' " 底栏

Plugin 'tomasr/molokai' " 主题

Plugin 'python-mode/python-mode' " 代码检查

Plugin 'vim-latex/vim-latex' " LaTex

Plugin 'godlygeek/tabular' " 对齐

Plugin 'plasticboy/vim-markdown' " Markdown

Plugin 'tyru/open-browser.vim' " previm需要,vim内打开浏览器

Plugin 'previm/previm' " Markdown预览

Plugin 'mattn/emmet-vim' " HTML,CSS

Plugin 'luochen1990/rainbow' " 括号层级显示

Plugin 'ap/vim-css-color' " 显示CSS颜色

Plugin 'yggdroot/indentline' " 显示缩进指示线

Plugin 'pangloss/vim-javascript' " JavaScript

Plugin 'posva/vim-vue' " Vue

Plugin 'tpope/vim-surround' " 快速添加、修改和删除括号、引号、HTML标签、XML标签等

Plugin 'terryma/vim-multiple-cursors' " 多光标操作

call vundle#end()
filetype plugin indent on

set encoding=utf-8
set nu
set mouse=a
set cursorline
set cursorcolumn
syntax on
color molokai

if has("gui_running")
	set lines=100 columns=200
endif

set guifont=Monaco\ 10

set guioptions-=m " 隐藏菜单栏
set guioptions-=T " 隐藏工具栏
set guioptions-=r " 隐藏右侧滚动条
set guioptions-=L " 隐藏左侧滚动条
set guioptions-=b " 隐藏底部滚动条

" NERDTree
autocmd vimenter * NERDTree " 自动开启NERDTree
" <F3>关闭NERDTree
map <F3> :NERDTreeToggle<CR>

" NERDCommenter
 let g:NERDSpaceDelims=1 " 于注释符后添加一个空格
" let g:NERDDefaultAlign= 'start' " 注释符左对齐
let g:NERDDefaultAlign= 'left' " 注释符左对齐
let g:NERDCommentEmptyLines=1 " 允许注释空行
let g:NERDTrimTrailingWhitespace=1 " 去掉注释时,去掉多余空格
let g:NERDToggleCheckAllLines=1 " 注释时检查所选行是否已被注释
" 注释或反注释快捷键<F2>
map <F2> <Leader>ci

" YouCompleteMe
autocmd InsertLeave * if pumvisible() == 0|pclose|endif	"离开插入模式后自动关闭预览窗口
let g:ycm_complete_in_comments = 1 "在注释输入中也能补全
let g:ycm_collect_identifiers_from_comments_and_strings = 0 "注释和字符串中的文字也会被收入补全
let g:ycm_autoclose_preview_window_after_completion = 0 " 补全后自动关闭preview窗口
let g:ycm_extra_conf_globlist = ['~/Workspace/*'] " 载入该路径下的.ycm_extra_conf.py前不会弹出提示框
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py' " 默认库路径

" vim-airline
let g:airline#extensions#tabline#enabled=1

" python-mode
let g:pymode_warnings=0 " 允许插件警告
let g:pymode_python='python3' " 设置pymode是用的Python版本
let g:pymode_virtualenv=1 " 支持自动检测virtualenv
let g:pymode_run_bind='<F5>' " 设置<F5>为运行代码快捷键
let g:pymode_lint_sort=['E','W','C','I'] " 报错等显示顺序
let g:pymode_lint_ignore = ["E116"] " 不显示E116报错,即注释缩进报错

" vim-latex
let g:tex_flavor='latex'
let g:Tex_DefaultTargetFormat='pdf'
let g:Tex_CompileRule_pdf='xelatex -interaction=nonstopmode $*'
let g:Tex_ViewRule_pdf='xreader'

" open-browser.vim
let g:previm_open_cmd='firefox'

" rainbow
let g:rainbow_active=1
let g:rainbow_conf={
	\	'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
	\	'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
	\	'operators': '_,_',
	\	'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
	\	'separately': {
	\		'*': {},
	\		'tex': {
	\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
	\		},
	\		'vim': {
	\			'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
	\		},
	\		'html': {
	\			'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
	\		},
	\		'css': 0,
	\	}
	\}
" 括号自动补齐
inoremap ( ()<ESC>i
inoremap [ []<ESC>i
inoremap { {}<ESC>i
inoremap ' ''<ESC>i
inoremap " ""<ESC>i

" 自动代码折叠
set foldmethod=indent
nnoremap <Space> za

" 插入头部
func AddTitlePY()
	call append(0,"# -*- coding=utf8 -*-")
	call append(1,"#")
	call append(2,"# Author       : Painter")
	call append(3,"# Created Time : ".strftime("%Y-%m-%d %a %H:%M:%S"))
	call append(4,"# Filename     : ".expand("%:t"))
	call append(5,"# Email        : painter9509@126.com")
	call append(6,"")
	call append(7,"")
endfunc

func AddTitleC()
	call append(0,"/*=======================================")
	call append(1," *")
	call append(2," * Author       : Painter")
	call append(3," * Created Time : ".strftime("%Y-%m-%d %a %H:%M:%S"))
	call append(4," * Filename     : ".expand("%:t"))
	call append(5," * Email        : painter9509@126.com")
	call append(6," *")
	call append(7," *=======================================*/")
	call append(8,"")
	call append(9,"")
endfunc

func AddTitleTeX()
	call append(0,"%")
	call append(1,"% Author      : Painter")
	call append(2,"% Created Time: ".strftime("%Y-%m-%d %a %H:%M:%S"))
	call append(3,"% Filename    : ".expand("%:t"))
	call append(4,"% Email       : painter9509@126.com")
	call append(5,"%")
	call append(6,"")
 	call append(7,"")
endfunc

au BufNewFile *.py,*.pyw call AddTitlePY()

au BufNewFile *.c,*.cpp,*.h call AddTitleC()

au BufNewFile *.tex call AddTitleTeX()

" Python C C++
highlight BadWhitespace ctermbg=red guibg=darkred
au BufNewFile,BufRead *.py,*.pyw,*.c,*.cpp,*.h
	\ set tabstop=4 |
	\ set softtabstop=4 |
	\ set shiftwidth=4 |
	\ set expandtab |
	\ set autoindent |
	\ set fileformat=unix |
 	\ match BadWhitespace /\s\+$/

au BufNewFile,BufRead *.c,*.cpp,*.h
	\ set cindent |
	\ set colorcolumn=80

au BufNewFile,BufRead *.tex,*.htm,*.html
	\ set tabstop=2 |
	\ set softtabstop=2 |
	\ set shiftwidth=2 |
	\ set expandtab |
	\ set fileformat=unix

" func AutoRun()
	" if &filetype=="python"
		" let mp=&makeprg
		" setlocal makeprg=python\ -u
		" silent make %
		" copen
		" let &makeprg=mp
	" endif
" endfunc

" map <F5> :w<CR> :call AutoRun()<CR>

auto BufEnter * if 0==len(filter(range(1,winnr('$')), 'empty(getbufvar(winbufnr(v:val), "&bt"))')) | qa! | endif " 若无可编辑窗口,则自动关闭其余窗口

1. Vundle.vim https://github.com/VundleVim/Vundle.vim

Git一下:

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

.vimrc中粘贴如下内容:

set nocompatible
filetype off

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'VundleVim/Vundle.vim'
" 按照上面这句的形式,在这块写需要安装的插件
call vundle#end()
filetype plugin indent on

安装:

:PluginInstall

或者指定安装某个插件:

:PluginInstall 'VundleVim/Vundle.vim'

若要删除插件,则在配置文件中删除该插件的相关代码,然后执行:

:PluginClean

2. YouCompleteMe https://github.com/Valloric/YouCompleteMe

2.1 安装

这个插件有个浪漫的名字,用于代码补全。但是,相比其他插件,它是最不好装的插件。安装该插件需要先安装cmake。
按照YouCompleteMe的Github上的步骤,用Vundle install好该插件后,进入插件所在路径,执行命令:
若需要支持C、C++、Objective-C等语言的补全,使用如下命令:

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

若不需要支持C、C++、Objective-C等语言的补全。如果只是编辑Python的话,选择这个命令:

cd ~/.vim/bundle/YouCompleteMe
./install.py

若需要支持其他语言的补全,详细见Github。若懒得挑选,就用下面这个命令:

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

很多人用Vundle install好YouCompleteMe之后,会看到报错:

ycmd server SHUT DOWN

就是因为没有执行以上./install.py

2.2 支持anaconda/miniconda虚拟环境

有两种方法,详见https://github.com/valloric/youcompleteme#python-semantic-completion,我选用头一种。
在项目根目录下创建文件.ycm_extra_conf.py,写入:

def Settings( **kwargs ):
  return {
    'interpreter_path': '/path/to/virtual/environment/python'
  }

例如,有个conda环境叫tf,那么这么写:

def Settings( **kwargs ):
  return {
    'interpreter_path': '~/anaconda3/envs/tf/bin/python'
  }

补全的时候反映有点慢。

2.3 C/C++补全

并不是安装时选择了--clang-completer就万事大吉了。默认情况下,YouCompleteMe还不知道怎么补全C/C++呢!
所以就有了这一句:

let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'

在上面的代码中已经有了。

3. NERDCommenter https://github.com/scrooloose/nerdcommenter

NERDCommenter的配置有两处需要注意一下。一处是对齐方式使用start,而不是left,才能真正的左对齐。另一处是需要改动源文件~/.vim/bundle/nerdcommenter/plugins/NERD_commenter.vim

\ 'python': { 'left': '#', 'leftAlt': '#'}

即删掉一个空格,这样在注释的时候不会自动添加两个空格,而是按照配置要求添加一个或零个。

4. Previm https://github.com/previm/previm

需要安装rst2html.py

pip install docutils
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vim是一个专为程序员开发的文本编辑器,而C/C++是使用最广泛的编程语言之一。将Vim作为C/C++的集成开发环境(IDE),可以带来以下几个方面的效果。 首先,Vim具有丰富的代码编辑功能,包括语法高亮、自动补全、跳转到定义、跳转到引用等功能,这些功能可以提高编码的效率和准确性。 其次,Vim支持多窗口布局和分屏功能,可以同时查看和编辑多个文件或代码块,方便程序员处理复杂的项目结构和代码逻辑。 此外,Vim还支持编译和调试C/C++代码的功能,可以通过配置编译器和调试器,实现代码的编译和调试过程,并提供快捷键和命令来进行断点设置、变量查看和单步调试等操作。 最后,Vim还支持插件扩展和定制,用户可以根据自己的需求选择和安装各种插件,例如代码静态分析、代码格式化、代码重构等插件,以进一步提升开发效率和代码质量。 总之,将Vim作为C/C++的集成开发环境,可以提供丰富的代码编辑功能、多窗口布局和分屏功能、编译和调试功能,以及插件扩展和定制功能,从而帮助程序员更高效地开发C/C++代码。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [vim C++开发环境插件安装详解](https://blog.csdn.net/littlewhite1989/article/details/39718105)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值