fix: Make colorcolumn work properly
Setting `colorcolumn` as a window option breaks any window that does not need it set. Use an autocmd to fix this.
This commit is contained in:
parent
3b4e204195
commit
0d623139fa
|
|
@ -1,3 +1,2 @@
|
||||||
vim.wo.spell = true
|
vim.wo.spell = true
|
||||||
vim.bo.textwidth = 75
|
vim.bo.textwidth = 75
|
||||||
vim.wo.colorcolumn = "75,80"
|
|
||||||
|
|
|
||||||
2
ftplugin/tex.lua
Normal file
2
ftplugin/tex.lua
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
vim.wo.spell = true
|
||||||
|
vim.bo.textwidth = 80
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
vim.wo.spell = true
|
vim.wo.spell = true
|
||||||
vim.bo.textwidth = 75
|
vim.bo.textwidth = 75
|
||||||
vim.wo.colorcolumn = "75,80"
|
|
||||||
|
|
||||||
vim.api.nvim_buf_create_user_command(0, "OpenPdf", function()
|
vim.api.nvim_buf_create_user_command(0, "OpenPdf", function()
|
||||||
local filepath = vim.api.nvim_buf_get_name(0)
|
local filepath = vim.api.nvim_buf_get_name(0)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
-- Control cursorline option
|
-- Control cursorline option
|
||||||
-- This function allows the easy creation of autocommands that configure cursorline for one buffer
|
-- This function allows the easy creation of autocommands that configure cursorline for one buffer
|
||||||
-- either based on events or filetypes
|
-- either based on events or filetypes
|
||||||
local auGroupCursorLine = vim.api.nvim_create_augroup("CursorLine", { clear = true })
|
local auGroupCursorLine = vim.api.nvim_create_augroup("CursorLine",
|
||||||
|
{ clear = true })
|
||||||
local set_cursorline = function(event, value, pattern)
|
local set_cursorline = function(event, value, pattern)
|
||||||
vim.api.nvim_create_autocmd(event, {
|
vim.api.nvim_create_autocmd(event, {
|
||||||
group = auGroupCursorLine,
|
group = auGroupCursorLine,
|
||||||
|
|
@ -18,7 +19,8 @@ set_cursorline("FileType", false, "TelescopePrompt")
|
||||||
-- Wrangle formatoptions
|
-- Wrangle formatoptions
|
||||||
-- Format options is local to the buffer
|
-- Format options is local to the buffer
|
||||||
-- This autocommand fixes formatoptions for all buffers at load
|
-- This autocommand fixes formatoptions for all buffers at load
|
||||||
local auGroupFormatOptions = vim.api.nvim_create_augroup("FormatOptions", { clear = true })
|
local auGroupFormatOptions = vim.api.nvim_create_augroup("FormatOptions",
|
||||||
|
{ clear = true })
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = auGroupFormatOptions,
|
group = auGroupFormatOptions,
|
||||||
pattern = "*",
|
pattern = "*",
|
||||||
|
|
@ -28,3 +30,30 @@ vim.api.nvim_create_autocmd("FileType", {
|
||||||
- "o" -- and for newlines
|
- "o" -- and for newlines
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Do some magic for colorcolumn
|
||||||
|
-- if set as a window option for a file, anything that uses that window
|
||||||
|
-- at a later date will inherit that even if it doesn't make sense.
|
||||||
|
local auGroupColorColumn = vim.api.nvim_create_augroup("ColorColumn",
|
||||||
|
{clear=true})
|
||||||
|
vim.api.nvim_create_autocmd( 'BufEnter', {
|
||||||
|
group = auGroupColorColumn,
|
||||||
|
pattern = "*",
|
||||||
|
callback = function (_)
|
||||||
|
-- if we set textwidth we show a colorcolumn
|
||||||
|
if vim.bo.textwidth > 0 then
|
||||||
|
local warn=vim.bo.textwidth - 5
|
||||||
|
vim.wo.colorcolumn=string.format("%d,%d", warn, vim.bo.textwidth)
|
||||||
|
else
|
||||||
|
vim.wo.colorcolumn=""
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
vim.api.nvim_create_autocmd('BufLeave',{
|
||||||
|
group=auGroupColorColumn,
|
||||||
|
pattern = '*',
|
||||||
|
callback = function ()
|
||||||
|
vim.wo.colorcolumn=""
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user