手头的Python学习资料都是2.7版本的,但是我的物理机上装的是3.5。正好趁机练习一下神器vim的使用,原始的版本太简陋了,对于我这种用惯了重量级IDE的小菜,实在是难以适应。。。自己动手改造一波~~

安装插件管理器Vundle

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

按照github上的说明进行安装:

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

这个命令会在Home目录下创建.vim目录

  • 0x02
    在Home目录下创建.vimrc文件,将/etc/vim/vimrc中的内容复制过来,然后在后面添加如下内容(以后可能会有改变,以GitHub上的为准)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    set nocompatible              " be iMproved, required
    filetype off " required

    " set the runtime path to include Vundle and initialize
    set rtp+=~/.vim/bundle/Vundle.vim
    call vundle#begin()
    " alternatively, pass a path where Vundle should install plugins
    "call vundle#begin('~/some/path/here')

    " let Vundle manage Vundle, required
    Plugin 'VundleVim/Vundle.vim'

    " The following are examples of different formats supported.
    " Keep Plugin commands between vundle#begin/end.
    " plugin on GitHub repo
    Plugin 'tpope/vim-fugitive'
    " plugin from http://vim-scripts.org/vim/scripts.html
    Plugin 'L9'
    " Git plugin not hosted on GitHub
    Plugin 'git://git.wincent.com/command-t.git'
    " git repos on your local machine (i.e. when working on your own plugin)
    Plugin 'file:///home/gmarik/path/to/plugin'
    " The sparkup vim script is in a subdirectory of this repo called vim.
    " Pass the path to set the runtimepath properly.
    Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
    " Install L9 and avoid a Naming conflict if you've already installed a
    " different version somewhere else.
    Plugin 'ascenator/L9', {'name': 'newL9'}

    " All of your Plugins must be added before the following line
    call vundle#end() " required
    filetype 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打开任意文件,命令模式输入:PluginList,安装成功的话会看到插件列表。使用:PluginInstall安装列表中的插件,安装哪些插件可以在.vimrc上配置。其他命令在贴出的这个配置文件中都有,不再多扯了。

安装括号、引号等符号匹配插件auto-pairs

GitHub:https://github.com/jiangmiao/auto-pairs

  • 0x01
    git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs
  • 0x02
    编辑.vimrc,加上Bundle 'auto-pairs',用vim打开任意一个文件,命令模式下输入:PluginList,发现list中已经有该插件,:PluginInstall即可安装。

安装代码补全插件YouCompleteMe

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

  • 0x01
    编辑.vimrc文件,添加Plugin 'Valloric/YouCompleteMe',直接:PluginInstall,vundle会自动从github上下载,速度可能会有一点慢。
  • 0x02
    一般的插件到这一步就可以了。但是ymc这种神器级的总要坑你一回,需要手工编译。
    cd .vim/bundle/YouCompleteMe/
    chmod +x install.py #本来是.sh,但是它提示使用py文件
    ./install.py --clang-completer #如果需要C#补全的话就加上后面的参数
    然后报错(手动捂脸。。),提示需要安装cmake。好吧。。
    apt-get install camke
    安装成功~
  • 0x03
    具体的配置在这里https://github.com/Valloric/YouCompleteMe/option#已经说得很详细了,一般采用默认的就好。
    只是有一点,坑了我很久。。。。在进行代码补全的时候,会在上面出现一个函数说明的框,占了好多编辑的地方,百度了半天没有结果,最后在配置说明的最后看到了解决方法,在这里记一下。。。。。
    在.vimrc文件中添加
  1. let g:ycm_autoclose_preview_window_after_completion = 1 说明会在代码补全之后关闭
  2. let g:ycm_autoclose_preview_window_after_insertion = 1 说明会在退出插入模式时关闭
  3. set completeopt-=preview 直接关闭,不会再出现。但是需要let g:ycm_add_preview_to_completeopt = 0(默认为0)

这个插件算是整了个差不多了。。。。。

其他的一些常用配置

syntax on 代码高亮
set tabstop=4 设置tab为4个空格
set softtabstop=4
set shiftwidth=4
set autoindent
set cindent
set number 设置行号
set hlsearch
set backspace=2

配好之后要好好敲代码了。。。