从零开始配置vim

今天主要记录一下有关编辑器之神--vim的配置。主要用于给想使用vim的孩子一个好的开端。也是为了给自己留一个笔记。
这里先上一下我已经配置好的vim


MacVim

这里能显示出来的部分只有一个NerdTree和TagBar,然后就是下面的一条powerline,但实际上还有很多当前界面没有体现出来的部分,vim在可扩展性和定制化程度上有相当大的发展空间,尤其是在编写代码的时候,更能体会到vim的强大。


教程谈不上,只能说自己的配置过程

环境说明
系统:macOS
终端:iTerm2
编辑器:Vim/MacVim

  • 安装vim/MacVim
  • 编辑配置文件.vimrc
  • 安装插件

macOS用户可以使用MacVim,其实macOS已在terminal里自带vim,但是版本较低,所以建议使用最新的MacVim(此建议仅代表个人观点)。Windows用户可以使用gVim。其配置过程及方法大同小异。

首先我们可以通过Homebrew安装MacVim, 然后在terminal中输入:
brew install macvim
安装完成后,在terminal中输入mvim此时就可以打开MacVim界面了。但是一开始的vim非常的“质朴”,什么都没有。
这时就需要我们去改造他了。
要说明的一点是Vim有一个配置文件叫.vimrc, 实际上是一个隐藏文件,你只需要在终端的~目录中输入vim .vimrc就可以编辑这个文件了。


.vimrc文件里有vim自带的属性设置,也有包括插件的设置,这里先写vim自带的属性设置

set enc=utf-8
set langmenu=zh_CN.UTF-8
set fileencoding=utf-8
set fileencodings=utf-8
set nu
set go=
set showcmd
set ruler
set clipboard+=unnamed
syntax on
set autoindent
set smartindent
set smarttab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set helplang=cn
set viminfo+=!
set showmatch
set ignorecase
set autochdir
set magic
set autowrite
set autoread
set showmode
set noswapfile
set nobackup
set hlsearch
set incsearch
set cursorcolumn
set cursorline
set paste

实际上这些属性的意思都不难理解,都是一些比较基本的配置,接下来就需要配置插件,让vim更加适合自己。
vim的插件有很多,这里只写到了我自己用的一些插件,还有其他的完全可以自己配置。


这里使用的是Vundle插件管理工具,安装方法戳戳这里,安装Vundle很简单,在terminal中输入
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
接下来将如下代码写到.vimrc文件的顶部

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中输入:PluginInstall就可以自动安装插件。


接下来就要安装自己喜欢的插件就可以了,方法依然是在.vimrc文件中写入需要的插件,在vim中用:PluginInstall安装。这里介绍几个常用的神器

  1. emmet--写前端的神器,具体使用方法可以参考这里,非常实用,在.vimrc文件的相应位置写入Plugin 'mattn/emmet-vim'.

  2. NerdTree -- 文件浏览,这里是GitHub上的内容,在.vimrc文件的相应位置写入Plugin 'scrooloose/nerdtree'

  3. tagbar -- 代码架构浏览,这里是GitHub上的内容,在.vimrc文件的相应位置写入Bundle 'majutsushi/tagbar'

  4. neocomplete -- 代码补全神器,这个玩意儿要按照GitHub上的内容一步一步摸索,链接放这里,一定要有耐心去探索,在.vimrc文件的相应位置写入Bundle 'shougo/neocomplete.vim'

还有其他的一些好用的插件就不一一介绍了,后面我会把自己的使用的插件列表放在下面,需要的可以自行在GitHub上查看使用方法。

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'scrooloose/nerdtree'
Bundle 'jistr/vim-nerdtree-tabs'
Plugin 'mattn/emmet-vim'
Plugin 'rizzatti/dash.vim'
Bundle 'majutsushi/tagbar'
Plugin 'vim-scripts/indentpython.vim'
Bundle 'minibufexpl.vim'
Bundle 'Lokaltog/vim-powerline'
Bundle 'terryma/vim-multiple-cursors'
Bundle 'Raimondi/delimitMate'
Bundle 'hail2u/vim-css3-syntax'
Bundle 'othree/html5.vim'
Bundle 'docunext/closetag.vim'
Bundle 'gregsexton/MatchTag'
Bundle 'tpope/vim-surround'
Bundle 'bronson/vim-trailing-whitespace'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Bundle 'rstacruz/vim-ultisnips-css'
Bundle 'othree/javascript-libraries-syntax.vim'
Plugin 'scrooloose/nerdcommenter'
Bundle 'shougo/neocomplete.vim'
Bundle 'https://github.com/gorodinskiy/vim-coloresque.git'
Plugin 'Yggdroot/LeaderF'

call vundle#end()

安装好插件之后可以根据自己的实际情况修改快捷键,依旧是在.vimrc文件中修改。

基本上自己的配置过程就是这样了,后面还需要自己去经常使用和练习才能把vim玩弄于股掌之间。
希望这篇文章能对感兴趣的同学有所帮助。

你可能感兴趣的:(从零开始配置vim)