nvim: fix textwidth to colorcolumn autocmd

This commit is contained in:
tastytea 2022-08-11 01:58:06 +02:00
parent 14896666cd
commit 0268a28869
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
3 changed files with 27 additions and 22 deletions

View File

@ -20,17 +20,14 @@ packer.use {
map('n', '<Leader>g', ':Neogit<cr>')
}
-- start git commits in insert mode
vim.api.nvim_create_augroup('config_coding', { clear = true })
vim.api.nvim_create_autocmd(
{ 'FileType' },
{
group = 'config_coding',
pattern = { 'gitcommit', 'gitrebase' },
callback = function()
-- FIXME: why does the autocmd in settings.lua not set it?
vim.opt_local.colorcolumn = tostring(vim.o.textwidth)
vim.cmd([[startinsert | 1]])
end
command = [[startinsert | 1]]
})
packer.use {

View File

@ -55,3 +55,28 @@ function my_insert_modeline()
end
end
vim.cmd([[command! ModelineInsert lua my_insert_modeline()]])
-- set colorcolumn to textwidth after buffer is displayed or option is changed
function my_set_colorcolumn()
if vim.o.textwidth > 0 then
vim.opt_local.colorcolumn = { vim.o.textwidth }
else
vim.opt_local.colorcolumn = ''
end
end
vim.api.nvim_create_augroup('config_settings', { clear = true })
vim.api.nvim_create_autocmd(
{ 'BufEnter' },
{
group = 'config_settings',
callback = my_set_colorcolumn
}
)
vim.api.nvim_create_autocmd(
{ 'OptionSet' },
{
group = 'config_settings',
pattern = { 'textwidth' },
callback = my_set_colorcolumn
}
)

View File

@ -26,20 +26,3 @@ packer.use {
}
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(
{ 'OptionSet' },
{
group = 'config_settings',
pattern = { 'textwidth' },
callback = function()
if vim.o.textwidth > 0 then
vim.opt_local.colorcolumn = tostring(vim.o.textwidth)
else
vim.opt_local.colorcolumn = ''
end
end
}
)