From 33fe27fd3dfbe21cf1ca9b4ab2b9c960e0ef9dd4 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 20 Aug 2023 23:38:05 +0300 Subject: nvim: nvim-ufo, bunch of fixes --- .config/nvim/lua/core/keymaps.lua | 19 +++--- .config/nvim/lua/core/options.lua | 97 +++++++++++++-------------- .config/nvim/lua/plugins/indent-blankline.lua | 2 +- .config/nvim/lua/plugins/lsp.lua | 18 +---- .config/nvim/lua/plugins/lualine.lua | 63 ++++++++--------- .config/nvim/lua/plugins/nvim-ufo.lua | 78 +++++++++++++++++++++ .config/nvim/lua/plugins/treesitter.lua | 20 +++++- .config/nvim/lua/plugins/vim-illuminate.lua | 16 +++++ .config/nvim/lua/plugins/vimwiki.lua | 1 + 9 files changed, 207 insertions(+), 107 deletions(-) create mode 100644 .config/nvim/lua/plugins/nvim-ufo.lua create mode 100644 .config/nvim/lua/plugins/vim-illuminate.lua (limited to '.config/nvim/lua') diff --git a/.config/nvim/lua/core/keymaps.lua b/.config/nvim/lua/core/keymaps.lua index b63156d..95e5fcd 100644 --- a/.config/nvim/lua/core/keymaps.lua +++ b/.config/nvim/lua/core/keymaps.lua @@ -12,12 +12,11 @@ map("c", "w!!", 'execute "silent! write !sudo tee % >/dev/null" edit!' map("n", "Q", "gq", "format lines") -- set formatprg to sentences, for prose --- TODO: can we do this with vim.o.formatprg? -map("n", "fp", "set formatprg=~/.local/bin/sentences", "switch to sentences view", { silent = false }) +map("n", "fp", ":set formatprg=~/.local/bin/sentences", "switch to sentences formatprg", { silent = false }) -- replace all is aliased to S. -map("n", "S", ":s//g", "replace all", { silent = false }) -map("v", "S", ":s//g", "replace all selection", { silent = false }) +map("n", "S", ":%s//g", "replace all", { silent = false }) +map("v", "S", ":s//g", "replace all", { silent = false }) -- jump to buffer map("n", "b", "ls:b", "jump to buffer") @@ -42,16 +41,16 @@ map("n", "cd", "lcd %:p:h:pwd", "cd to current buffer's pwd -- call CreatePaper on word below cursor map("n", "np", 'gewi[[/papers/Ea]]bb:call CreatePaper(expand(""))', - "vimwiki new paper on word under cursor") + "vimwiki: new paper on word under cursor") -- link paper -map("n", "lp", "gewi[[/papers/Ea]]", "vimwiki link wrap word under cursor") +map("n", "lp", "gewi[[/papers/Ea]]", "vimwiki: link wrap word under cursor") -- call CreateReference on word below cursor -map("n", "nr", 'call CreateReference(expand(""))', "vimwiki new reference word under cursor") +map("n", "nr", 'call CreateReference(expand(""))', "vimwiki: new reference word under cursor") -- create a new note -map("n", "nn", "call CreateNote()", "vimwiki new note for slipbox") +map("n", "nn", "call CreateNote()", "vimwiki: new note for slipbox") -- :%% to get current file path map('c', '%%', "getcmdtype() == ':' ? expand('%:h').'/' : '%%'", "get current file path", { expr = true, silent = false }) @@ -67,6 +66,10 @@ map('v', 'Y', 'myY`y') -- ` is more useful than ' map('n', "'", '`') +-- keep cursor in the middle while doing search +map("n", "n", "nzzzv") +map("n", "N", "Nzzzv") + -- switch between light and dark modes map("n", "ut", function() if vim.o.background == "dark" then diff --git a/.config/nvim/lua/core/options.lua b/.config/nvim/lua/core/options.lua index 3299e83..1a45b8f 100644 --- a/.config/nvim/lua/core/options.lua +++ b/.config/nvim/lua/core/options.lua @@ -1,75 +1,74 @@ local opts = { - -- this might not be needed anymore - termguicolors = true, + -- this might not be needed anymore + termguicolors = true, - -- copy indent on a new line - autoindent = true, + -- copy indent on a new line + autoindent = true, - -- :h tabstop, 2. point - -- use appropriate number of spaces to insert a - expandtab = true, - shiftwidth = 4, - softtabstop = 4, - tabstop = 8, + -- :h tabstop, 2. point + -- use appropriate number of spaces to insert a + expandtab = true, + shiftwidth = 4, + softtabstop = 4, + tabstop = 8, - -- use english for spellchecking - spelllang = "en_gb", + -- use english for spellchecking + spelllang = "en_gb", - -- tab completion, zsh style - wildmode = "longest:full,full", + -- tab completion, zsh style + wildmode = "longest:full,full", - -- put one space for join (not two) - joinspaces = false, + -- put one space for join (not two) + joinspaces = false, - -- keep n lines above/below cursor while scrolling - scrolloff = 4, + -- keep n lines above/below cursor while scrolling + scrolloff = 4, - -- line numbers - number = true, + -- line numbers + number = true, - -- manual folding - foldmethod = "marker", + -- manual folding + foldcolumn = "0", + foldlevel = 99, + foldlevelstart = 99, + foldenable = true, - -- set the terminal title - title = true, + -- set the terminal title + title = true, - -- wrap using 'breakat' character - linebreak = true, + -- wrap using 'breakat' character + linebreak = true, - -- new split panes will split to below and right - splitbelow = true, - splitright = true, + -- new split panes will split to below and right + splitbelow = true, + splitright = true, - -- use relative line numbers - relativenumber = true, + -- use relative line numbers + relativenumber = true, - -- we are already using a cursorline, don't clobber linter messages - showmode = false, + -- we are already using a cursorline, don't clobber linter messages + showmode = false, - -- jump to the matching bracket briefly - showmatch = true, + -- jump to the matching bracket briefly + showmatch = true, - -- persistent undo - undofile = true, + -- persistent undo + undofile = true, - -- lower case searches ignore case, upper case searches do not - ignorecase = true, - smartcase = true, + -- lower case searches ignore case, upper case searches do not + ignorecase = true, + smartcase = true, - -- https://stackoverflow.com/a/3445040/ - -- switch case labels - cinoptions = "l1", + -- https://stackoverflow.com/a/3445040/ + -- switch case labels + cinoptions = "l1", } for opt, val in pairs(opts) do - vim.o[opt] = val + vim.o[opt] = val end --- set other options --- local colorscheme = require("helpers.colorscheme") --- vim.cmd.colorscheme(colorscheme) - -- interact with system clipboard vim.opt.clipboard:append('unnamedplus') @@ -90,7 +89,7 @@ vim.opt.diffopt = { -- menu: use a popup menu to show the possible completions -- preview: show extra information -vim.opt.completeopt = {"menu", "menuone", "noselect"} +vim.opt.completeopt = { "menu", "menuone", "noselect" } if vim.fn.executable("rg") then vim.o.grepprg = "rg --vimgrep --no-heading --smart-case" diff --git a/.config/nvim/lua/plugins/indent-blankline.lua b/.config/nvim/lua/plugins/indent-blankline.lua index 42e5c62..0906298 100644 --- a/.config/nvim/lua/plugins/indent-blankline.lua +++ b/.config/nvim/lua/plugins/indent-blankline.lua @@ -4,7 +4,7 @@ return { init = function() vim.opt.list = true end, - config = { + opts = { show_current_context = true, char = "┊", buftype_exclude = {"terminal"}, diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index d03d9af..8444f4b 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -60,7 +60,7 @@ return { vim.diagnostic.config(config) -- this function gets run when an lsp connects to a particular buffer. - local on_attach = function(client, bufnr) + local on_attach = function(_, bufnr) map = require("helpers.keys").lsp_map map("lr", vim.lsp.buf.rename, bufnr, "lsp: rename symbol") @@ -81,11 +81,6 @@ return { end, { desc = "lsp: format current buffer" }) map("fm", "Format", bufnr, "lsp: format current buffer") - - -- Attach and configure vim-illuminate - -- apparently this is deprecated - -- https://github.com/RRethy/vim-illuminate/issues/111 - require("illuminate").on_attach(client) end -- nvim-cmp supports additional completion capabilities, so broadcast that to servers @@ -211,7 +206,7 @@ return { { "j-hui/fidget.nvim", tag = "legacy", - event = "LspAttach", + event = "VeryLazy", opts = { text = { spinner = "triangle", @@ -224,13 +219,4 @@ return { "simrat39/rust-tools.nvim", event = "LspAttach", }, - -- { - -- "RRethy/vim-illuminate", - -- opts = { - -- filetypes_denylist = { - -- 'NvimTree', - -- 'fugitive', - -- }, - -- }, - -- }, } diff --git a/.config/nvim/lua/plugins/lualine.lua b/.config/nvim/lua/plugins/lualine.lua index c528b69..0da0b89 100644 --- a/.config/nvim/lua/plugins/lualine.lua +++ b/.config/nvim/lua/plugins/lualine.lua @@ -1,45 +1,48 @@ +local function lualine_spell() + if vim.wo.spell then + return "spell" + else + return + end +end + +local conditions = { + spell_on = function () + return vim.wo.spell + end, + filetype_is_tex = function() + return vim.bo.filetype == "tex" + end +} + +-- https://www.reddit.com/r/neovim/comments/u2uc4p/your_lualine_custom_features/i4muvp6/ +-- override 'encoding': don't display if encoding is utf-8. +local encoding = function() + local ret, _ = vim.bo.fenc:gsub("^utf%-8$", "") + return ret +end + +-- fileformat: don't display if &ff is unix. +local fileformat = function() + local ret, _ = vim.bo.fileformat:gsub("^unix$", "") + return ret +end + return { "nvim-lualine/lualine.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() - local function lualine_spell() - if vim.wo.spell then - return "spell" - else - return - end - end - - local conditions = { - spell_on = function () - return vim.wo.spell - end, - filetype_is_tex = function() - return vim.bo.filetype == "tex" - end - } - - -- https://www.reddit.com/r/neovim/comments/u2uc4p/your_lualine_custom_features/i4muvp6/ - -- override 'encoding': don't display if encoding is utf-8. - local encoding = function() - local ret, _ = vim.bo.fenc:gsub("^utf%-8$", "") - return ret - end - - -- fileformat: don't display if &ff is unix. - local fileformat = function() - local ret, _ = vim.bo.fileformat:gsub("^unix$", "") - return ret - end - require("lualine").setup({ options = { icons_enabled = true, theme = "catppuccin", section_separators = { left = '', right = '' }, component_separators = { left = '', right = '' }, + disabled_filetypes = { + "NvimTree", + }, }, sections = { lualine_a = {{'mode', fmt = string.lower}}, diff --git a/.config/nvim/lua/plugins/nvim-ufo.lua b/.config/nvim/lua/plugins/nvim-ufo.lua new file mode 100644 index 0000000..a3d69ba --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-ufo.lua @@ -0,0 +1,78 @@ +return { + { + "kevinhwang91/nvim-ufo", + event = "BufEnter", + keys = { + { + "zR", + function() + require("ufo").openAllFolds() + end, + desc = "ufo: open all folds", + }, + { + "zM", + function() + require("ufo").closeAllFolds() + end, + desc = "ufo: close all folds", + }, + { + "zr", + function() + require("ufo").openFoldsExceptKinds() + end, + desc = "ufo: open folds except kinds", + }, + { + "zm", + function() + require("ufo").closeFoldsWith() + end, + desc = "ufo: close folds with" + }, + { + "zp", + function() + require("ufo").peekFoldedLinesUnderCursor() + end, + desc = "ufo: peek fold" + }, + }, + dependencies = { + "kevinhwang91/promise-async", + }, + opts = { + preview = { + mappings = { + scrollB = "", + scrollF = "", + scrollU = "", + scrollD = "", + }, + }, + provider_selector = function(_, filetype, buftype) + local function handleFallbackException(bufnr, err, providerName) + if type(err) == "string" and err:match("UfoFallbackException") then + return require("ufo").getFolds(bufnr, providerName) + else + return require("promise").reject(err) + end + end + + return (filetype == "" or buftype == "nofile") and + "indent" -- only use indent until a file is opened + or function(bufnr) + return require("ufo") + .getFolds(bufnr, "lsp") + :catch(function(err) + return handleFallbackException(bufnr, err, "treesitter") + end) + :catch(function(err) + return handleFallbackException(bufnr, err, "indent") + end) + end + end, + }, + } +} diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua index c454b48..c462ec8 100644 --- a/.config/nvim/lua/plugins/treesitter.lua +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -9,8 +9,22 @@ return { }, config = function() require("nvim-treesitter.configs").setup({ - ensure_installed = { "bash", "bibtex", "c", "cpp", "css", "fish", "http", "latex", "lua", "python", "rust", "vim" }, - ignore_install = { }, + ensure_installed = { + "bash", + "bibtex", + "c", + "cpp", + "css", + "fish", + "http", + "latex", + "lua", + "python", + "rust", + "toml", + "vim", + }, + ignore_install = {}, auto_install = true, sync_install = false, highlight = { @@ -66,7 +80,7 @@ return { }, }, }, - modules = { }, + modules = {}, }) end, }, diff --git a/.config/nvim/lua/plugins/vim-illuminate.lua b/.config/nvim/lua/plugins/vim-illuminate.lua new file mode 100644 index 0000000..451ffdb --- /dev/null +++ b/.config/nvim/lua/plugins/vim-illuminate.lua @@ -0,0 +1,16 @@ +return { + { + "RRethy/vim-illuminate", + event = "BufEnter", + opts = { + filetypes_denylist = { + "NvimTree", + "fugitive", + "TelescopePrompt" + }, + }, + config = function(_, opts) + require("illuminate").configure(opts) + end, + }, +} diff --git a/.config/nvim/lua/plugins/vimwiki.lua b/.config/nvim/lua/plugins/vimwiki.lua index 11d4c2b..352c01a 100644 --- a/.config/nvim/lua/plugins/vimwiki.lua +++ b/.config/nvim/lua/plugins/vimwiki.lua @@ -15,6 +15,7 @@ return { auto_tags = 1 } } + vim.g.vimwiki_global_ext = 0 vim.g.vimwiki_hl_headers = 1 local map = require("helpers.keys").map -- cgit v1.2.3-70-g09d2