我的VIM配置

个人非常喜欢Vim的工作方式,所以有时间会研究一下,
下面是我自己的一些配置,我暂时没有修改vim默认的vimrc文件。

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
set relativenumber      " Show relative numbers instead of absolute ones.
set nocompatible " Disable vi compatibility.
set undolevels=200 " Number of undo levels.
set scrolloff=10 " Keep a context (rows) when scrolling vertically.
set sidescroll=5 " Keep a context (columns) when scrolling horizontally.
set tabpagemax=1000 " Maximum number of tabs to open by the -p argument.
set esckeys " Cursor keys in insert mode.
set incsearch
set confirm " Ask to save file before operations like :q or :e fail.


" Allow backspacing over everything in insert mode.
set backspace=indent,eol,start

" Backup and swap files.
set nobackup " Disable backup files.
set noswapfile " Disable swap files.
set nowritebackup " Disable auto backup before overwriting a file.

" History
set history=1000 " Number of lines of command line history.
set viminfo='100,\"500,r/mnt,r~/mnt,r/media " Read/write a .viminfo file.
set viminfo+=h " Do not store searches.

" Splitting.
set splitright " Open new vertical panes in the right rather than left.
set splitbelow " Open new horizontal panes in the bottom rather than top.

" Security.
set secure " Forbid loading of .vimrc under $PWD.
set nomodeline " Modelines have been a source of vulnerabilities.

syntax on
filetype indent on " Turn off indention by filetype.
" Override the previous settings for all file types (some filetype plugins set
" these options to different values, which is really annoying).
au FileType * set autoindent nosmartindent nocindent fo+=q fo-=r fo-=o fo+=j
set laststatus=2

" Whitespace.
set tabstop=4 " Number of spaces a tab counts for.
set shiftwidth=4 " Number of spaces to use for each step of indent.
set shiftround " Round indent to multiple of shiftwidth.
set expandtab " Expand tab with spaces.

" Wrapping.
set wrap " Enable text wrapping.
set linebreak " Break after words only.
set display+=lastline " Show as much as possible from the last shown line.
set textwidth=0 " Don't automatically wrap lines.
" Disable automatic wrapping for all files (some filetype plugins set this to
" a different value, which is really annoying).
au FileType * set textwidth=0

"------------------------------------------------------------------------------
" Typos correction.
"------------------------------------------------------------------------------

if has("multi_byte")
" UTF-8 编码
set encoding=utf-8
set termencoding=utf-8
set formatoptions+=mM
set fencs=utf-8,gbk
if v:lang =~? '^/(zh/)/|/(ja/)/|/(ko/)'
set ambiwidth=double
endif
if has("win32")
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
language messages zh_CN.utf-8
endif
else
echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif

"---------------------------------------------
" 插件
"---------------------------------------------

" NERDTree

" 打开vim是自动打开NERDTree
" autocmd vimenter * NERDTree

" 打开编辑器时鼠标默认在编辑区域
autocmd vimenter * wincmd p

"如果打开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

" 快捷键设置
map <C-b> :NERDTreeToggle<CR>

"Powerline configuration
" set guifont=Consolas_for_Powerline_FixedD:h10:cANSI
" set guifont=Liberation_Mono_for_Powerline:h10
" set encoding=utf-8
set t_Co=256
let g:Powerline_symbols = 'fancy'
let Powerline_symbols = 'compatible'