1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-24 10:47:07 +08:00
SpaceVim/autoload/SpaceVim/autocmds.vim

193 lines
7.3 KiB
VimL
Raw Normal View History

2017-03-19 20:20:33 +08:00
"=============================================================================
" autocmd.vim --- main autocmd group for spacevim
2019-06-09 14:11:17 +08:00
" Copyright (c) 2016-2019 Shidong Wang & Contributors
2017-03-19 20:20:33 +08:00
" Author: Shidong Wang < wsdjeg at 163.com >
" URL: https://spacevim.org
2018-02-15 22:25:03 +08:00
" License: GPLv3
2017-03-19 20:20:33 +08:00
"=============================================================================
let s:SYS = SpaceVim#api#import('system')
let s:JOB = SpaceVim#api#import('job')
2017-01-03 22:29:54 +08:00
"autocmds
function! SpaceVim#autocmds#init() abort
2017-03-19 20:20:33 +08:00
augroup SpaceVim_core
2017-03-06 23:26:26 +08:00
au!
autocmd BufWinEnter quickfix nnoremap <silent> <buffer>
\ q :cclose<cr>:lclose<cr>
autocmd BufEnter * if (winnr('$') == 1 && &buftype ==# 'quickfix' ) |
\ bd|
\ q | endif
2017-06-03 12:50:44 +08:00
autocmd QuitPre * call SpaceVim#plugins#windowsmanager#UpdateRestoreWinInfo()
2017-06-03 15:07:09 +08:00
autocmd WinEnter * call SpaceVim#plugins#windowsmanager#MarkBaseWin()
if g:spacevim_relativenumber
autocmd BufEnter,WinEnter * if &nu | set rnu | endif
autocmd BufLeave,WinLeave * if &nu | set nornu | endif
endif
2017-03-06 23:26:26 +08:00
autocmd BufRead,BufNewFile *.pp setfiletype puppet
if g:spacevim_enable_cursorline == 1
2018-09-16 13:54:57 +08:00
autocmd BufEnter,WinEnter,InsertLeave * call s:enable_cursorline()
autocmd BufLeave,WinLeave,InsertEnter * call s:disable_cursorline()
endif
if g:spacevim_enable_cursorcolumn == 1
autocmd BufEnter,WinEnter,InsertLeave * setl cursorcolumn
autocmd BufLeave,WinLeave,InsertEnter * setl nocursorcolumn
endif
2017-03-06 23:26:26 +08:00
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 BufWinLeave * let b:_winview = winsaveview()
autocmd BufWinEnter * if(exists('b:_winview')) | call winrestview(b:_winview) | endif
2017-03-06 23:26:26 +08:00
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 c,cpp,java,javascript set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
autocmd FileType cs set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
autocmd FileType vim set comments=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"
2018-03-27 22:39:33 +08:00
autocmd Filetype qf setlocal nobuflisted
autocmd FileType python,coffee call SpaceVim#util#check_if_expand_tab()
au StdinReadPost * call s:disable_welcome()
2017-03-06 23:26:26 +08:00
autocmd InsertEnter * call s:fixindentline()
2017-07-26 04:52:18 +08:00
autocmd BufEnter,FileType * call SpaceVim#mapping#space#refrashLSPC()
2017-05-31 22:00:17 +08:00
if executable('synclient') && g:spacevim_auto_disable_touchpad
2017-03-06 23:26:26 +08:00
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
2018-07-12 20:57:06 +08:00
autocmd BufWritePre * call SpaceVim#plugins#mkdir#CreateCurrent()
2017-03-06 23:26:26 +08:00
autocmd BufWritePost *.vim call s:generate_doc()
autocmd ColorScheme * call SpaceVim#api#import('vim#highlight').hide_in_normal('EndOfBuffer')
2019-04-28 21:19:09 +08:00
autocmd ColorScheme gruvbox,jellybeans,nord,srcery call s:fix_colorschem_in_SpaceVim()
2017-05-13 20:35:45 +08:00
autocmd VimEnter * call SpaceVim#autocmds#VimEnter()
2017-12-17 21:14:50 +08:00
autocmd BufEnter * let b:_spacevim_project_name = get(g:, '_spacevim_project_name', '')
autocmd SessionLoadPost * let g:_spacevim_session_loaded = 1
autocmd VimLeavePre * call SpaceVim#plugins#manager#terminal()
2017-03-06 23:26:26 +08:00
augroup END
2017-01-03 22:29:54 +08:00
endfunction
2018-09-16 13:54:57 +08:00
function! s:enable_cursorline() abort
if g:_spacevim_cursorline_flag == -1
setl cursorline
endif
endfunction
function! s:disable_cursorline() abort
setl nocursorline
endfunction
2017-01-03 22:29:54 +08:00
function! s:reload_touchpad_status() abort
2017-03-06 23:26:26 +08:00
if s:touchpadoff
call s:disable_touchpad()
endif
2017-01-03 22:29:54 +08:00
endf
function! s:disable_touchpad() abort
2017-03-06 23:26:26 +08:00
let s:touchpadoff = 1
call system('synclient touchpadoff=1')
2017-01-03 22:29:54 +08:00
endfunction
function! s:enable_touchpad() abort
2017-03-06 23:26:26 +08:00
let s:touchpadoff = 0
call system('synclient touchpadoff=0')
2017-01-03 22:29:54 +08:00
endfunction
2017-01-12 23:20:17 +08:00
function! s:fixindentline() abort
if !exists('s:done') && has('conceal')
" The indentLine plugin need conceal feature
2017-03-06 23:26:26 +08:00
if exists(':IndentLinesToggle') == 2
IndentLinesToggle
IndentLinesToggle
else
echohl WarningMsg
echom 'plugin : indentLines has not been installed,
\ please use `:call dein#install(["indentLine"])` to install this plugin,'
echohl None
2017-01-03 22:29:54 +08:00
endif
2017-03-06 23:26:26 +08:00
let s:done = 1
endif
2017-01-03 22:29:54 +08:00
endfunction
function! s:generate_doc() abort
" neovim in windows executable function is broken
" https://github.com/neovim/neovim/issues/9391
if filereadable('./addon-info.json') && executable('vimdoc') && !s:SYS.isWindows
call s:JOB.start(['vimdoc', '.'])
elseif filereadable('./addon-info.json') && executable('python')
call s:JOB.start(['python', '-m', 'vimdoc', '.'])
2017-03-06 23:26:26 +08:00
endif
2017-01-03 22:29:54 +08:00
endfunction
2017-03-06 23:26:26 +08:00
2019-04-28 21:19:09 +08:00
function! s:fix_colorschem_in_SpaceVim() abort
2017-04-17 23:41:01 +08:00
if &background ==# 'dark'
if g:colors_name ==# 'gruvbox'
hi VertSplit guibg=#282828 guifg=#181A1F
elseif g:colors_name ==# 'jellybeans'
hi VertSplit guibg=#151515 guifg=#080808
elseif g:colors_name ==# 'nord'
hi VertSplit guibg=#2E3440 guifg=#262626
2019-04-28 21:19:09 +08:00
elseif g:colors_name ==# 'srcery'
hi VertSplit guibg=#1C1B19 guifg=#262626
hi clear Visual
hi Visual guibg=#303030
endif
2017-04-17 23:41:01 +08:00
else
if g:colors_name ==# 'gruvbox'
hi VertSplit guibg=#fbf1c7 guifg=#e7e9e1
endif
2017-04-17 23:41:01 +08:00
endif
2017-04-17 20:40:13 +08:00
hi SpaceVimLeaderGuiderGroupName cterm=bold ctermfg=175 gui=bold guifg=#d3869b
2017-04-16 19:00:24 +08:00
endfunction
2017-12-01 20:16:24 +08:00
2017-05-13 20:35:45 +08:00
function! SpaceVim#autocmds#VimEnter() abort
call SpaceVim#api#import('vim#highlight').hide_in_normal('EndOfBuffer')
2017-12-01 20:16:24 +08:00
for argv in g:_spacevim_mappings_space_custom_group_name
2017-12-16 16:03:16 +08:00
if len(argv[0]) == 1
if !has_key(g:_spacevim_mappings_space, argv[0][0])
let g:_spacevim_mappings_space[argv[0][0]] = {'name' : argv[1]}
endif
elseif len(argv[0]) == 2
if !has_key(g:_spacevim_mappings_space, argv[0][0])
let g:_spacevim_mappings_space[argv[0][0]] = {'name' : '+Unnamed',
\ argv[0][1] : { 'name' : argv[1]},
\ }
else
if !has_key(g:_spacevim_mappings_space[argv[0][0]], argv[0][1])
let g:_spacevim_mappings_space[argv[0][0]][argv[0][1]] = {'name' : argv[1]}
endif
endif
endif
2017-12-01 20:16:24 +08:00
endfor
2017-12-16 16:08:03 +08:00
for argv in g:_spacevim_mappings_space_custom
call call('SpaceVim#mapping#space#def', argv)
endfor
2018-03-18 20:57:14 +08:00
if SpaceVim#layers#isLoaded('core#statusline')
2017-05-16 22:14:38 +08:00
set laststatus=2
2017-05-17 00:46:25 +08:00
call SpaceVim#layers#core#statusline#def_colors()
2017-05-17 22:56:14 +08:00
setlocal statusline=%!SpaceVim#layers#core#statusline#get(1)
2017-05-16 22:14:38 +08:00
endif
2018-03-18 20:57:14 +08:00
if SpaceVim#layers#isLoaded('core#tabline')
2017-05-17 21:55:32 +08:00
call SpaceVim#layers#core#tabline#def_colors()
set showtabline=2
endif
2017-12-24 23:24:50 +08:00
call SpaceVim#plugins#projectmanager#RootchandgeCallback()
if !empty(get(g:, '_spacevim_bootstrap_after', ''))
2018-09-16 13:54:57 +08:00
try
call call(g:_spacevim_bootstrap_after, [])
catch
call SpaceVim#logger#error('failed to call bootstrap_after function: ' . g:_spacevim_bootstrap_after)
call SpaceVim#logger#error(' exception: ' . v:exception)
call SpaceVim#logger#error(' throwpoint: ' . v:throwpoint)
2018-09-16 13:54:57 +08:00
endtry
endif
2017-05-13 20:35:45 +08:00
endfunction
function! s:disable_welcome() abort
2017-12-16 16:03:16 +08:00
augroup SPwelcome
au!
augroup END
endfunction
2017-04-16 19:00:24 +08:00
2017-03-06 23:26:26 +08:00
" vim:set et sw=2: