最近在自己学习使用Vim,查阅了一些资料,发现可以将Vim配置的很强大,以下是我自己添加的一些Vim配置,首先先要输入vim ~/.vimrc来进入vimrc文件。
1 set nu "显示当前行号
2
3 set shiftwidth=4 "Tab空四个字符,并且自动对齐(首行缩进)
4 set softtabstop=4
5 set autoindent
6
7 "自动补全
8 inoremap ( ()<ESC>i
9 inoremap ) <c-r>=ClosePair(')')<CR>'')
10 inoremap [ []<ESC>i
11 inoremap ] <c-r>=ClosePair(']'<CR>'')
12 inoremap { {}<ESC>i
13 inoremap } <c-r>=ClosePair('}'<CR>'')
14 inoremap " ""<ESC>i
15 inoremap ' ''<ESC>i
16
17 "在vim的普通模式下 空格+e 快捷键实现快速添加另一个vim
18 nnoremap <space>e : tabe
19
20 "在vim的插入模式中,按jk保存并退出"
21 inoremap jk <esc> : wq<cr>
22
23 "语法高亮"
24 syntax on
25
26 "用浅色高亮当前行"
27 autocmd InsertLeave * se nocul
28 autocmd InsertEnter * se cul
29
30 "输入的命令显示出来"
31 set showcmd
32
33 "允许折叠"
34 set foldenable
35
36 "手动折叠"
37 set foldmethod=manual
38
39 "显示中文帮助
40 if version>=603
41 set helplang=cn
42 set encoding=utf-8
43 endif
44
45 "新建.c .cpp .sh 文件,自动插入头文件
46 autocmd BufNewFile *.cpp,*.c,*.[ch],*.sh,*.java exec ":call SetTitle()"
47 func SetTitle()
48 if &filetype == 'sh'
49 call setline(1,"\##############")
50 call append(line("."),"\# File Name:".expand("%"))
51 call append(line(".")+1,"\# Autor:ma6174")
52 call append(line(".")+2,"\# mail:ma6174@613.com")
53 call append(line(".")+3,"\# Created Time:".strftime("%c"))
54 call append(line(".")+4,"\#############")
55 call append(line(".")+5,"")
56 endif
57
58 if &filetype == 'cpp'
59 call setline(1,"#include<iostream>")
60 call append(line("."),"\using namespace std;")
61 call append(line(".")+1,"")
62 endif
63
64 if &filetype == 'c'
65 call setline(1,"#include<stdio.h>")
66 call append(line("."),"")
67 endif
68
71 autocmd BufNewFile * normal G
74 set go=
75
76 "设置背景主题"
77 ""color asmanian2
78 "设置字体
79 set guifont=Courier_New:h10:cANSI
80 "显示标尺
81 set ruler
82 "命令行的高度设置为1
83 set cmdheight=1
84 "光标移动到buffer的顶部和底部时保持三行距离"
85 set scrolloff=3
86 "不要闪烁
87 set novisualbell
88 "状态行显示的内容"
90
91 "显示中文帮助"
92 if version >=603
93 set helplang=cn
94 set encoding=utf-8
95 endif
96
97 "设置配色方案"
98 ""colorscheme murphy
99
100 set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
101 set termencoding=utf-8
102 set fileencodings=ucs-bom,utf-8,cp936
103 set fileencoding=utf-8
104
105
106 ""键盘命令
107 ""nmap <leader>w :w!<cr>
108 ""nmap <leader>f :find<cr>
109
110 ""map <C-A> ggVGY
111 ""map! <C-A> <Esc>ggVGY
112 ""map <F12> gg=G
113
114 ""vmap <C-c> "+y
115
116 "F5进行编译运行"
117 map <F5> :call CompileRunGcc()<CR>
118 func! CompileRunGcc()
119 exec "w"
120 if &filetype =='c'
121 exec "!g++ % -o %<"
122 exec "! ./%<"
123 elseif &filetype =='cpp'
124 exec "!g++ % -o %<"
125 exec "! ./%<"
126 elseif &filetype =='java'
127 exec "!javac %"
128 exec "!java %<"
129 elseif &filetype =='sh'
130 :!./%
131 endif
132 endfunc
133
134 "F8进行调试"
135 map <F8> :call Rungdb()<CR>
136 func! Rungdb()
137 exec "w"
138 exec "!g++ % -g -o %<"
139 exec "!gdb ./%<"
140 endfunc