-
Notifications
You must be signed in to change notification settings - Fork 4
/
allrc.vim
executable file
·231 lines (199 loc) · 6.25 KB
/
allrc.vim
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
set nocompatible
filetype off
filetype plugin indent on
" use lazyredraw to speed things up. Ruby syntax highlight is too slow wihtout this
set lazyredraw
autocmd VimEnter * redraw! " workaround for missing statusline when entering vim in some terminals
syntax enable
set mouse=a " enable mouse mode in terminal
" copy selected text by default on click release
vmap <2-LeftRelease> "*ygv
vmap <3-LeftRelease> "*ygv
""""""""""""""""""""""""""""""
" Default tab and indent
""""""""""""""""""""""""""""""
" expand tab to spaces
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" For special file type
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
autocmd FileType haml setlocal expandtab shiftwidth=2 softtabstop=2
autocmd FileType dokuwiki setlocal expandtab shiftwidth=2 softtabstop=2
autocmd FileType terraform setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
autocmd FileType nix setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
""""""""""""""""""""""""""""""
" Ruby syntax highlight is horrible in Vim
""""""""""""""""""""""""""""""
autocmd FileType ruby set regexpengine=1 foldmethod=manual norelativenumber nocursorline
\ expandtab tabstop=2 softtabstop=2 shiftwidth=2
""""""""""""""""""""""""""""""
" Jenkinsfile highlight
""""""""""""""""""""""""""""""
au BufNewFile,BufRead Jenkinsfile setf groovy
"show tab
set list
" start with ▸ and fill the remaining with spaces
set listchars=tab:▸\ " we have an extra space at the end
set autoindent
set cindent
" enable true color in terminal
set termguicolors
" persistent undo support
if !isdirectory($HOME."/.vim/undo-dir")
call mkdir($HOME."/.vim/undo-dir", "", 0700)
endif
set undodir=~/.vim/undo-dir
set undofile
set nu
" set scroll offset
set so=7
" highlight current line
set cursorline
" highlight colorcolumn 100
if exists('+colorcolumn')
set colorcolumn=100
highlight ColorColumn guibg=#333333
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>100v.\+', -1)
endif
" 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set ignorecase smartcase
" 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存
set hidden
"set the number of changes that are remembered
set undolevels=200
set modifiable
set write
set foldcolumn=1
" find tags file recursively from current directory to root directory
set tags=tags;
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" For search
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set hlsearch
set incsearch "search every word you type
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
map <silent> <leader><cr> :noh<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Auto motion for vim
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" change working dir to folder that hosts current file being edited
set autochdir
" Set to auto read when a file is changed from the outside
set autoread
" reload vimrc when it is changed
autocmd! BufWritePost .vimrc,.gvimrc,allrc.vim
\ if has("gui_running") |
\ source $MYGVIMRC |
\ else |
\ source $MYVIMRC |
\ endif
" auto disable input method
autocmd! InsertLeave * set imdisable
autocmd! InsertEnter * set noimdisable
""""""""""""""""""""""""""""""
" Some other mappings
""""""""""""""""""""""""""""""
" switch between two windows
nmap <leader><TAB> :wincmd p<cr>
"Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :call ToggleSpellCheck()<cr>
"toggle hex mode
map <leader>h :call ToggleHexMode()<cr>
"Fast saving
nmap <leader>w :w!<cr>
imap <C-s> <esc>:w<cr>a
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
""""""""""""""""""""""""""""""""
" Command mode related mappings
""""""""""""""""""""""""""""""""
"Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>
cnoremap <C-P> <Up>
cnoremap <C-N> <Down>
cnoremap <C-F> <Right>
cnoremap <C-B> <left>
"""""""""""""""""""""""""""""""""""""
" Abbreviations for spelling correct
"""""""""""""""""""""""""""""""""""""
function! ToggleSpellCheck()
setlocal spell!
highlight SpellBad ctermfg=1 guifg=#BF616A gui=underline
highlight SpellCap ctermfg=1 guifg=#BF616A gui=underline
highlight SpellLocal ctermfg=1 guifg=#BF616A gui=underline
highlight SpellRare ctermfg=1 guifg=#BF616A gui=underline
endfunction
iab szie size
iab SZIE SIZE
""""""""""""""""""""""""""""""
" Statusline
""""""""""""""""""""""""""""""
set encoding=utf-8 " Necessary to show unicode glyphs
function! CurDir()
let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")
return curdir
endfunction
function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction
""""""""""""""""""""""""""""""
" Toggle hex mode
""""""""""""""""""""""""""""""
let s:hexMode = "N"
function! ToggleHexMode()
if s:hexMode == "Y"
%!xxd -r
let s:hexMode = "N"
else
%!xxd
let s:hexMode = "Y"
endif
endfunction
""""""""""""""""""""""""""""""
" Place holder
""""""""""""""""""""""""""""""
nnoremap <c-j> /<+.\{-1,}><cr>c/+>/e<cr>
inoremap <c-j> <ESC>/<+.\{-1,}><cr>c/+>/e<cr>
""""""""""""""""""""""""""""""
" Font size helper function
" From: http://vim.wikia.com/wiki/Change_font_size_quickly
""""""""""""""""""""""""""""""
let s:pattern = '^\(.* \)\([1-9][0-9]*\)$'
let s:minfontsize = 6
let s:maxfontsize = 16
function! AdjustFontSize(amount)
if has("gui_gtk2") && has("gui_running")
let fontname = substitute(&guifont, s:pattern, '\1', '')
let cursize = substitute(&guifont, s:pattern, '\2', '')
let newsize = cursize + a:amount
if (newsize >= s:minfontsize) && (newsize <= s:maxfontsize)
let newfont = fontname . newsize
let &guifont = newfont
endif
else
echoerr "You need to run the GTK2 version of Vim to use this function."
endif
endfunction
function! LargerFont()
call AdjustFontSize(1)
endfunction
command! LargerFont call LargerFont()
function! SmallerFont()
call AdjustFontSize(-1)
endfunction
command! SmallerFont call SmallerFont()
""""""""""""""""""""""""""""""
" disable the stupid ex mode
""""""""""""""""""""""""""""""
nnoremap Q <Nop>