将Vim打造成服务器端IDE

仔细想了下,服务器端编程由于服务器(一般都是Linux)并不会装Eclipse,Visual Studio之类的IDE,所以用Vim还是比较好的选择,还能提高Coding(敲键盘)能力,固化编程式思维。

爱上Coding!

  • .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# ls color
export CLICOLOR=1;
export LSCOLORS=gxfxaxdxcxegedabagacad;

# command display
# export PS1="\u@\H \w\n\$ "
export PS1='\[\033[01;32m\]\u@\H\[\033[01;33m\] \w\[\033[34;40m\]\n> \[\033[00m\] '

# change open files -> 10000
ulimit -n 10000

# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
  • ctags

brew install ctags

(Centos: yum install ctags)

  • vundle
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
  • .vimrc.bundles

这个是vim vundle的配置文件。

set nocompatible              " be iMproved, required
filetype off                  " required

set rtp+=~/.vim/bundle/vundle/
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'taglist.vim'
Bundle 'winmanager'
Bundle 'The-NERD-tree'
Bundle 'The-NERD-Commenter'
" Bundle 'fholgado/minibufexpl.vim'
Bundle 'minibufexplorerpp'
Bundle 'Yggdroot/indentLine'
Bundle 'scrooloose/syntastic'
Bundle 'vim-scripts/pylint.vim'
call vundle#end()            " required
filetype plugin indent on    " required
  • .vimrc

这个是vim的配置文件,每次vim启动时都会逐条执行里面的配置选项。贴下我的通用配置 (还没有包含插件,按照下面的步骤增加插件会增加.vimrc中的内容):

" vundle bundles
if filereadable(expand("~/.vimrc.bundles"))
	source ~/.vimrc.bundles
endif

" my own settings
syn on "语法支持
set laststatus=2 "始终显示状态栏
set tabstop=4 "一个制表符的长度
set softtabstop=4 "一个制表符的长度(可以大于tabstop)
set shiftwidth=4 "一个缩进的长度
set expandtab "使用空格替代制表符
set smarttab "智能制表符
set autoindent "自动缩进
set smartindent "智能缩进
set number "显示行号
set ruler "显示位置指示器
set backupdir=/tmp "设置备份文件目录
set directory=/tmp "设置临时文件目录
set ignorecase "检索时忽略大小写
set hls "检索时高亮显示匹配项
set helplang=cn "帮助系统设置为中文
set foldmethod=syntax "代码折叠
set nobackup "不生成备份文件
set guifont=Courier\ New:h15 "设置字体
set nowrap "长句在一行显示
set encoding=utf-8

colorscheme pablo

" Tlist
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_Right_Window=1
let Tlist_Sort_Type = "name"
let Tlist_Auto_Open=1
nmap wt :Tlist<CR>

 " MiniBufExplorer
let g:miniBufExplMapWindowNavVim = 1   
let g:miniBufExplMapWindowNavArrows = 1   
let g:miniBufExplMapCTabSwitchBufs = 1   
let g:miniBufExplModSelTarget = 1  
let g:miniBufExplMoreThanOne=0

nmap be :MiniBufExplorer<CR>

" NERDTree
let g:NERDTree_title="[NERDTree]"

function! NERDTree_Start()
    exec 'NERDTree'
endfunction

function! NERDTree_IsValid()
    return 1
endfunction

" WinManager
let g:winManagerWindowLayout="NERDTree"

nmap wm :WMToggle<CR>

" Cscope
:set cscopequickfix=s-,c-,d-,i-,t-,e-

  • YouCompleteMe

安装最新vim:brew install vim

安装vundle: https://github.com/VundleVim/Vundle.vim#quick-start

cd ~/.vim/bundle/

git clone--recursive https://github.com/Valloric/YouCompleteMe.git 获取最新的仓库,而后使用git submodule update --init --recursive确认仓库的完整性。

在.vimrc中添加:

call vundle#begin()
. . . 
Plugin 'Valloric/YouCompleteMe'
. . .
call vundle#end()

编译YCM:

brew install CMake

cd ~/.vim/bundle/YouCompleteMe

./install.sh --clang-completer

vim

:BundleInstall

cp  ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py ~/.vim/

vim ~/.vim/.ycm_extra_conf.py

加上这些:

'-isystem',                                                                                                 
'/usr/include',                                                                                             
'-isystem',                                                                                                 
'/usr/local/include',                                                                                       
'-isystem',                                                                                                 
'/Library/Developer/CommandLineTools/usr/include',                                                          
'-isystem',                                                                                                 
'/Library/Developer/CommandLineTools/usr/bin/../lib/c++/v1',

注释掉:

#    try:

#      final_flags.remove( '-stdlib=libc++' )

#    except ValueError:

#      pass

return { 'flags': final_flags, 'do_cache': True }

vim .vimrc

" YouCompleteMe

let g:ycm_global_ycm_extra_conf='~/.vim/.ycm_extra_conf.py'

set completeopt=longest,menu    "让Vim的补全菜单行为与一般IDE一致(参考VimTip1228) 

autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口 

inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"    "回车即选中当前项

"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 locationlist
inoremap <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 = 0

let g:clang_user_options='|| exit 0' 

nnoremap <C-g> :YcmCompleter GoToDefinitionElseDeclaration<CR> " (Ctrl + g)跳转到定义处

" 另外:YCM提供的跳跃功能采用了vim的jumplist,往前跳和往后跳的快捷键为Ctrl+O以及Ctrl+I。

解决头文件找不到的问题:

在~/.vim/.ycm_extra_conf.py文件中加入:

# nginx                                                                                                   
'-isystem',
'/Users/zhangyaodong/Documents/Projects/Open/nginx-1.12.1/src/core',
'-isystem',
'/Users/zhangyaodong/Documents/Projects/Open/nginx-1.12.1/src/http',
'-isystem',
'/Users/zhangyaodong/Documents/Projects/Open/nginx-1.12.1/src/mail',
'-isystem',
'/Users/zhangyaodong/Documents/Projects/Open/nginx-1.12.1/src/os/unix',
'-isystem',
'/Users/zhangyaodong/Documents/Projects/Open/nginx-1.12.1/src/event',
'-isystem',
'/Users/zhangyaodong/Documents/Projects/Open/nginx-1.12.1/src/stream'

  • echofunc

http://www.vim.org/scripts/script.php?script_id=1735

下下来后直接扔 ~/.vim/plugin/, 需配合ctags,ctags -R --fields=+lS

MAC includes: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/

  • Syntastic

" syntastic,vundle是从git上下载插件的,配置中scrooloose是作者名,后面是repo
Bundle  'scrooloose/syntastic'

vim ~/.vimrc

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0

" 关闭Syntastic窗口:    :lclose  (在代码窗口,不是在Syntastic执行)

" 打开Syntastic窗口:    :lopen

  • pylint

sudo easy_install pylint

vim ~/.vimrc

Bundle 'vim-scripts/pylint.vim'

let g:syntastic_python_checkers=['pylint']
let g:syntastic_python_pylint_args='--disable=C0111,R0903,C0301'

  • 待研究

cscope (需要吗?)

easymotion

猜你喜欢

转载自blog.csdn.net/chunzhenzyd/article/details/76167848