diff --git a/nvim/autoload/user/plugin/coc.vim b/nvim/autoload/user/plugin/coc.vim index f341261e..41da8dab 100644 --- a/nvim/autoload/user/plugin/coc.vim +++ b/nvim/autoload/user/plugin/coc.vim @@ -51,13 +51,23 @@ function! user#plugin#coc#init() abort autocmd User CocJumpPlaceholder silent call CocActionAsync('showSignatureHelp') " Auto format - autocmd FocusLost,BufLeave *.go silent call CocActionAsync('format') + autocmd FocusLost,BufLeave *.go call user#plugin#coc#auto_format() " Override plugin commands autocmd VimEnter * command! -nargs=0 CocRestart :silent call coc#rpc#restart() augroup END endfunction +function! user#plugin#coc#auto_format() abort + if &readonly || !&modifiable + return + endif + if mode() ==# 'n' + return + endif + silent call CocActionAsync('format') +endfunction + " Custom actions "----------------------------------------------- nnoremap (coc-hover) call CocActionAsync('doHover')