Skip to content

super-fast cursor word highlighting with callbacks(I call them murmurs) included.

Notifications You must be signed in to change notification settings

nyngwang/murmur.lua

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

murmur.lua

Intro.

Cursorword highlighting with callbacks support(I call this murmuring). Created with performance in mind.

DEMO

Dynamic coloring of your cursorword:

demo_murmur_cursor_rgb.mov

IDE-like no blinking diagnostic message with cursor scope.

murmur_no_blinking_on_cursormoved.mov

Example Setup.

Commented lines are the default.

local FOO = 'your_augroup_name'
vim.api.nvim_create_augroup(FOO, { clear = true })

use {
  'nyngwang/murmur.lua',
  config = function ()
    require('murmur').setup {
      -- cursor_rgb = {
      --  guibg = '#393939',
      -- },
      -- cursor_rgb_always_use_config = false, -- if set to `true`, then always use `cursor_rgb`.
      -- yank_blink = {
      --   enabled = true,
      --   on_yank = nil, -- Can be customized. See `:h on_yank`.
      -- },
      max_len = 80,
      min_len = 3, -- this is recommended since I prefer no cursorword highlighting on `if`.
      exclude_filetypes = {},
      callbacks = {
        -- to trigger the close_events of vim.diagnostic.open_float.
        function ()
          -- Close floating diag. and make it triggerable again.
          vim.api.nvim_exec_autocmds("User", { pattern = "MurmurDiagnostics" })
          vim.w.diag_shown = false
        end,
      }
    }

    -- To create IDE-like no blinking diagnostic message with `cursor` scope. (should be paired with the callback above)
    vim.api.nvim_create_autocmd('CursorHold', {
      group = FOO,
      pattern = '*',
      callback = function ()
        -- skip when a float-win already exists.
        if vim.w.diag_shown then return end

        -- open float-win when hovering on a cursor-word.
        if vim.w.cursor_word ~= "" then
          local buf = vim.diagnostic.open_float({
            scope = "cursor",
            -- Only close the window on InsertEnter and the explicit diagnostic close event
            close_events = { "InsertEnter", "User MurmurDiagnostics" },
          })
          -- If the window closes for any reason *other* than it being closed by a callback,
          -- make it triggerable again
          vim.api.nvim_create_autocmd("WinClosed", {
            group = FOO,
            buffer = buf,
            once = true,
            callback = function() vim.w.diag_shown = false end,
          })
          vim.w.diag_shown = true
        else
          vim.w.diag_shown = false
        end
      end
    })

    -- To create special cursorword coloring for the colortheme `typewriter-night`.
    -- remember to change it to the name of yours.
    vim.api.nvim_create_autocmd({ 'ColorScheme' }, {
      group = FOO,
      pattern = 'typewriter-night',
      callback = function ()
        vim.api.nvim_set_hl(0, "murmur_cursor_rgb", { fg = "#0a100d", bg = "#ffee32" })
      end
    })
  end
}

Reference

Extended from the original project: xiyaowong / nvim-cursorword

Comparison

demo_david.mov

About

super-fast cursor word highlighting with callbacks(I call them murmurs) included.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published