nvim: only run colorcolumn function on tw change

This commit is contained in:
tastytea 2022-08-11 01:04:28 +02:00
parent 0e14ee24f2
commit b72fab5c29
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 4 additions and 4 deletions

View File

@ -28,7 +28,7 @@ vim.api.nvim_create_autocmd(
pattern = { 'gitcommit', 'gitrebase' },
callback = function()
-- FIXME: why does the autocmd in settings.lua not set it?
vim.wo.colorcolumn = tostring(vim.o.textwidth)
vim.opt_local.colorcolumn = tostring(vim.o.textwidth)
vim.cmd([[startinsert | 1]])
end
})

View File

@ -32,15 +32,15 @@ packer.use 'https://github.com/editorconfig/editorconfig-vim'
-- set colorcolumn to textwidth after buffer is displayed or option is changed
vim.api.nvim_create_augroup('config_settings', { clear = true })
vim.api.nvim_create_autocmd(
{ 'BufWinEnter', 'OptionSet' },
{ 'OptionSet' },
{
group = 'config_settings',
pattern = { 'textwidth' },
callback = function()
if vim.o.textwidth > 0 then
vim.wo.colorcolumn = tostring(vim.o.textwidth)
vim.opt_local.colorcolumn = tostring(vim.o.textwidth)
else
vim.wo.colorcolumn = ''
vim.opt_local.colorcolumn = ''
end
end
}