From 65a9e840fd6526d732fb7d9e70a9a9f932c48f3e Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 3 Jan 2017 22:29:54 +0800 Subject: [PATCH 1/2] Move autocmds into autoload --- autoload/SpaceVim/autocmds.vim | 87 ++++++++++++++++++++++++++++++++++ config/main.vim | 2 +- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 autoload/SpaceVim/autocmds.vim diff --git a/autoload/SpaceVim/autocmds.vim b/autoload/SpaceVim/autocmds.vim new file mode 100644 index 000000000..5b56fdff8 --- /dev/null +++ b/autoload/SpaceVim/autocmds.vim @@ -0,0 +1,87 @@ +"autocmds +function! SpaceVim#autocmds#init() abort + augroup My_autocmds + au! + autocmd BufWinEnter quickfix nnoremap + \ q :cclose:lclose + autocmd BufEnter * if (winnr('$') == 1 && &buftype ==# 'quickfix' ) | + \ bd| + \ q | endif + autocmd FileType jsp call JspFileTypeInit() + autocmd FileType html,css,jsp EmmetInstall + autocmd FileType java call JavaFileTypeInit() + autocmd BufEnter,WinEnter,InsertLeave * set cursorline + autocmd BufLeave,WinLeave,InsertEnter * set nocursorline + autocmd BufReadPost * + \ if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal! g`\"" | + \ endif + autocmd BufNewFile,BufEnter * set cpoptions+=d " NOTE: ctags find the tags file from the current path instead of the path of currect file + autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full) + autocmd BufNewFile,BufRead *.avs set syntax=avs " for avs syntax file. + autocmd FileType text setlocal textwidth=78 " for all text files set 'textwidth' to 78 characters. + autocmd FileType c,cpp,cs,swig set nomodeline " this will avoid bug in my project with namespace ex, the vim will tree ex:: as modeline. + autocmd FileType c,cpp,java,javascript set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,f:// + autocmd FileType cs set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,f:///,f:// + autocmd FileType vim set comments=sO:\"\ -,mO:\"\ \ ,eO:\"\",f:\" + autocmd FileType lua set comments=f:-- + autocmd FileType vim setlocal foldmethod=marker + autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS + autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS + autocmd Filetype html setlocal omnifunc=htmlcomplete#CompleteTags + autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags + autocmd FileType xml call XmlFileTypeInit() + autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags + autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS + autocmd FileType python setlocal omnifunc=pythoncomplete#Complete + autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP + autocmd BufEnter * + \ if empty(&buftype)&&has('nvim') + \| nnoremap :call MyTagfunc() + \| nnoremap :call MyTagfuncBack() + \| else + \| nnoremap ] :call MyTagfunc() + \| nnoremap [ :call MyTagfuncBack() + \| endif + "}}} + autocmd FileType python,coffee call zvim#util#check_if_expand_tab() + " Instead of reverting the cursor to the last position in the buffer, we + " set it to the first line when editing a git commit message + au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) + autocmd InsertEnter * call s:tool() + if executable('synclient') + let s:touchpadoff = 0 + autocmd InsertEnter * call s:disable_touchpad() + autocmd InsertLeave * call s:enable_touchpad() + autocmd FocusLost * call system('synclient touchpadoff=0') + autocmd FocusGained * call s:reload_touchpad_status() + endif + autocmd VimResized * wincmd = + autocmd BufWritePost *.vim call s:generate_doc() + augroup END +endfunction +function! s:reload_touchpad_status() abort + if s:touchpadoff + call s:disable_touchpad() + endif +endf +function! s:disable_touchpad() abort + let s:touchpadoff = 1 + call system('synclient touchpadoff=1') +endfunction +function! s:enable_touchpad() abort + let s:touchpadoff = 0 + call system('synclient touchpadoff=0') +endfunction +function! s:tool() abort + if !exists('s:done') + IndentLinesToggle + IndentLinesToggle + let s:done = 1 + endif +endfunction +function! s:generate_doc() abort + if filereadable('./addon-info.json') && executable('vimdoc') + call system('vimdoc .') + endif +endfunction diff --git a/config/main.vim b/config/main.vim index db8fda188..0a9a898e2 100644 --- a/config/main.vim +++ b/config/main.vim @@ -22,7 +22,7 @@ call zvim#util#source_rc('general.vim') call zvim#util#source_rc('mappings.vim') -call zvim#util#source_rc('autocmds.vim') +call SpaceVim#autocmds#init() if has('nvim') call zvim#util#source_rc('neovim.vim') From 19c37e4308d8deb8610ab1a76fc04521f2be82d9 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 3 Jan 2017 22:30:38 +0800 Subject: [PATCH 2/2] Remove config/autocmds.vim --- config/autocmds.vim | 85 --------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 config/autocmds.vim diff --git a/config/autocmds.vim b/config/autocmds.vim deleted file mode 100644 index 38462c726..000000000 --- a/config/autocmds.vim +++ /dev/null @@ -1,85 +0,0 @@ -"autocmds -augroup My_autocmds - au! - autocmd BufWinEnter quickfix nnoremap - \ q :cclose:lclose - autocmd BufEnter * if (winnr('$') == 1 && &buftype ==# 'quickfix' ) | - \ bd| - \ q | endif - autocmd FileType jsp call JspFileTypeInit() - autocmd FileType html,css,jsp EmmetInstall - autocmd FileType java call JavaFileTypeInit() - autocmd BufEnter,WinEnter,InsertLeave * set cursorline - autocmd BufLeave,WinLeave,InsertEnter * set nocursorline - autocmd BufReadPost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ exe "normal! g`\"" | - \ endif - autocmd BufNewFile,BufEnter * set cpoptions+=d " NOTE: ctags find the tags file from the current path instead of the path of currect file - autocmd BufEnter * :syntax sync fromstart " ensure every file does syntax highlighting (full) - autocmd BufNewFile,BufRead *.avs set syntax=avs " for avs syntax file. - autocmd FileType text setlocal textwidth=78 " for all text files set 'textwidth' to 78 characters. - autocmd FileType c,cpp,cs,swig set nomodeline " this will avoid bug in my project with namespace ex, the vim will tree ex:: as modeline. - autocmd FileType c,cpp,java,javascript set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,f:// - autocmd FileType cs set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,f:///,f:// - autocmd FileType vim set comments=sO:\"\ -,mO:\"\ \ ,eO:\"\",f:\" - autocmd FileType lua set comments=f:-- - autocmd FileType vim setlocal foldmethod=marker - autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS - autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS - autocmd Filetype html setlocal omnifunc=htmlcomplete#CompleteTags - autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags - autocmd FileType xml call XmlFileTypeInit() - autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags - autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS - autocmd FileType python setlocal omnifunc=pythoncomplete#Complete - autocmd FileType php setlocal omnifunc=phpcomplete_extended#CompletePHP - autocmd BufEnter * - \ if empty(&buftype)&&has('nvim') - \| nnoremap :call MyTagfunc() - \| nnoremap :call MyTagfuncBack() - \| else - \| nnoremap ] :call MyTagfunc() - \| nnoremap [ :call MyTagfuncBack() - \| endif - "}}} - autocmd FileType python,coffee call zvim#util#check_if_expand_tab() - " Instead of reverting the cursor to the last position in the buffer, we - " set it to the first line when editing a git commit message - au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) - autocmd InsertEnter * call s:tool() - if executable('synclient') - let s:touchpadoff = 0 - autocmd InsertEnter * call s:disable_touchpad() - autocmd InsertLeave * call s:enable_touchpad() - autocmd FocusLost * call system('synclient touchpadoff=0') - autocmd FocusGained * call s:reload_touchpad_status() - endif - autocmd VimResized * wincmd = - autocmd BufWritePost *.vim call s:generate_doc() -augroup END -function! s:reload_touchpad_status() - if s:touchpadoff - call s:disable_touchpad() - endif -endf -function! s:disable_touchpad() abort - let s:touchpadoff = 1 - call system('synclient touchpadoff=1') -endfunction -function! s:enable_touchpad() abort - let s:touchpadoff = 0 - call system('synclient touchpadoff=0') -endfunction -fu! s:tool() - if !exists('s:done') - IndentLinesToggle - IndentLinesToggle - let s:done = 1 - endif -endf -function! s:generate_doc() abort - if filereadable('./addon-info.json') && executable('vimdoc') - call system('vimdoc .') - endif -endfunction