forked from skywind3000/vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unix.vim
261 lines (221 loc) · 7.21 KB
/
unix.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
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
" just another setup file yet, some handy stuff
"----------------------------------------------------------------------
" Better setup for VIM 7.0 and later
"----------------------------------------------------------------------
filetype plugin indent on
set hlsearch
set incsearch
set wildmenu
set ignorecase
set cpo-=<
set lazyredraw
set errorformat=%.\ %#-->\ %f:%l:%c,%f(%l):%m,%f:%l:%c:%m,%f:%l:%m
set vop=folds,cursor
set fdm=indent
set foldlevel=99
set tags=./.tags;,.tags
set history=2000
set viminfo+=!
if has('patch-8.1.1300')
set shortmess-=S
endif
noremap <tab>/ :emenu <C-Z>
"----------------------------------------------------------------------
" Include Scripts
"----------------------------------------------------------------------
let s:home = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
" IncScript / IncRtp
if !exists(':IncScript')
command! IncScript -nargs=1 exec 'so ' . fnameescape(s:home .'/<args>')
endif
if !exists(':IncRtp')
command! -nargs=1 IncRtp exec 'set rtp+='.s:home.'/'.'<args>'
endif
"----------------------------------------------------------------------
" turn latest features
"----------------------------------------------------------------------
" Enable vim-diff-enhanced (Christian Brabandt)
if has('patch-8.2.0001')
set diffopt+=internal,algorithm:patience
set diffopt+=indent-heuristic
endif
" complete option
if has('patch-8.0.1000')
set completeopt=menu,menuone,noselect
else
set completeopt=menu,menuone
endif
" new blowfish2
if has('patch-7.4.500') || v:version >= 800
if !has('nvim')
set cryptmethod=blowfish2
endif
endif
" enable new-style cursorline (for numbers only)
if exists('+cursorlineopt')
set cursorlineopt=number cursorline
endif
"----------------------------------------------------------------------
" fixed cursor shaping compatible issues for some terminals
"----------------------------------------------------------------------
if has('nvim')
set guicursor=
elseif (!has('gui_running')) && has('terminal') && has('patch-8.0.1200')
let g:termcap_guicursor = &guicursor
let g:termcap_t_RS = &t_RS
let g:termcap_t_SH = &t_SH
set guicursor=
set t_RS=
set t_SH=
endif
" restore last position
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" DiffOrig command
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
"----------------------------------------------------------------------
" use ~/.vim/tmp as backup directory
"----------------------------------------------------------------------
if get(g:, 'asc_no_backup', 0) == 0
set backup
set writebackup
set backupdir=~/.vim/tmp
set backupext=.bak
set noswapfile
set noundofile
let path = expand('~/.vim/tmp')
if isdirectory(path) == 0
silent! call mkdir(path, 'p', 0755)
endif
endif
"----------------------------------------------------------------------
" autocmd group
"----------------------------------------------------------------------
augroup AscUnixGroup
au!
au FileType * call s:language_setup()
au User VimScope,VimMakeStart call vimmake#toggle_quickfix(6, 1)
au BufNewFile,BufRead *.as setlocal filetype=actionscript
au BufNewFile,BufRead *.pro setlocal filetype=prolog
au BufNewFile,BufRead *.es setlocal filetype=erlang
au BufNewFile,BufRead *.asc setlocal filetype=asciidoc
au BufNewFile,BufRead *.vl setlocal filetype=verilog
au BufNewFile,BufRead *.bxrc setlocal filetype=bxrc
au BufNewFile,BufRead *.odin setlocal filetype=odin
au BufNewFile,BufRead *.md setlocal filetype=markdown
au FileType lisp setlocal ts=8 sts=2 sw=2 et
au FileType scala setlocal sts=4 sw=4 noet
au FileType haskell setlocal et
augroup END
"----------------------------------------------------------------------
" language setup (on FileType autocmd)
"----------------------------------------------------------------------
function! s:language_setup()
" echom "FileType: " . &ft
if &ft == 'qf'
setlocal nonumber
endif
let tags = expand("~/.vim/tags/") . &ft . '.tags'
let dict = expand("~/.vim/dict/") . &ft . '.dict'
if filereadable(tags)
exec "setlocal tags+=" . fnameescape(tags)
endif
if filereadable(dict)
exec "setlocal dict+=" . fnameescape(dict)
endif
endfunc
" Persistent folding information
function! s:fold_restore(enable)
if a:enable == 'true' || a:enable == 'yes' || a:enable != 0
augroup VimUnixFoldGroup
au!
au BufWrite,VimLeave * silent! mkview
au BufRead * silent! loadview
augroup END
else
augroup VimUnixFoldGroup
au!
augroup END
endif
endfunc
command! -nargs=1 PersistFoldEnable call s:fold_restore(<q-args>)
" turn off number and signcolumn for terminal
if has('terminal') && exists(':terminal') == 2
if exists('##TerminalOpen')
augroup VimUnixTerminalGroup
au!
" au TerminalOpen * setlocal nonumber signcolumn=no
augroup END
endif
endif
" setup shell
if &shell =~# 'fish'
set shell=sh
endif
"----------------------------------------------------------------------
" Shougo
"----------------------------------------------------------------------
command! -range -nargs=1 AddNumbers
\ call s:add_numbers((<line2>-<line1>+1) * eval(<args>))
function! s:add_numbers(num)
let prev_line = getline('.')[: col('.')-1]
let next_line = getline('.')[col('.') :]
let prev_num = matchstr(prev_line, '\d\+$')
if prev_num != ''
let next_num = matchstr(next_line, '^\d\+')
let new_line = prev_line[: -len(prev_num)-1] .
\ printf('%0'.len(prev_num).'d',
\ max([0, prev_num . next_num + a:num])) . next_line[len(next_num):]
else
let new_line = prev_line . substitute(next_line, '\d\+',
\ "\\=printf('%0'.len(submatch(0)).'d',
\ max([0, submatch(0) + a:num]))", '')
endif
if getline('.') !=# new_line
call setline('.', new_line)
endif
endfunction
command! -nargs=0 Undiff setlocal nodiff noscrollbind wrap
command! -nargs=1 -complete=file DiffFile vertical diffsplit <args>
" Open junk file.
command! -nargs=0 JunkFile call s:open_junk_file()
function! s:open_junk_file()
let junk_dir = asclib#setting#get('junk', '~/.vim/junk')
let junk_dir = junk_dir . strftime('/%Y/%m')
let real_dir = expand(junk_dir)
if !isdirectory(real_dir)
call mkdir(real_dir, 'p')
endif
let filename = junk_dir.strftime('/%Y-%m-%d-%H%M%S.')
let filename = tr(filename, '\', '/')
let filename = input('Junk Code: ', filename)
if filename != ''
execute 'edit ' . fnameescape(filename)
endif
endfunction
command! -nargs=0 JunkList call s:open_junk_list()
function! s:open_junk_list()
let junk_dir = asclib#setting#get('junk', '~/.vim/junk')
" let junk_dir = expand(junk_dir) . strftime('/%Y/%m')
let junk_dir = tr(junk_dir, '\', '/')
echo junk_dir
exec "Leaderf file " . fnameescape(expand(junk_dir))
endfunction
command! -nargs=+ Log call s:quick_note(<q-args>)
function! s:quick_note(text)
let text = substitute(a:text, '^\s*\(.\{-}\)\s*$', '\1', '')
if exists('*writefile') && text != ''
let filename = get(g:, 'quicknote_file', '~/.vim/quicknote.md')
let notehead = get(g:, 'quicknote_head', '- ')
let notetime = strftime("[%Y-%m-%d %H:%M:%S] ")
let realname = expand(filename)
call writefile([notehead . notetime . text], realname, 'a')
checktime
echo notetime . text
endif
endfunc