forked from adonis0147/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
263 lines (201 loc) · 6.25 KB
/
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable plugins
try
source ~/.vim/plugins.vim
source ~/.vim/plugins_config.vim
catch
endtry
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Automatically source the .vimrc when it is saved
autocmd! bufwritepost .vimrc source %
" Not compatible with vi
set nocompatible
" Automatically read a file when it is changed from the outside
set autoread
" No backup files
set nobackup
set nowritebackup
set noswapfile
" Use mouse in all mode
set mouse=a
" Encoding
set encoding=utf-8
set termencoding=utf-8
set fileencodings=utf-8,gb2312
" File formats
set fileformats=unix,dos,mac
" timeout
set timeoutlen=500
" Hide a buffer when it is abandoned
set hidden
" To toggle the paste mode
set pastetoggle=<F2>
" Set the clipboard
"set clipboard=unnamedplus
" History
set history=700
" Undo
set undolevels=700
" Don't redraw while executing macros
"set lazyredraw
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" User Interface "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Only toggle a menu when using complete
set completeopt=menu
" Show line number
set number
" Show the current postion
set ruler
" Show the status line
set laststatus=2
" Show matching brackets
set showmatch
" The time of blinking when matching brackets
set matchtime=0
" Enable syntax highlighting
syntax on
" Set colors
set t_Co=256
" colorscheme
try
colorscheme molokai
catch
colorscheme desert
endtry
highlight MatchParen ctermbg=None ctermfg=Red cterm=bold
highlight Conceal ctermbg=None
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text, Tab, Indent, Backspace "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text width
set textwidth=80
" Color the column 80
set colorcolumn=80
highlight ColorColumn ctermbg=235
highlight link OverLength ColorColumn
exec 'match OverLength /\%'.&cc.'v.\+/'
" Don't automatically wrap on load
set nowrap
" Don't automatically wrap text when typing
set fo-=t
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs
set smarttab
" Tab width
set tabstop=4
set softtabstop=4
" Shift
set shiftwidth=4
set shiftround
" Auto indent
set autoindent
" Smart indent
set smartindent
" Backspace
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Search "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Using regular expressions easily
set magic
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map j gj
map k gk
" Disable highlight
noremap <silent> <leader><cr> :noh<cr>
" Quick quit command
nnoremap <leader>e :quit<cr>
nnoremap <leader>E :qa!<cr>
" Easier moving between windows
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
" Easier moving between tabs
nnoremap <leader>n <esc>:tabprevious<cr>
nnoremap <leader>m <esc>:tabnext<cr>
" Easier moving of code blocks
vnoremap < <gv
vnoremap > >gv
" Copy content to clipboard
vnoremap <c-c> y:call CopyToClipboard()<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocmd, Helper Functions "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Indent
autocmd FileType c,cpp set cindent
autocmd FileType html,xhtml setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType css setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType javascript setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType php setlocal tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType ruby setlocal tabstop=2 softtabstop=2 shiftwidth=2
" Colorcolumn
autocmd FileType php setlocal textwidth=120 colorcolumn=120
autocmd FileType php exec 'match OverLength /\%'.&cc.'v.\+/'
autocmd FileType markdown highlight clear ColorColumn
" Build and run(just available for a single source code)
autocmd FileType c imap <F9> <esc>:w<cr>:!clear && gcc % -o %< && ./%<<cr>
autocmd FileType c nmap <F9> :w<cr>:!clear && gcc % -o %< && ./%<<cr>
autocmd FileType cpp imap <F9> <esc>:w<cr>:!clear && g++ % -o %< && ./%<<cr>
autocmd FileType cpp nmap <F9> :w<cr>:!clear && g++ % -o %< && ./%<<cr>
autocmd FileType python imap <F9> <esc>:w<cr>:!clear && python %<cr>
autocmd FileType python nmap <F9> :w<cr>:!clear && python %<cr>
autocmd FileType ruby imap <F9> <esc>:w<cr>:!clear && ruby %<cr>
autocmd FileType ruby nmap <F9> :w<cr>:!clear && ruby %<cr>
autocmd FileType sh imap <F9> <esc>:w<cr>:!clear && bash %<cr>
autocmd FileType sh nmap <F9> :w<cr>:!clear && bash %<cr>
" Make
autocmd FileType c,cpp imap <F5> <esc>:w<cr>:copen<cr>:make<cr>
autocmd FileType c,cpp nmap <F5> :w<cr>:copen<cr>:make<cr>
"autocmd QuickFixCmdPost * :copen
" filetype settings
let g:tex_flavor = 'latex'
autocmd bufread,bufnewfile *.md :set filetype=markdown
" Delete trailing white space on save, useful for Python
function! DeleteTrailingWS()
if index(['markdown'], &ft) == -1
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
end
endfunction
autocmd! bufwritepre * :call DeleteTrailingWS()
" Auto generate tags
function! CreateTags()
:silent !ctags -R
exec "redraw!"
endfunction
"autocmd! bufwritepost *.h,*.c,*.cpp call CreateTags()
" Copy content to clipboard
function! CopyToClipboard()
python << EOF
import vim
from subprocess import Popen, PIPE
try:
p = Popen(['xsel', '-bi'], stdin=PIPE)
p.communicate(input=vim.eval('@0'))
print('yanked')
except:
vim.command('echohl Error')
error = "The content isn't yanked, please install xsel to your system."
vim.command('echoerr "%s"' % error)
vim.command('echohl None')
EOF
endfunction