dotfiles/dot_config/nvim/lua/utils/trim.lua
2024-01-14 23:03:03 +09:00

28 lines
568 B
Lua

-- Trim
vim.cmd([[
command! Trim call TrimSpace()
function! TrimSpace()
let save_cursor = getpos(".")
%s#\ \+$##e
%s#\($\n\s*\)\+\%$##e
call setpos('.', save_cursor)
endfunction
command! TrimDisable call TrimAuto(0)
command! TrimEnable call TrimAuto(1)
function! TrimAuto(enable)
if a:enable == 1
augroup TrimAuto
au!
au BufWritePre * Trim " See: ~/.config/nvim/functions/Trim.vim
augroup END
else
augroup TrimAuto
au!
augroup END
endif
endfunction
call TrimAuto(1)
]])