Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions plugin/capslock.vim
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,27 @@ function! s:enabled(mode) abort
if a:mode == 'i' && exists('##InsertCharPre')
return get(b:, 'capslock', 0)
else
return maparg('a',a:mode) == 'A'
return maparg('a',a:mode) ==# 'A'
endif
endfunction

function! s:exitcallback() abort
if s:enabled('i') == 1
call s:disable('i')
function! s:exitcallback(mode) abort
if s:enabled(a:mode)
call s:disable(a:mode)
endif
endfunction

function! CapsLockStatusline(...) abort
return s:enabled('i') ? (a:0 == 1 ? a:1 : '[Caps]') : ''
return (s:enabled('i') || s:enabled('c')) ? (a:0 == 1 ? a:1 : '[Caps]') : ''
endfunction

augroup capslock
autocmd!
autocmd User Flags call Hoist('window', 'CapsLockStatusline')

autocmd InsertLeave * call s:exitcallback()
autocmd CmdlineLeave : call s:exitcallback('c')

autocmd InsertLeave * call s:exitcallback('i')
if exists('##InsertCharPre')
autocmd InsertCharPre *
\ if s:enabled('i') |
Expand All @@ -102,6 +104,9 @@ cnoremap <silent> <Plug>CapsLockDisable <C-R>=<SID>disable('c')<CR>
if empty(mapcheck("<C-L>", "i"))
imap <C-L> <Plug>CapsLockToggle
endif
if empty(mapcheck("<C-L>", "c"))
cmap <C-L> <Plug>CapsLockToggle
endif
imap <C-G>c <Plug>CapsLockToggle
nmap gC <Plug>CapsLockToggle

Expand Down