Skip to content

Instantly share code, notes, and snippets.

@gerrard00
Created April 11, 2022 14:53
Show Gist options
  • Select an option

  • Save gerrard00/38b5b087b7a65ebb1acc273441e7893c to your computer and use it in GitHub Desktop.

Select an option

Save gerrard00/38b5b087b7a65ebb1acc273441e7893c to your computer and use it in GitHub Desktop.
coc.nvim Toggle Format On Save
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>
@gerrard00
Copy link
Copy Markdown
Author

Enable or disable COC.nvim format on save functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment