From 1b83aba8f085e28b4fdfb8f10517654fa25d048d Mon Sep 17 00:00:00 2001 From: tiyn <43725244+tiyn@users.noreply.github.com> Date: Wed, 3 Jan 2024 01:16:50 +0100 Subject: [PATCH] check if buffer is modifiable --- lua/tidy/init.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lua/tidy/init.lua b/lua/tidy/init.lua index 4d46829..a829db7 100644 --- a/lua/tidy/init.lua +++ b/lua/tidy/init.lua @@ -66,11 +66,14 @@ function M.setup(opts) local cursor_pos = vim.api.nvim_win_get_cursor(0) - -- delete trailing whitespace - vim.cmd([[:keepjumps keeppatterns %s/\s\+$//e]]) - -- delete lines @ eof - vim.cmd([[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d_]]) + if vim.o.ma then + -- delete trailing whitespace + vim.cmd([[:keepjumps keeppatterns %s/\s\+$//e]]) + + -- delete lines @ eof + vim.cmd([[:keepjumps keeppatterns silent! 0;/^\%(\n*.\)\@!/,$d_]]) + end reset_cursor_pos(cursor_pos) end,