vim-jp / autofmt

Text Formatting Plugin
28 stars 2 forks source link

How can I toggle autofmt #18

Closed VimWei closed 5 years ago

VimWei commented 5 years ago

I use the following code in vimrc, but it can't toggle. What should I do?

nnoremap <leader>fm :call FormatexprToggle()<CR>
function! FormatexprToggle()
    if &formatexpr
        setlocal formatexpr=
        echo "Not use uax14."
    else
        setlocal formatexpr=autofmt#uax14#formatexpr()
        echo "Use uax14."
    endif
endfunction
VimWei commented 5 years ago

This code is ok:

nnoremap <leader>fm :call FormatexprToggle()<CR>
function! FormatexprToggle()
    if &formatexpr == "autofmt#uax14#formatexpr()"
        setlocal formatexpr=
        echo "Not use uax14."
    else
        setlocal formatexpr=autofmt#uax14#formatexpr()
        echo "Use uax14."
    endif
endfunction