"Pathogen
execute pathogen#infect()
syntax on
filetype plugin indent on
"Common
let mapleader=","
set helplang=cn
set fileencodings=8859-1,utf-8,gbk,cp936
set number
syntax enable
set laststatus=2
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
"NERDTree
nmap <C-e> :NERDTreeToggle<CR>
"Tagbar
nmap <leader>tt :TagbarToggle<CR>
let g:tagbar_left=1
let g:tagbar_width=60
"Airline
let g:airline#extensions#bufferline#enabled=0
let g:airline#extensions#tabline#enabled=1
let g:airline#extensions#tabline#show_buffers=1
let g:airline#extensions#tabline#buffer_nr_show=1
"Cscope
set cscopequickfix=s-,c-,d-,i-,t-,e-
nmap <C-c>g :cs find g <C-R><C-W><CR>
nmap <C-c>c :cs find c <C-R><C-W><CR>
if filereadable("cscope.out")
cs add cscope.out .
endif
"Grep
nnoremap <silent> <F3> :Grep<CR>
"CppTag
set tags+=~/.vim/tags/cpp
"ColorScheme
:colorscheme nove
插件:
插件的管理推荐pathogen(可以优先安装它),它使删除和添加插件更方便,.vim目录看着不乱。
好用的插件在vimrc中以"打头列出(包括ack/airline/ctrlp/easymotion/neocomplete/nerdtree/supertab/tagbar),可在github上直接搜索并使用git clone安装它们。
注1:关于自动补全(就是上头的neocomplete和supertab)有更好的替代品ycm(youcompleteme),但后者要求更高的vim版本(系统版本)。如果版本满足要求,
作者强烈推荐ycm。
这里单独讲一下ycm的安装(其他的插件全部使用git clone即可,很简单)。官方页:https://github.com/Valloric/YouCompleteMe
step1:git clone
step2:install build-essential cmake python-dev python3-dev step3:如果是使用的pathogen,不是vundle,那么需要手动克隆依赖仓。
let g:ycm_server_python_interpreter='/usr/bin/python'
let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'
step7:完事后发现c++的头文件无法自动补全,需要在ycm的配置文件(.ycm_extra_conf.py)的flags中添加c++的头文件(最后四行粗斜体):
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-fexceptions',
'-DNDEBUG',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-isystem',
'/usr/include',
'-isystem',
'/usr/local/include',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1',
'-isystem',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include', # ADD BY NOVE
# add c++ headers.
'-isystem',
'/usr/include/c++/5.4.0',
]
大功告成。
配色:
作者没能找到比较好的配色方案,目前作者使用的是:
http://bytefluent.com/vivify/
# GTEST ROOT DIR
# use this, do not copy gtest_root/include to each of your project.
GTEST_DIR = ~/nove/gtest/googletest-master/googletest
# Where to find user code.
CUR_DIR = $(shell pwd)
includes = -I $(CUR_DIR)/include\
-I $(GTEST_DIR)/include\
libs = -L lib\
link_libs = -lpthread\
-lgtest\
SRC_DIR = src\
# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem $(GTEST_DIR)/include
# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread --std=c++11
target = gogogo
files = $(foreach d, $(SRC_DIR), $(wildcard $(d)/*.cpp))
objects = $(patsubst %.cpp, %.o, $(files))
# House-keeping build targets.
$(target) : $(objects)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $^ -o $@ $(libs) $(link_libs)
%.o : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(includes) -c $^ -o $@
all : $(target)
clean :
rm -rf $(target)
rm -rf $(objects)