From ce3ee731b3fa2fe136ca23aa40086163da86b9f4 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Fri, 19 Aug 2022 09:56:00 +0300 Subject: [PATCH] nix/prog/nvim: improve lua augroups --- nix/progs/nvim/lua/basic.lua | 54 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/nix/progs/nvim/lua/basic.lua b/nix/progs/nvim/lua/basic.lua index 1934aca..033fe24 100644 --- a/nix/progs/nvim/lua/basic.lua +++ b/nix/progs/nvim/lua/basic.lua @@ -101,46 +101,48 @@ local bufReadFile = {'BufNewFile', 'BufRead'} -- Set up a line limiter for each lang local line_limiter_augroup = vim.api.nvim_create_augroup('line_limiter', {}) -local function set_line_limiter(pattern, limit) +local function set_line_limiter(limit, patterns) vim.api.nvim_create_autocmd(bufReadFile, { - pattern = pattern, + pattern = patterns, group = line_limiter_augroup, - callback = function () vim.wo.colorcolumn = limit end, + callback = function () vim.wo.colorcolumn = tostring(limit) end, }) end -set_line_limiter('*.nix', '101') -set_line_limiter('*.vim', '101') -set_line_limiter('*.lua', '101') -set_line_limiter('*.ts,*.tsx', '101') -set_line_limiter('*.js.*.jsx', '101') -set_line_limiter('*.rs', '101') -set_line_limiter('*.json', '81') -set_line_limiter('*.yml','*.yaml', '81') -set_line_limiter('*.md', '81') -set_line_limiter('*.html', '81') -set_line_limiter('*.css', '81') --- TODO: add line limiter for haskell +set_line_limiter(101, { + '*.nix', + '*.vim', + '*.lua', + '*.ts', + '*.tsx', + '*.js', + '*.jsx', + '*.rs', +}) +set_line_limiter(81, { + '*.json', + '*.yml', + '*.yaml', + '*.md', + '*.html', + '*.css', +}) -- Spell check for markdown files local spell_check_augroup = vim.api.nvim_create_augroup('spell_check', {}) -local function enable_spell_check(pattern) - vim.api.nvim_create_autocmd(bufReadFile, { - pattern = pattern, - group = spell_check_augroup, - callback = function () vim.wo.spell = true end, - }) -end -enable_spell_check '*.md' - +vim.api.nvim_create_autocmd(bufReadFile, { + pattern = { '*.md' }, + group = spell_check_augroup, + callback = function () vim.wo.spell = true end, +}) ------------------------------------------------------------------------------- -- -- Bindings -- -local function disable_search_highlighting() vim.opt.hlsearch = false end -vim.keymap.set('n', '', disable_search_highlighting, { desc = 'Clear search highlighting' }) +local function clear_search_hl() vim.opt.hlsearch = false end +vim.keymap.set('n', '', clear_search_hl, { desc = 'Clear search highlighting' }) -- Enable fast navigation between windows vim.keymap.set('n', '', 'h')