Vim的所有配置都是写在.vimrc这个文件里的,我们先创建该文件。
cd ~
touch .vimrc
vim .vimrc
- 创建完成后,写入一些基础配置,引号内是注释:
"去掉vi的一致性"
set nocompatible
"显示行号"
set number
" 隐藏滚动条"
set guioptions-=r
set guioptions-=L
set guioptions-=b
"隐藏顶部标签栏"
set showtabline=0
"设置字体"
set guifont=Monaco:h13
syntax on "开启语法高亮"
let g:solarized_termcolors=256 "solarized主题设置在终端下的设置"
set background=dark "设置背景色"
colorscheme solarized
set nowrap "设置不折行"
set fileformat=unix "设置以unix的格式保存文件"
set cindent "设置C样式的缩进格式"
set tabstop=4 "设置table长度"
set shiftwidth=4 "同上"
set showmatch "显示匹配的括号"
set scrolloff=5 "距离顶部和底部5行"
set laststatus=2 "命令行为两行"
set fenc=utf-8 "文件编码"
set backspace=2
set mouse=a "启用鼠标"
set selection=exclusive
set selectmode=mouse,key
set matchtime=5
set ignorecase "忽略大小写"
set incsearch
set hlsearch "高亮搜索项"
set noexpandtab "不允许扩展table"
set whichwrap+=<,>,h,l
set autoread
set cursorline "突出显示当前行"
set cursorcolumn "突出显示当前列"
- 安装Vim的插件管理器Vundle
首先从github上获取项目的源码,在终端里输入:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
通常会帮你创建Vundle.vim文件及其所属的文件夹,如果提示目录不存在,那就自己手动创建一个:
cd ~
mkdir .vim
cd .vim
mkdir bundle
当获取源码成功后,在.vimrc文件里添加配置:
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
"此处添加所要安装的Vim插件"
call vundle#end()
filetype plugin indent on
例如,我们在上述call vundle#begin()
和call vundle#end()
之间添加:
Plugin 'VundleVim/Vundle.vim' "vundle插件"
Plugin 'Valloric/YouCompleteMe' "自动补全"
Plugin 'nathanaelkane/vim-indent-guides' "缩进显示"
Plugin 'fholgado/minibufexpl.vim' "操作多个文件"
Plugin 'Yggdroot/indentLine' "缩进指示线"
Plugin 'scrooloose/nerdtree' "树形目录配置"
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'majutsushi/tagbar' "显示文件的类、函数、变量"
Plugin 'dyng/ctrlsf.vim'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'MattesGroeger/vim-bookmarks'
Plugin 'vim-syntastic/syntastic' "语法检查"
- 以下将给出一些插件的配置方法
1.indentLine缩进插件配置
let g:indentLine_char = "┆"
let g:indentLine_enabled = 1
let g:autopep8_disable_show_diff=1
2.syntastic语法检查插件配置
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 = 0
let g:syntastic_check_on_wq = 0
let g:syntastic_mode_map = {'mode': 'passive', 'active_filetypes': [], 'passive_filetypes': []}
" Use pylint to check python files.
let g:syntastic_python_checkers = ['pylint']
map :SyntasticToggleMode :SyntasticCheck
" Ignore warnings about newlines trailing.
let g:syntastic_quiet_messages = { 'regex': ['trailing-newlines', 'invalid-name',
\'too-many-lines', 'too-many-instance-attributes', 'too-many-public-methods',
\'too-many-locals', 'too-many-branches'] }
3.NERDTree左侧树形目录插件配置
map :NERDTreeToggle
let NERDTreeChDirMode=1
let NERDTreeShowBookmarks=1
let NERDTreeWinSize=25
let NERDTreeShowHidden=1
let NERDTreeIgnore=['\~$', '\.pyc$', '\.swp$', '\.git$']
4.tagbar显示文件的类、函数、变量插件快捷方式配置
map :TagbarToggle
5.ctrlp.vim在项目中快速定位文件插件
map :CtrlP
引用文章
优雅的在终端中编写python
如果文章中有错误,请留言,谢谢~