From fe084ae46a802f1eeb8cd91c72ee7b8a8c39d218 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Thu, 22 Feb 2024 18:42:06 +0100 Subject: [PATCH] vim: enforce style in top-level code --- config/nvim/lua/fschauen/autocmd.lua | 33 +++--- config/nvim/lua/fschauen/diagnostic.lua | 42 ++++---- config/nvim/lua/fschauen/filetype.lua | 11 +- config/nvim/lua/fschauen/init.lua | 19 ++-- config/nvim/lua/fschauen/keymap.lua | 129 ++++++++++++------------ config/nvim/lua/fschauen/lazy.lua | 44 ++++---- config/nvim/lua/fschauen/options.lua | 123 +++++++++++----------- config/nvim/lua/fschauen/window.lua | 51 ++++++---- 8 files changed, 232 insertions(+), 220 deletions(-) diff --git a/config/nvim/lua/fschauen/autocmd.lua b/config/nvim/lua/fschauen/autocmd.lua index 43afd2b..621521d 100644 --- a/config/nvim/lua/fschauen/autocmd.lua +++ b/config/nvim/lua/fschauen/autocmd.lua @@ -1,29 +1,34 @@ local M = {} M.setup = function() - local group = vim.api.nvim_create_augroup('fschauen', { clear = true } ) + local group = vim.api.nvim_create_augroup("fschauen", { clear = true }) - vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Briefly highlight yanked text.', + vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Briefly highlight yanked text.", group = group, - pattern = '*', - callback = function(_) vim.highlight.on_yank() end + pattern = "*", + callback = function(_) + vim.highlight.on_yank() + end, }) - vim.api.nvim_create_autocmd('InsertEnter', { - desc = 'Hide cursor line when entering insert mode.', + vim.api.nvim_create_autocmd("InsertEnter", { + desc = "Hide cursor line when entering insert mode.", group = group, - pattern = '*', - callback = function(_) vim.opt.cursorlineopt = 'number' end + pattern = "*", + callback = function(_) + vim.opt.cursorlineopt = "number" + end, }) - vim.api.nvim_create_autocmd('InsertLeave', { - desc = 'Show cursor line when leaving insert mode.', + vim.api.nvim_create_autocmd("InsertLeave", { + desc = "Show cursor line when leaving insert mode.", group = group, - pattern = '*', - callback = function(_) vim.opt.cursorlineopt = 'both' end + pattern = "*", + callback = function(_) + vim.opt.cursorlineopt = "both" + end, }) end return M - diff --git a/config/nvim/lua/fschauen/diagnostic.lua b/config/nvim/lua/fschauen/diagnostic.lua index 04f78f5..eba65bb 100644 --- a/config/nvim/lua/fschauen/diagnostic.lua +++ b/config/nvim/lua/fschauen/diagnostic.lua @@ -1,6 +1,6 @@ local M = {} -local icons = require('fschauen.util.icons') +local icons = require("fschauen.util.icons") -- Show/navigate warning and errors by default. M.severity = vim.diagnostic.severity.WARN @@ -8,38 +8,38 @@ M.severity = vim.diagnostic.severity.WARN -- Go to next/prev diagnostic, but only if next item has a visible virtual text. -- If we can move, then also center screen at target location. local conditional_goto = function(condition, move, opts) - opts = vim.tbl_extend('keep', opts or {}, { - wrap = false, -- don't wrap around the begin/end of file - severity = { -- only navigate items with visible virtual text - min = M.severity + opts = vim.tbl_extend("keep", opts or {}, { + wrap = false, -- don't wrap around the begin/end of file + severity = { -- only navigate items with visible virtual text + min = M.severity, }, }) if condition(opts) then move(opts) - vim.cmd 'normal zz' + vim.cmd("normal zz") else - vim.notify( - ('No more diagnostics [level: %s]'):format(vim.diagnostic.severity[M.severity] or '???'), - vim.log.levels.WARN) + local level = vim.diagnostic.severity[M.severity] or "???" + local msg = string.format("No more diagnostics [level: %s]", level) + vim.notify(msg, vim.log.levels.WARN) end end ---Move to the next diagnostic. ---@param opts table\nil: options passed along to `vim.diagnostic.goto_next`. -M.goto_next= function(opts) +M.goto_next = function(opts) conditional_goto(vim.diagnostic.get_next_pos, vim.diagnostic.goto_next, opts) end ---Move to the previous diagnostic. ---@param opts table|nil: options passed along to `vim.diagnostic.goto_prev`. -M.goto_prev= function(opts) +M.goto_prev = function(opts) conditional_goto(vim.diagnostic.get_prev_pos, vim.diagnostic.goto_prev, opts) end ---Show diagnostics in a floating window. ---@param opts table|nil: options passed along to `vim.diagnostic.open_float`. -M.open_float= function(opts) +M.open_float = function(opts) vim.diagnostic.open_float(opts) end @@ -62,18 +62,19 @@ end M.select_virtual_text_severity = function() vim.ui.select( - { 'ERROR', 'WARN', 'INFO', 'HINT' }, - { prompt = 'Min. severity for virtual text:' }, - function(choice, --[[index]]_) + { "ERROR", "WARN", "INFO", "HINT" }, + { prompt = "Min. severity for virtual text:" }, + function(choice) if choice then M.severity = vim.diagnostic.severity[choice] or M.severity vim.diagnostic.config { virtual_text = { - severity = { min = M.severity } + severity = { min = M.severity }, }, } end - end) + end + ) end ---Customize nvim's diagnostics display. @@ -85,19 +86,18 @@ M.setup = function() prefix = icons.ui.Circle, severity = { min = M.severity, - } + }, }, float = { - border = 'rounded', + border = "rounded", }, severity_sort = true, } for type, icon in pairs(icons.diagnostics) do - local hl = 'DiagnosticSign' .. type + local hl = "DiagnosticSign" .. type vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) end end return M - diff --git a/config/nvim/lua/fschauen/filetype.lua b/config/nvim/lua/fschauen/filetype.lua index 0dda927..e178cc1 100644 --- a/config/nvim/lua/fschauen/filetype.lua +++ b/config/nvim/lua/fschauen/filetype.lua @@ -3,13 +3,12 @@ local M = {} M.setup = function() vim.filetype.add { pattern = { - ['${HOME}/.ssh/config.d/.*'] = 'sshconfig', - ['.*/ssh/config'] = 'sshconfig', - ['.*/git/config'] = 'gitconfig', - ['.*config/zsh/.*'] = 'zsh', - } + ["${HOME}/.ssh/config.d/.*"] = "sshconfig", + [".*/ssh/config"] = "sshconfig", + [".*/git/config"] = "gitconfig", + [".*config/zsh/.*"] = "zsh", + }, } end return M - diff --git a/config/nvim/lua/fschauen/init.lua b/config/nvim/lua/fschauen/init.lua index a86e4ea..a0b543d 100644 --- a/config/nvim/lua/fschauen/init.lua +++ b/config/nvim/lua/fschauen/init.lua @@ -4,17 +4,16 @@ P = function(v) end R = function(module) - require('plenary.reload').reload_module(module) + require("plenary.reload").reload_module(module) return require(module) end -require('fschauen.options').setup() -require('fschauen.keymap').setup() -require('fschauen.diagnostic').setup() -require('fschauen.autocmd').setup() -require('fschauen.filetype').setup() -require('fschauen.lazy').setup() - -local colorscheme = vim.env.NVIM_COLORSCHEME or 'gruvbox' -vim.cmd('silent! colorscheme ' .. colorscheme) +require("fschauen.options").setup() +require("fschauen.keymap").setup() +require("fschauen.diagnostic").setup() +require("fschauen.autocmd").setup() +require("fschauen.filetype").setup() +require("fschauen.lazy").setup() +local colorscheme = vim.env.NVIM_COLORSCHEME or "gruvbox" +vim.cmd("silent! colorscheme " .. colorscheme) diff --git a/config/nvim/lua/fschauen/keymap.lua b/config/nvim/lua/fschauen/keymap.lua index 8daf38e..f6844ee 100644 --- a/config/nvim/lua/fschauen/keymap.lua +++ b/config/nvim/lua/fschauen/keymap.lua @@ -1,123 +1,124 @@ local M = {} -local ui = require('fschauen.util.icons').ui +local ui = require("fschauen.util.icons").ui local map = function(mode, lhs, rhs, opts) - if mode ~= 'c' then + if mode ~= "c" then opts = opts or {} - opts.silent = opts.silent ~= false -- silent by default + opts.silent = opts.silent ~= false -- silent by default end vim.keymap.set(mode, lhs, rhs, opts) end +-- stylua: ignore start M.setup = function() -- better navigation for wrapped lines - map('n', 'j', 'gj') - map('n', 'k', 'gk') + map("n", "j", "gj") + map("n", "k", "gk") -- maintain cursor position when joining lines - map('n', 'J', 'mzJ`z') + map("n", "J", "mzJ`z") -- retain selection when making changes in visual mode - map('v', '', 'gv') - map('v', '', 'gv') - map('v', 'g', 'ggv') - map('v', 'g', 'ggv') - map('v', '>', '>gv') - map('v', '<', '<gv') + map("v", "", "gv") + map("v", "", "gv") + map("v", "g", "ggv") + map("v", "g", "ggv") + map("v", ">", ">gv") + map("v", "<", "<gv") -- place destination of important movements in the center of the screen - map('n', 'n', 'nzzzv') - map('n', 'N', 'Nzzzv') - map('n', '*', '*zzzv') - map('n', '#', '#zzzv') - map('n', 'g*', 'g*zzzv') - map('n', 'g#', 'g#zzzv') - map('n', '', 'zzzv') - map('n', '', 'zzzv') + map("n", "n", "nzzzv") + map("n", "N", "Nzzzv") + map("n", "*", "*zzzv") + map("n", "#", "#zzzv") + map("n", "g*", "g*zzzv") + map("n", "g#", "g#zzzv") + map("n", "", "zzzv") + map("n", "", "zzzv") -- easier window navigation - map('n', '', 'j') - map('n', '', 'k') - map('n', '', 'h') - map('n', '', 'l') + map("n", "", "j") + map("n", "", "k") + map("n", "", "h") + map("n", "", "l") local window = require 'fschauen.window' -- window resizing - map('n', '', window.resize_up(2), { desc = 'Resize window upward' }) - map('n', '', window.resize_down(2), { desc = 'Resize window downward' }) - map('n', '', window.resize_left(2), { desc = 'Resize window leftward' }) - map('n', '', window.resize_right(2), { desc = 'Resize window rightward' }) + map("n", "", window.resize_up(2), { desc = "Resize window upward" }) + map("n", "", window.resize_down(2), { desc = "Resize window downward" }) + map("n", "", window.resize_left(2), { desc = "Resize window leftward" }) + map("n", "", window.resize_right(2), { desc = "Resize window rightward" }) -- easy tab navigation - map('n', '', 'tabnext') - map('n', '', 'tabprevious') + map("n", "", "tabnext") + map("n", "", "tabprevious") -- move lines up and down - map('n', '', [[:move .+1==]]) - map('n', '', [[:move .-2==]]) - map('v', '', [[:move '>+1gv=gv]]) - map('v', '', [[:move '<-2gv=gv]]) - map('i', '', [[:move .+1==gi]]) - map('i', '', [[:move .-2==gi]]) + map("n", "", [[:move .+1==]]) + map("n", "", [[:move .-2==]]) + map("v", "", [[:move '>+1gv=gv]]) + map("v", "", [[:move '<-2gv=gv]]) + map("i", "", [[:move .+1==gi]]) + map("i", "", [[:move .-2==gi]]) -- move to begin/end of line in insert mode - map('i', '', '^') - map('i', '', '$') + map("i", "", "^") + map("i", "", "$") -- move to begin of line in command mode ( moves to end by default) - map('c', '', '') + map("c", "", "") -- more convenient way of entering normal mode from terminal mode - map('t', [[]], [[]]) + map("t", [[]], [[]]) -- recall older/recent command-line from history - map('c', '', '') - map('c', '', '') + map("c", "", "") + map("c", "", "") -- trigger InsertLeave when leaving Insert mode with ctrl-c (see :help i_CTRL-C) - map('i', '', '') + map("i", "", "") -- quickly change background - map('n', 'bg', [[let &background = &background ==? 'light' ? 'dark' : 'light']]) + map("n", "bg", [[let &background = &background ==? "light" ? "dark" : "light"]]) -- don't loose the original yanked contents when pasting in visual mode - map('x', 'p', [["_dP]]) + map("x", "p", [["_dP]]) local diagnostic = require 'fschauen.diagnostic' -- navigate diagnostics - map('n', '', diagnostic.goto_next, { desc = ui.Diagnostic .. ' [d]iagnostic [n]ext' }) - map('n', '', diagnostic.goto_prev, { desc = ui.Diagnostic .. ' [d]iagnostic [p]revious' }) - map('n', 'dd', diagnostic.toggle, { desc = ui.Diagnostic .. ' [d]iagnostic enable/[d]isable' }) - map('n', 'do', diagnostic.open_float, { desc = ui.Diagnostic .. ' [d]iagnostic [o]pen' }) - map('n', 'dh', diagnostic.hide, { desc = ui.Diagnostic .. ' [d]iagnostic [h]ide' }) - map('n', 'ds', diagnostic.select_virtual_text_severity, { desc = ui.Diagnostic .. ' [d]iagnostic [s]everity' }) + map("n", "", diagnostic.goto_next, { desc = ui.Diagnostic .. " [d]iagnostic [n]ext" }) + map("n", "", diagnostic.goto_prev, { desc = ui.Diagnostic .. " [d]iagnostic [p]revious" }) + map("n", "dd", diagnostic.toggle, { desc = ui.Diagnostic .. " [d]iagnostic enable/[d]isable" }) + map("n", "do", diagnostic.open_float, { desc = ui.Diagnostic .. " [d]iagnostic [o]pen" }) + map("n", "dh", diagnostic.hide, { desc = ui.Diagnostic .. " [d]iagnostic [h]ide" }) + map("n", "ds", diagnostic.select_virtual_text_severity, { desc = ui.Diagnostic .. " [d]iagnostic [s]everity" }) -- disable highlight until next search - map('n', 'h', 'nohlsearch') + map("n", "h", "nohlsearch") -- navigate items in quickfix and location lists - map('n', 'j', 'cnextzz') - map('n', 'k', 'cpreviouszz') - map('n', 'j', 'lnextzz') - map('n', 'k', 'lpreviouszz') + map("n", "j", "cnextzz") + map("n", "k", "cpreviouszz") + map("n", "j", "lnextzz") + map("n", "k", "lpreviouszz") -- toggle quickfix and loclist - map('n', 'll', window.toggle_quickfix, { desc = ui.Toggle .. ' toggle quickfix' }) - map('n', 'll', window.toggle_loclist, { desc = ui.Toggle .. ' toggle loclist' }) + map("n", "ll", window.toggle_quickfix, { desc = ui.Toggle .. " toggle quickfix" }) + map("n", "ll", window.toggle_loclist, { desc = ui.Toggle .. " toggle loclist" }) local options = require('fschauen.util.options') -- toggle options - map('n', 'sn', options.toggle_number, { desc = ui.Toggle .. " toggle 'number'" }) - map('n', 'sr', options.toggle_relativenumber, { desc = ui.Toggle .. " toggle 'relativenumber'" }) - map('n', 'sl', options.toggle_list, { desc = ui.Toggle .. " toggle 'list'" }) - map('n', 'sw', options.toggle_wrap, { desc = ui.Toggle .. " toggle 'wrap'" }) - map('n', 'ss', options.toggle_spell, { desc = ui.Toggle .. " toggle 'spell'" }) + map("n", "sn", options.toggle_number, { desc = ui.Toggle .. " toggle 'number'" }) + map("n", "sr", options.toggle_relativenumber, { desc = ui.Toggle .. " toggle 'relativenumber'" }) + map("n", "sl", options.toggle_list, { desc = ui.Toggle .. " toggle 'list'" }) + map("n", "sw", options.toggle_wrap, { desc = ui.Toggle .. " toggle 'wrap'" }) + map("n", "ss", options.toggle_spell, { desc = ui.Toggle .. " toggle 'spell'" }) end +-- stylua: ignore end return M - diff --git a/config/nvim/lua/fschauen/lazy.lua b/config/nvim/lua/fschauen/lazy.lua index d4a286f..4dc9b2c 100644 --- a/config/nvim/lua/fschauen/lazy.lua +++ b/config/nvim/lua/fschauen/lazy.lua @@ -3,22 +3,22 @@ local M = {} local bootstrap = function(path) if not vim.loop.fs_stat(path) then vim.fn.system { - 'git', - 'clone', - '--filter=blob:none', - '--branch=stable', - 'https://github.com/folke/lazy.nvim.git', + "git", + "clone", + "--filter=blob:none", + "--branch=stable", + "https://github.com/folke/lazy.nvim.git", path, } end vim.opt.rtp:prepend(path) - return vim.F.npcall(require, 'lazy') + return vim.F.npcall(require, "lazy") end local dev_path = function() local paths = { - '~/Projects/nvim-plugins', - '~/.local/src', + "~/Projects/nvim-plugins", + "~/.local/src", } paths = vim.tbl_map(vim.fn.expand, paths) paths = vim.tbl_filter(vim.loop.fs_stat, paths) @@ -26,35 +26,35 @@ local dev_path = function() end M.setup = function() - local lazy = bootstrap(vim.fn.stdpath('data') .. '/lazy/lazy.nvim') + local lazy = bootstrap(vim.fn.stdpath("data") .. "/lazy/lazy.nvim") if not lazy then - vim.notify('Lazy not installed and failed to bootstrap!', vim.log.levels.WARN) + vim.notify("Lazy not installed and failed to bootstrap!", vim.log.levels.WARN) return end - vim.keymap.set('n', 'L', 'Lazy') + vim.keymap.set("n", "L", "Lazy") lazy.setup { - spec = 'fschauen.plugins', + spec = "fschauen.plugins", dev = { path = dev_path(), fallback = true, }, ui = { - border = 'rounded', - title = ' Lazy ', + border = "rounded", + title = " Lazy ", }, performance = { rtp = { disabled_plugins = { - 'gzip', - 'matchit', - 'matchparen', - 'netrwPlugin', - 'tarPlugin', - 'tohtml', - 'tutor', - 'zipPlugin', + "gzip", + "matchit", + "matchparen", + "netrwPlugin", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin", }, }, }, diff --git a/config/nvim/lua/fschauen/options.lua b/config/nvim/lua/fschauen/options.lua index 2e64bcd..b013384 100644 --- a/config/nvim/lua/fschauen/options.lua +++ b/config/nvim/lua/fschauen/options.lua @@ -1,8 +1,9 @@ local M = {} +-- stylua: ignore start M.setup = function() - vim.g.mapleader = ' ' - vim.g.maplocalleader = ',' + vim.g.mapleader = " " + vim.g.maplocalleader = "," vim.cmd [[let &t_8f = "\[38:2:%lu:%lu:%lum"]] vim.cmd [[let &t_8b = "\[48:2:%lu:%lu:%lum"]] @@ -10,21 +11,21 @@ M.setup = function() local o = vim.opt -- General - o.belloff = 'all' -- never ring bells + o.belloff = "all" -- never ring bells o.hidden = true -- hide abandoned buffers - o.clipboard = 'unnamedplus' -- synchronize with system clipboard - o.lazyredraw = true -- don't redraw screen during macros + o.clipboard = "unnamedplus" -- synchronize with system clipboard + o.lazyredraw = true -- don"t redraw screen during macros o.modelines = 0 -- never use modelines - o.fileformats = 'unix,mac,dos' -- prioritize unix format - o.pastetoggle = '' -- toggle paste with P on Moonlander + o.fileformats = "unix,mac,dos" -- prioritize unix format + o.pastetoggle = "" -- toggle paste with P on Moonlander o.winblend = 8 -- minimum transparency for floating windows - o.swapfile = false -- don't use swap files + o.swapfile = false -- don"t use swap files o.writebackup = true -- Make a backup before writing a file... - o.backup = false -- ...but don't keep it around. + o.backup = false -- ...but don"t keep it around. o.undofile = true -- write undo history - o.shortmess:append 'I' -- no intro message when starting Vim + o.shortmess:append("I") -- no intro message when starting Vim o.shada = { "'1000", -- remember marks for this many files "/1000", -- remember this many search patterns @@ -44,29 +45,29 @@ M.setup = function() o.tabstop = 4 -- tabs are 4 spaces o.shiftwidth = 0 -- (auto)indent using 'tabstop' spaces o.smartindent = true -- use smart autoindenting - o.inccommand = 'split' -- preview command partial results + o.inccommand = "split" -- preview command partial results o.joinspaces = false -- use one space after a period whe joining lines o.showmatch = true -- briefly jump to matching bracket if insert one - o.virtualedit = 'block' -- position the cursor anywhere in Visual Block mode + o.virtualedit = "block" -- position the cursor anywhere in Visual Block mode o.formatlistpat = [[^\s*\(\d\+[\]:.)}\t ]\|[-+*]\|[\[(][ x][\])]\)\s*]] o.completeopt = { - 'menu', -- show completions in a popup menu - 'preview', -- show extra information about the selected match - 'noinsert', -- don't insert text until I select a match - 'noselect', -- don't pre-select the first match in the menu + "menu", -- show completions in a popup menu + "preview", -- show extra information about the selected match + "noinsert", -- don"t insert text until I select a match + "noselect", -- don"t pre-select the first match in the menu } local fmt = o.formatoptions - fmt:remove 't' -- Don't auto-wrap on 'textwidth'... - fmt:append 'c' -- ...but do it within comment blocks... - fmt:append 'l' -- ...but not if line was already long before entering Insert mode. - fmt:append 'r' -- Insert comment leader when pressing Enter... - fmt:remove 'o' -- ...but not when opening a new line with o & O. - fmt:append 'q' -- allow formatting of comments with gq - fmt:remove 'a' -- don't auto-format every time text is inserted - fmt:append 'n' -- indent lists automatically acc. 'formatlistpat' - fmt:append 'j' -- remove comment leader when joining lines - fmt:append '1' -- don't break lines after a one letter word but rather before it + fmt:remove("t") -- Don't auto-wrap on 'textwidth'... + fmt:append("c") -- ...but do it within comment blocks... + fmt:append("l") -- ...but not if line was already long before entering Insert mode. + fmt:append("r") -- Insert comment leader when pressing Enter... + fmt:remove("o") -- ...but not when opening a new line with o & O. + fmt:append("q") -- allow formatting of comments with gq + fmt:remove("a") -- don"t auto-format every time text is inserted + fmt:append("n") -- indent lists automatically acc. 'formatlistpat' + fmt:append("j") -- remove comment leader when joining lines + fmt:append("1") -- don"t break lines after a one letter word but rather before it -- Appearance o.termguicolors = true -- use "gui" :higlight instead of "cterm" @@ -75,49 +76,49 @@ M.setup = function() o.number = true -- ...but real number for current line. o.wrap = false -- don't wrap long lines initially o.textwidth = 80 -- maximum width for text being inserted - o.colorcolumn = '' -- highlight column after 'textwidth' + o.colorcolumn = "" -- highlight column after 'textwidth' o.cursorline = true -- highlight the line of the cursor - o.showbreak = '⤷ ' -- prefix for wrapped lines + o.showbreak = "⤷ " -- prefix for wrapped lines o.scrolloff = 3 -- min. # of lines above and below cursor o.sidescrolloff = 3 -- min. # of columns to left and right of cursor - o.signcolumn = 'yes' -- always display the signs column + o.signcolumn = "yes" -- always display the signs column o.list = false -- don't show invisible characters initially o.listchars = { - eol = '↲', - tab = '󰌒 ', -- » - extends = '…', - precedes = '…', - trail = '·', - conceal = '┊', + eol = "↲", + tab = "󰌒 ", -- » + extends = "…", + precedes = "…", + trail = "·", + conceal = "┊", } o.fillchars = { - diff = '⋅', + diff = "⋅", } -- Wildcard Expansion o.wildignore = { - '.git', - '.svn', - '__pycache__', - '**/tmp/**', - '*.DS_Store', - '*.dll', - '*.egg-info', - '*.exe', - '*.gif', - '*.jpeg', - '*.jpg', - '*.o', - '*.obj', - '*.out', - '*.png', - '*.pyc', - '*.so', - '*.zip', - '*~', + ".git", + ".svn", + "__pycache__", + "**/tmp/**", + "*.DS_Store", + "*.dll", + "*.egg-info", + "*.exe", + "*.gif", + "*.jpeg", + "*.jpg", + "*.o", + "*.obj", + "*.out", + "*.png", + "*.pyc", + "*.so", + "*.zip", + "*~", } o.wildignorecase = true -- ignore case when completing file names - o.wildmode = 'longest:full' -- longest common prefix first, then wildmenu + o.wildmode = "longest:full" -- longest common prefix first, then wildmenu -- Window Splitting o.splitbelow = true -- :split below current window @@ -127,16 +128,16 @@ M.setup = function() -- Folding o.foldenable = true -- enable folding o.foldlevelstart = 100 -- start with all folds open - o.foldmethod = 'syntax' -- fold based on syntax by default + o.foldmethod = "syntax" -- fold based on syntax by default o.foldnestmax = 10 -- limit nested folds to 10 levels -- Options for diff mode o.diffopt = { -- better side-by-side diffs - 'filler', -- show filler lines (so text is vertically synced) - 'vertical', -- use vertical splits (files side-by-side) - 'closeoff', -- disable diff mode when one window is closed + "filler", -- show filler lines (so text is vertically synced) + "vertical", -- use vertical splits (files side-by-side) + "closeoff", -- disable diff mode when one window is closed } end +-- stylua: ignore end return M - diff --git a/config/nvim/lua/fschauen/window.lua b/config/nvim/lua/fschauen/window.lua index d7909e4..d6dfd4c 100644 --- a/config/nvim/lua/fschauen/window.lua +++ b/config/nvim/lua/fschauen/window.lua @@ -18,11 +18,13 @@ end ---@param direction string: one of 'h', 'j', 'k', or 'l' local is_last = function(direction) local current = vim.api.nvim_get_current_win() - vim.cmd('wincmd ' .. direction) + vim.cmd("wincmd " .. direction) local next = vim.api.nvim_get_current_win() local is_last = current == next - if not is_last then vim.cmd('wincmd p') end + if not is_last then + vim.cmd("wincmd p") + end return is_last end @@ -31,26 +33,28 @@ end ---@param dir string: one of 'h', 'j', 'k', or 'l' ---@param size integer: how much to resize local resize = function(dir, size) - if dir ~= 'h' and dir ~= 'j' and dir ~= 'k' and dir ~= 'l' then return end + if dir ~= "h" and dir ~= "j" and dir ~= "k" and dir ~= "l" then + return + end size = math.abs(size) - local is_height = dir == 'j' or dir == 'k' - local is_positive = dir == 'j' or dir == 'l' + local is_height = dir == "j" or dir == "k" + local is_positive = dir == "j" or dir == "l" - if is_last(is_height and 'j' or 'l') then + if is_last(is_height and "j" or "l") then is_positive = not is_positive end - local delta = string.format('%s%d', is_positive and '+' or '-', size) - local prefix = is_height and '' or 'vertical ' - vim.cmd(prefix .. 'resize ' .. delta .. '') + local delta = string.format("%s%d", is_positive and "+" or "-", size) + local prefix = is_height and "" or "vertical " + vim.cmd(prefix .. "resize " .. delta .. "") end ---Resize current window upwards. ---@param size integer: how much to resize M.resize_up = function(size) return function() - resize('k', size) + resize("k", size) end end @@ -58,7 +62,7 @@ end ---@param size integer: how much to resize M.resize_down = function(size) return function() - resize('j', size) + resize("j", size) end end @@ -66,7 +70,7 @@ end ---@param size integer: how much to resize M.resize_left = function(size) return function() - resize('h', size) + resize("h", size) end end @@ -74,35 +78,38 @@ end ---@param size integer: how much to resize M.resize_right = function(size) return function() - resize('l', size) + resize("l", size) end end ---Toggle quickfix (or location) list. ---@param qf string: 'c' for quickfix, 'l' for location list local toggle_list = function(qf) - local l = qf == 'l' and 1 or 0 - local is_qf = function(win) return win.quickfix == 1 and win.loclist == l end + local l = qf == "l" and 1 or 0 + local is_qf = function(win) + return win.quickfix == 1 and win.loclist == l + end local is_open = not vim.tbl_isempty(vim.tbl_filter(is_qf, vim.fn.getwininfo())) if is_open then - vim.cmd(qf .. 'close') + vim.cmd(qf .. "close") else - local ok = pcall(function(c) vim.cmd(c) end, qf .. 'open') - if not ok and qf == 'l' then - vim.notify('No location list', vim.log.levels.WARN) + local ok = pcall(function(c) + vim.cmd(c) + end, qf .. "open") + if not ok and qf == "l" then + vim.notify("No location list", vim.log.levels.WARN) end end end ---Toggle quickfix list. M.toggle_quickfix = function() - toggle_list('c') + toggle_list("c") end ---Toggle location list. M.toggle_loclist = function() - toggle_list('l') + toggle_list("l") end return M -