summaryrefslogtreecommitdiff
path: root/nvim/lua/config/trailing-spaces.lua
blob: 799280e31ceb4d8f0ab33d88fa8cd624bc507cad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- highlights trailing spaces
vim.cmd("match Search /\\s\\+$/")

-- disable highlight when going into insert mode
vim.api.nvim_create_autocmd({ "ModeChanged" }, {
	pattern = { "*:i" },
	command = "match none",
})

-- highlights trailing spaces when going back to normal mode
vim.api.nvim_create_autocmd({ "ModeChanged" }, {
	pattern = { "*:n" },
	command = "match Search /\\s\\+$/",
})

vim.keymap.set(
	"n",
	"<leader>t",
	":%s/\\s\\+$//g<CR>",
	{ noremap = true, silent = true, desc = "Remove Trailing Whitespaces" }
)