summaryrefslogtreecommitdiff
path: root/nvim/lua/config/trailing-spaces.lua
blob: 2bb4cbf1ba9afd43bea1d34a64b47f009104bfdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- 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' })