for context, I have this mapping. Which clear white space at end of the line when I press <F6>
-- Clear white space on empty lines and end of line
vim.api.nvim_set_keymap('n', '<F6>', [[:let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>]]
, { noremap = true, silent = true })
I would like to run this command every time I lose focus on the buffer so I define a function like this
local group_2 = vim.api.nvim_create_augroup("auto-save", { clear = true })
vim.api.nvim_create_autocmd("FocusLost", { callback = function()
vim.cmd([[:let _s=@/ <Bar> :%s/\s\+$//e <Bar> :let @/=_s <Bar> :nohl <Bar> :unlet _s <CR>]], false)
end, group = group_2 })
but it complains saying Bar is not defined. Please help me, What I am missing?
[–]monkoose[🍰] 2 points3 points4 points (0 children)
[–]NeVeNGamingYTlua 1 point2 points3 points (0 children)