All Projects → kevinhwang91 → Nvim Hlslens

kevinhwang91 / Nvim Hlslens

Licence: bsd-3-clause
Hlsearch Lens for Neovim

Programming Languages

lua
6591 projects

Projects that are alternatives of or similar to Nvim Hlslens

Chadtree
File manager for Neovim. Better than NERDTree.
Stars: ✭ 653 (+1087.27%)
Mutual labels:  neovim, nvim, neovim-plugin
Semshi
🌈 Semantic Highlighting for Python in Neovim
Stars: ✭ 758 (+1278.18%)
Mutual labels:  neovim, nvim, neovim-plugin
Lualine.nvim
A blazing fast and easy to configure neovim statusline written in pure lua.
Stars: ✭ 198 (+260%)
Mutual labels:  neovim, nvim, neovim-plugin
Nvim Bqf
Better quickfix window in Neovim, polish old quickfix window.
Stars: ✭ 120 (+118.18%)
Mutual labels:  neovim, nvim, neovim-plugin
agitator.nvim
No description or website provided.
Stars: ✭ 16 (-70.91%)
Mutual labels:  neovim, nvim, neovim-plugin
Nvim Compe
Auto completion plugin for nvim that written in Lua.
Stars: ✭ 433 (+687.27%)
Mutual labels:  neovim, nvim, neovim-plugin
Comment.nvim
🧠 💪 // Smart and powerful comment plugin for neovim. Supports treesitter, dot repeat, left-right/up-down motions, hooks, and more
Stars: ✭ 796 (+1347.27%)
Mutual labels:  neovim, nvim, neovim-plugin
Acid.nvim
Asynchronous Clojure Interactive Development
Stars: ✭ 147 (+167.27%)
Mutual labels:  neovim, nvim, neovim-plugin
nvim-ghost.nvim
👻 GhostText plugin for Neovim with zero dependencies 🎉 Supports neovim running inside WSL too! 🥳 Windows/Linux/macOS supported out-of-the-box! 😄 (Other OSes need python3.6+ installed)
Stars: ✭ 32 (-41.82%)
Mutual labels:  neovim, nvim, neovim-plugin
close-buffers.nvim
📑 Delete multiple vim buffers based on different conditions
Stars: ✭ 54 (-1.82%)
Mutual labels:  neovim, nvim, neovim-plugin
Lsp Status.nvim
Utility functions for getting diagnostic status and progress messages from LSP servers, for use in the Neovim statusline
Stars: ✭ 201 (+265.45%)
Mutual labels:  neovim, nvim, neovim-plugin
Iron.nvim
Interactive Repl Over Neovim
Stars: ✭ 265 (+381.82%)
Mutual labels:  neovim, nvim, neovim-plugin
lir.nvim
Neovim file explorer
Stars: ✭ 194 (+252.73%)
Mutual labels:  neovim, nvim, neovim-plugin
neogen
A better annotation generator. Supports multiple languages and annotation conventions.
Stars: ✭ 339 (+516.36%)
Mutual labels:  neovim, nvim, neovim-plugin
Packer.nvim
A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
Stars: ✭ 418 (+660%)
Mutual labels:  neovim, nvim, neovim-plugin
Vim Markdown Composer
An asynchronous markdown preview plugin for Vim and Neovim.
Stars: ✭ 501 (+810.91%)
Mutual labels:  neovim, neovim-plugin
Tmux Complete.vim
Vim plugin for insert mode completion of words in adjacent tmux panes
Stars: ✭ 447 (+712.73%)
Mutual labels:  neovim, neovim-plugin
Deoplete Jedi
deoplete.nvim source for Python
Stars: ✭ 559 (+916.36%)
Mutual labels:  neovim, neovim-plugin
Neovim Dots
most beautiful neovim cli setup
Stars: ✭ 547 (+894.55%)
Mutual labels:  neovim, nvim
Alchemist.vim
Elixir Integration Into Vim
Stars: ✭ 632 (+1049.09%)
Mutual labels:  neovim, neovim-plugin

nvim-hlslens

nvim-hlslens helps you better glance searched information, seamlessly jump matched instances.

Table of contents

Features

  • Fully customizable style of virtual text
  • Display virtual text dynamicly while cursor is moving
  • Clear highlighting and virtual text when cursor is out of range

Quickstart

Requirements

Installation

Install nvim-hlslens with your favorite plugin manager! For instance: Vim-plug:

Plug 'kevinhwang91/nvim-hlslens'

The default branch is main, please upgrade vim-plug if you encounter any installation issues.

Minimal configuration

Plug 'kevinhwang91/nvim-hlslens'

noremap <silent> n <Cmd>execute('normal! ' . v:count1 . 'n')<CR>
            \<Cmd>lua require('hlslens').start()<CR>
noremap <silent> N <Cmd>execute('normal! ' . v:count1 . 'N')<CR>
            \<Cmd>lua require('hlslens').start()<CR>
noremap * *<Cmd>lua require('hlslens').start()<CR>
noremap # #<Cmd>lua require('hlslens').start()<CR>
noremap g* g*<Cmd>lua require('hlslens').start()<CR>
noremap g# g#<Cmd>lua require('hlslens').start()<CR>

" use : instead of <Cmd>
nnoremap <silent> <leader>l :nohlsearch<CR>

3 ways to start hlslens

  1. Press / or ? to search text
  2. Press n or N to jump to the instance matched by last pattern
  3. Press *, #, g* or g# to search word nearest to the cursor

run ex command :help search-commands for more information.

Stop hlslens

In CmdlineLeave event, hlslens will listen whether nohlsearch is entered.

  1. Run ex command nohlsearch
  2. Map key to :nohlsearch, make sure that to use : instead of <Cmd>

Default Settings

Setup

setup({
    -- enable hlslens after searching
    -- type: boolean
    auto_enable = true,
    -- if calm_down is true, stop hlslens when cursor is out of position range
    -- type: boolean
    calm_down = false,
    -- hackable function for customizing the virtual text
    -- type: function(lnum, loc, idx, r_idx, count, hls_ns)
    override_line_lens = nil
})

Highlight

highlight default link HlSearchLensCur IncSearch
highlight default link HlSearchLens WildMenu
highlight default link HlSearchCur IncSearch
  1. HlSearchLensCur: highlight the current or the nearest virtual text
  2. HlSearchLens: highlight virtual texts but except for HlSearchLensCur
  3. HlSearchCur: highlight the current or the nearest text instance

Function

  1. enable(): enable hlslens, create autocmd event
  2. disable(): disable hlslens, clear any context and autocmd event of hlslens
  3. start(): enable hlslens and refresh virtual text immediately
  4. setup(): when auto_enable = false, must manually invoke enable() or start() for enabling hlslens
  5. get_config(): return current configuration
  6. override_line_lens: override add_line_lens

Advanced configuration

Customize virtual text

Plug 'kevinhwang91/nvim-hlslens'

" below code after `call plug#end()`, make sure 'hlslens' have been loaded in lua path
lua <<EOF
require('hlslens').setup({
    override_line_lens = function(lnum, loc, idx, r_idx, count, hls_ns)
        local sfw = vim.v.searchforward == 1
        local indicator, text, chunks
        local a_r_idx = math.abs(r_idx)
        if a_r_idx > 1 then
            indicator = string.format('%d%s', a_r_idx, sfw ~= (r_idx > 1) and '▲' or '▼')
        elseif a_r_idx == 1 then
            indicator = sfw ~= (r_idx == 1) and '▲' or '▼'
        else
            indicator = ''
        end

        if loc ~= 'c' then
            text = string.format('[%s %d]', indicator, idx)
            chunks = {{' ', 'Ignore'}, {text, 'HlSearchLens'}}
        else
            if indicator ~= '' then
                text = string.format('[%s %d/%d]', indicator, idx, count)
            else
                text = string.format('[%d/%d]', idx, count)
            end
            chunks = {{' ', 'Ignore'}, {text, 'HlSearchLensCur'}}
            vim.api.nvim_buf_clear_namespace(0, hls_ns, lnum - 1, lnum)
        end
        vim.api.nvim_buf_set_virtual_text(0, hls_ns, lnum - 1, chunks, {})
    end
})
EOF

Integrate with other plugins

Plug 'kevinhwang91/nvim-hlslens'

" integrate with vim-asterisk
Plug 'haya14busa/vim-asterisk'
map *  <Plug>(asterisk-z*)<Cmd>lua require('hlslens').start()<CR>
map #  <Plug>(asterisk-z#)<Cmd>lua require('hlslens').start()<CR>
map g* <Plug>(asterisk-gz*)<Cmd>lua require('hlslens').start()<CR>
map g# <Plug>(asterisk-gz#)<Cmd>lua require('hlslens').start()<CR>

" integrate with vim-visual-multi
Plug 'mg979/vim-visual-multi'
augroup VMlens
    autocmd!
    autocmd User visual_multi_start lua require('vmlens').vmlens_start()
    autocmd User visual_multi_exit lua require('vmlens').vmlens_exit()
augroup END

" below code after `call plug#end()`, make sure 'hlslens' have been loaded in lua path
lua require('hlslens').setup({calm_down = true})

Add vmlens.lua under your lua path, for instance: ~/.config/nvim/lua/vmlens.lua

M = {}
local hlslens = require('hlslens')
local hlslens_started = false
local line_lens_bak

local override_line_lens = function(lnum, loc, idx, r_idx, count, hls_ns)
    local text, chunks
    if loc ~= 'c' then
        text = string.format('[%d]', idx)
        chunks = {{' ', 'Ignore'}, {text, 'HlSearchLens'}}
    else
        text = string.format('[%d/%d]', idx, count)
        chunks = {{' ', 'Ignore'}, {text, 'HlSearchLensCur'}}
        vim.api.nvim_buf_clear_namespace(0, hls_ns, lnum - 1, lnum)
    end
    vim.api.nvim_buf_set_virtual_text(0, hls_ns, lnum - 1, chunks, {})
end

function M.vmlens_start()
    if not hlslens then
        return
    end
    local config = hlslens.get_config()
    line_lens_bak = config.override_line_lens
    config.override_line_lens = override_line_lens
    hlslens_started = config.started
    if hlslens_started then
        hlslens.disable()
    end
    hlslens.start()
end

function M.vmlens_exit()
    if not hlslens then
        return
    end
    local config = hlslens.get_config()
    config.override_line_lens = line_lens_bak
    hlslens.disable()
    if hlslens_started then
        hlslens.start()
    end
end

return M

Limitation

nvim-hlslens add virtual text via nvim_buf_set_virtual_text without priority, so nvim-hlslens can't override the existed lens added by other plugins, you can use override_line_lens function to get the existed lens' namespace, delete and set them again.

Feedback

  • If you get an issue or come up with an awesome idea, don't hesitate to open an issue in github.
  • If you think this plugin is useful or cool, consider rewarding it a star.

License

The project is licensed under a BSD-3-clause license. See LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].