Created
April 11, 2022 14:53
-
-
Save gerrard00/38b5b087b7a65ebb1acc273441e7893c to your computer and use it in GitHub Desktop.
coc.nvim Toggle Format On Save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:toggleFormatOnSave() | |
let l:currentValue = coc#util#get_config('coc.preferences').formatOnSaveFiletypes | |
if(len(l:currentValue) > 0) | |
echo "Disabling format on save." | |
let g:PreviousFormatOnSaveFiletypesValue = l:currentValue | |
call coc#config('coc.preferences', {'formatOnSaveFiletypes': []}) | |
else | |
echo "Re-enabling format on save." | |
call coc#config('coc.preferences', {'formatOnSaveFiletypes': g:PreviousFormatOnSaveFiletypesValue}) | |
endif | |
endfunction | |
command! ToggleFormatOnSave :call s:toggleFormatOnSave() | |
nnoremap <Leader>fos :ToggleFormatOnSave<CR> | |
inoremap <Leader>fos <C-o>:ToggleFormatOnSave<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Enable or disable COC.nvim format on save functionality.