mac vim 配置(生产力工具)

2018-02-25  本文已影响0人  qishuai

vim是我经常使用的工具,但他的功能太简陋了,连代码高亮都没有,实在影响效率;之前也配置过vim,但是失败了,这次实在忍不了了,周末花几个小时时间配置一下,配置完之后果然很爽。现在vim能做:代码高亮、自动补全c++/golang/js代码、文件快速定位、语法检测。

安装列表:

安装步骤:

  1. 安装Vundle,插件管理软件

     git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
    
  2. 安装YouCompleteMe

     cd ~/.vim/bundle
     git clone https://github.com/Valloric/YouCompleteMe.git
     cd YouCompleteMe
             git submodule update --init --recursive
             brew install cmake
     ./install.py --clang-completer --go-completer --js-completer
    
  3. 安装syntastic

     mkdir -p ~/.vim/autoload && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
    

    如果以上命令没有反应,可以使用以下方法补救:

     //浏览器打开以下链接
     https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim
     cd ~/.vim/autoload
     touch pathogen.vim
     vim pathogen.vim
     // 手动复制网页上的内容,到该文件中,保存退出即可
    
  4. 安装NERD_tree

     git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
    
  5. 安装command-t

     git clone https://github.com/wincent/command-t.git ~/.vim/bundle/command-t
    
  6. 安装vim-gitgutter

     git clone git://github.com/airblade/vim-gitgutter.git ~/.vim/bundle/vim-gitgutter
    
  7. 安装ctags,mac默认已经安装了ctags,如果没有通过以下命令安装

     brew install ctags
    
  8. 安装taglist,去浏览器下载:https://sourceforge.net/projects/vim-taglist/files/

     unzip taglist_45.zip
     cd taglist_45
     cp -r ./doc ~/.vim/
     cp -r ./plugin  ~/.vim/
     cd ~/.vim/plugin
     vim taglist.vim
     //在if !exists('loaded_taglist')上一行输入:
     let Tlist_Ctags_Cmd="/usr/local/bin/ctags"
    

    运行 ctags -R

  9. 将文章末尾代码复制到~/.vimrc中

     vim
     :PluginInstall
    

我的配置文件:

set guifont=Darcula:h52
let g:ycm_global_ycm_extra_conf='~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'

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

Plugin 'VundleVim/Vundle.vim'
Plugin 'Scrooloose/nerdtree'
Plugin 'airblade/vim-gitgutter'
Plugin 'vim-syntastic/syntastic'
Plugin 'wincent/command-t'
Plugin 'Valloric/YouCompleteMe'
Plugin 'SirVer/ultisnips'

call vundle#end()
filetype plugin indent on

" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"

"NERDTree
"F2开启和关闭树"
"map <F2> :NERDTreeToggle<CR>
"let NERDTreeChDirMode=1
""显示书签"
"let NERDTreeShowBookmarks=1
"设置忽略文件类型"
"let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$']
""窗口大小"
"let NERDTreeWinSize=25

"indentLine
"缩进指示线"
let g:indentLine_char='|'
let g:indentLine_enabled=1

set number
set ruler
set history=1000
set showcmd
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
set laststatus=2
syntax on
set fileencodings=utf-8,gb2312,gbk,cp936,latin-1
set fileencoding=utf-8
set termencoding=utf-8
set fileformat=unix
set encoding=utf-8
colorscheme desert
set t_Co=256

set wildmenu

set nocompatible
set backspace=indent,eol,start
set backspace=2

set autoindent

set smartindent

set nobackup
set nowritebackup
set noswapfile

set expandtab

set tabstop=4

set softtabstop=4

set shiftwidth=4

set helplang=cn

set showmatch

au FileType html,python,vim,javascript setl shiftwidth=4
au FileType html,python,vim,javascript setl tabstop=4
au FileType java,php setl shiftwidth=4
au FileType java,php setl tabstop=4
set hlsearch

filetype indent on

set cindent
set completeopt=longest,menu


set noeb
set autowrite
set cursorline
"if $TERM_PROGRAM =~ "iTerm"
let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
"endif
set clipboard+=unnamed
set autoread
set scrolloff=3
  1. 小技巧

使用鼠标定位

 set mouse=a

使用鼠标复制

  set mouse=v

vim如果没有指定打开的文件,指定开启NERDTree

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

如果窗口只剩下NERDTree时,自动关闭vim

  autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
上一篇 下一篇

猜你喜欢

热点阅读