From 64dac6ac02d6d73dafcabc4bb824aad44626c588 Mon Sep 17 00:00:00 2001 From: juanmagalhaes Date: Tue, 15 Aug 2023 18:18:19 -0300 Subject: [PATCH] Add color highlighting for some comment keywords --- init.lua | 20 ++++----- lua/plugins/init.lua | 4 ++ lua/plugins/nvim-ufo.lua | 22 +++++----- lua/plugins/todo-comments.lua | 76 +++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 lua/plugins/todo-comments.lua diff --git a/init.lua b/init.lua index 8e93b7ce..292c4bc2 100644 --- a/init.lua +++ b/init.lua @@ -79,19 +79,19 @@ pcall(require('telescope').load_extension, 'fzf') -- vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) ---[[ - vim.keymap.set('n', '/', function() - -- You can pass additional configuration to telescope to change theme, layout, etc. - require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { - winblend = 10, - previewer = false, - }) - end, { desc = '[/] Fuzzily search in current buffer' }) ---]] +local function fuzzyFindFiles() + require('telescope.builtin').grep_string({ + path_display = { 'smart' }, + only_sort_text = true, + word_match = "-w", + search = '', + }) +end vim.keymap.set('n', '', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' }) vim.keymap.set('n', 'K', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' }) -vim.keymap.set('n', '', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) +vim.keymap.set('n', '', fuzzyFindFiles, { desc = '[S]earch by [G]rep' }) +vim.keymap.set('n', '', require('telescope.builtin').live_grep, { desc = '[S]earch Live Exact Match' }) vim.keymap.set('n', 'sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' }) vim.keymap.set('n', 'sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' }) vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 29579e9d..93476f9c 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -61,6 +61,7 @@ local plugins = { -- Theme inspired by Atom 'Mofiqul/dracula.nvim', priority = 1000, + lazy = false, config = function() vim.cmd.colorscheme 'dracula' end, @@ -122,6 +123,7 @@ local plugins = { build = ':TSUpdate', }, + -- Multiple cursors { "mg979/vim-visual-multi", branch = "master" @@ -129,6 +131,8 @@ local plugins = { -- require plugins with more complex config + require 'plugins.todo-comments', + require 'plugins.neo-tree', require 'plugins.nvim-ufo', diff --git a/lua/plugins/nvim-ufo.lua b/lua/plugins/nvim-ufo.lua index 57ade383..9c5215d3 100644 --- a/lua/plugins/nvim-ufo.lua +++ b/lua/plugins/nvim-ufo.lua @@ -32,10 +32,12 @@ local function applyFoldsAndThenCloseAllFolds(bufnr, providerName) -- make sure buffer is attached require('ufo').attach(bufnr) -- getFolds return Promise if providerName == 'lsp' - local ranges = await(require('ufo').getFolds(bufnr, providerName)) - local ok = require('ufo').applyFolds(bufnr, ranges) - if ok then - require('ufo').closeFoldsWith(1) + local ok, ranges = pcall(await, require('ufo').getFolds(bufnr, providerName)) + if ok and ranges then + ok = require('ufo').applyFolds(bufnr, ranges) + if ok then + require('ufo').closeFoldsWith(1) + end end end) end @@ -59,18 +61,12 @@ return { end, }, }, - event = "BufReadPost", - opts = { - provider_selector = function() - return { "treesitter", "indent" } - end, - }, + event = "VeryLazy", init = function() vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]] vim.o.foldcolumn = '1' - vim.o.foldnestmax = 1 vim.o.foldlevel = 99 - vim.o.foldlevelstart = 1 + vim.o.foldlevelstart = 99 vim.o.foldenable = true end, config = function(_, opts) @@ -82,7 +78,7 @@ return { require("ufo").setup(newOpts) - vim.api.nvim_create_autocmd('BufRead', { + vim.api.nvim_create_autocmd('BufWinEnter', { pattern = '*', callback = function(e) applyFoldsAndThenCloseAllFolds(e.buf, 'lsp') diff --git a/lua/plugins/todo-comments.lua b/lua/plugins/todo-comments.lua new file mode 100644 index 00000000..5a5e0cc5 --- /dev/null +++ b/lua/plugins/todo-comments.lua @@ -0,0 +1,76 @@ +-- Highlight comment keywords like: + +-- PERF +-- HACK +-- TODO +-- NOTE +-- FIX +-- WARNING +-- TEST + +return { + "folke/todo-comments.nvim", + dependencies = { "nvim-lua/plenary.nvim" }, + lazy = false, + config = function() + local colors = require('dracula').colors() + + require('todo-comments').setup({ + signs = true, -- show icons in the signs column + sign_priority = 8, -- sign priority + + TODO = { icon = " ", color = "info" }, + PERF = { icon = " ", color = "default", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + HACK = { icon = "✇ ", color = "warning" }, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + NOTE = { icon = "✐", color = "hint", alt = { "INFO" } }, + TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + FIX = { icon = " ", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" } }, + + gui_style = { + fg = "NONE", -- The gui style to use for the fg highlight group. + bg = "BOLD", -- The gui style to use for the bg highlight group. + }, + merge_keywords = true, -- when true, custom keywords will be merged with the defaults + + highlight = { + multiline = true, -- enable multine todo comments + multiline_pattern = "^.", -- lua pattern to match the next multiline from the start of the matched keyword + multiline_context = 10, -- extra lines that will be re-evaluated when changing a line + before = "", -- "fg" or "bg" or empty + keyword = "bg", -- "fg", "bg", "wide", "wide_bg", "wide_fg" or empty. (wide and wide_bg is the same as bg, but will also highlight surrounding characters, wide_fg acts accordingly but with fg) + after = "fg", -- "fg" or "bg" or empty + pattern = [[(KEYWORDS)]], -- pattern or table of patterns, used for highlighting (vim regex) + comments_only = true, -- uses treesitter to match keywords in comments only + max_line_len = 400, -- ignore lines longer than this + exclude = {}, -- list of file types to exclude highlighting + }, + + -- list of named colors where we try to extract the guifg from the + -- list of highlight groups or use the hex color if hl not found as a fallback + colors = { + error = colors.red, + warning = colors.yellow, + info = colors.cyan, + hint = colors.purple, + default = colors.pink, + test = colors.green, + }, + + search = { + command = "rg", + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + -- regex that will be used to match keywords. + -- don't replace the (KEYWORDS) placeholder + pattern = [[(KEYWORDS)]], -- ripgrep regex + -- pattern = [[\b(KEYWORDS)\b]], -- match without the extra colon. You'll likely get false positives + }, + }) + end +}