Add color highlighting for some comment keywords

This commit is contained in:
juanmagalhaes 2023-08-15 18:18:19 -03:00
parent aa1b35c68b
commit 64dac6ac02
4 changed files with 99 additions and 23 deletions

View File

@ -79,19 +79,19 @@ pcall(require('telescope').load_extension, 'fzf')
-- vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
--[[
vim.keymap.set('n', '<leader>/', 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', '<C-p>', 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', '<C-a>', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<C-a>', fuzzyFindFiles, { desc = '[S]earch by [G]rep' })
vim.keymap.set('n', '<C-s>', require('telescope.builtin').live_grep, { desc = '[S]earch Live Exact Match' })
vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })

View File

@ -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',

View File

@ -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')

View File

@ -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
}