All Projects → RRethy → Vim Illuminate

RRethy / Vim Illuminate

illuminate.vim - Vim plugin for automatically highlighting other uses of the word under the cursor. Integrates with Neovim's LSP client for intelligent highlighting.

Labels

Projects that are alternatives of or similar to Vim Illuminate

Fzf Preview.vim
The plugin that powerfully integrates fzf and (Neo)vim. It is also possible to integrate with coc.nvim.
Stars: ✭ 563 (-21.91%)
Mutual labels:  neovim
Coc Tsserver
Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
Stars: ✭ 602 (-16.5%)
Mutual labels:  neovim
Asyncomplete.vim
async completion in pure vim script for vim8 and neovim
Stars: ✭ 654 (-9.29%)
Mutual labels:  neovim
Tagbar
Vim plugin that displays tags in a window, ordered by scope
Stars: ✭ 5,322 (+638.14%)
Mutual labels:  neovim
Gina.vim
👣 Asynchronously control git repositories in Neovim/Vim 8
Stars: ✭ 587 (-18.59%)
Mutual labels:  neovim
Jarvis
Dotfiles for a powerful, web development-focused environment powered by Neovim, iTerm2, tmux, and zsh
Stars: ✭ 617 (-14.42%)
Mutual labels:  neovim
Fern.vim
🌿 General purpose asynchronous tree viewer written in Pure Vim script
Stars: ✭ 552 (-23.44%)
Mutual labels:  neovim
Vim Quickui
The missing UI extensions for Vim 8.2 (and NeoVim 0.4) !! 😎
Stars: ✭ 714 (-0.97%)
Mutual labels:  neovim
Neovim Dots
most beautiful neovim cli setup
Stars: ✭ 547 (-24.13%)
Mutual labels:  neovim
Chadtree
File manager for Neovim. Better than NERDTree.
Stars: ✭ 653 (-9.43%)
Mutual labels:  neovim
Conjure
Interactive evaluation for Neovim (Clojure, Fennel, Janet, Racket, Hy, MIT Scheme, Guile)
Stars: ✭ 569 (-21.08%)
Mutual labels:  neovim
Vimr
Project VimR is a Neovim GUI for macOS. The goal is to build an editor that uses Neovim inside with many of the convenience GUI features similar to those present in modern editors. We mainly use Swift, but also use C/Objective-C when where appropriate.
Stars: ✭ 5,524 (+666.16%)
Mutual labels:  neovim
Alchemist.vim
Elixir Integration Into Vim
Stars: ✭ 632 (-12.34%)
Mutual labels:  neovim
Evervim
A Modern, Powerful & Modular Vim Distribution
Stars: ✭ 568 (-21.22%)
Mutual labels:  neovim
Neovim Gtk
gtk ui for neovim
Stars: ✭ 670 (-7.07%)
Mutual labels:  neovim
Deoplete Jedi
deoplete.nvim source for Python
Stars: ✭ 559 (-22.47%)
Mutual labels:  neovim
Nvim Typescript
Typescript tooling for Neovim
Stars: ✭ 609 (-15.53%)
Mutual labels:  neovim
Far.vim
Find And Replace Vim plugin
Stars: ✭ 717 (-0.55%)
Mutual labels:  neovim
Context.vim
Vim plugin that shows the context of the currently visible buffer contents
Stars: ✭ 688 (-4.58%)
Mutual labels:  neovim
Dotfiles
Zsh, Karabiner, VS Code, Sublime, Neovim, Nix
Stars: ✭ 634 (-12.07%)
Mutual labels:  neovim

vim-illuminate

Vim plugin for automatically highlighting other uses of the current word under the cursor

gif

Rationale

All modern IDEs and editors will highlight the word under the cursor which is a great way to see other uses of the current variable without having to look for it.

About

This plugin is a tool for illuminating the other uses of the current word under the cursor.

If Neovim's builtin LSP is available, it can be used to highlight more intelligently.

Otherwise, Illuminate will by default highlight all uses of the word under the cursor, but with a little bit of configuration it can easily only highlight what you want it to highlight based on the filetype and highlight-groups.

Illuminate will also do a few other niceties such as delaying the highlight for a user-defined amount of time based on g:Illuminate_delay (by default 0), it will interact nicely with search highlighting, jumping around between buffers, jumping around between windows, and won't illuminate while in insert mode (unless told to).

LSP Configuration

vim-illuminate can use Neovim's builtin LSP client to intelligently highlight. This is not compatible with |illuminate-configuration| with a few exceptions explained below.

To set it up, simply call on_attach when the LSP client attaches to a buffer. For example, if you want gopls to be used by vim-illuminate:

  require'lspconfig'.gopls.setup {
    on_attach = function(client)
      -- [[ other on_attach code ]]
      require 'illuminate'.on_attach(client)
    end,
  }

Highlighting is done using the same highlight groups as the builtin LSP which is LspReferenceText, LspReferenceRead, and LspReferenceWrite.

  vim.api.nvim_command [[ hi def link LspReferenceText CursorLine ]]
  vim.api.nvim_command [[ hi def link LspReferenceWrite CursorLine ]]
  vim.api.nvim_command [[ hi def link LspReferenceRead CursorLine ]]

The other additional configuration currently supported is g:Illuminate_delay.

You can cycle through these document highlights with these mappings:

vim.api.nvim_set_keymap('n', '<a-n>', '<cmd>lua require"illuminate".next_reference{wrap=true}<cr>', {noremap=true})
vim.api.nvim_set_keymap('n', '<a-p>', '<cmd>lua require"illuminate".next_reference{reverse=true,wrap=true}<cr>', {noremap=true})

I used alt+n and alt+p but you can map to whatever.

Configuration

Illuminate will delay before highlighting, this is not lag, it is to avoid the jarring experience of things illuminating too fast. This can be controlled with g:Illuminate_delay (which is default to 0 milliseconds):

Note: Delay only works for Vim8 and Neovim.

" Time in milliseconds (default 0)
let g:Illuminate_delay = 0

Illuminate will by default highlight the word under the cursor to match the behaviour seen in Intellij and VSCode. However, to make it not highlight the word under the cursor, use the following:

" Don't highlight word under cursor (default: 1)
let g:Illuminate_highlightUnderCursor = 0

By default illuminate will highlight all words the cursor passes over, but for many languages, you will only want to highlight certain highlight-groups (you can determine the highlight-group of a symbol under your cursor with :echo synIDattr(synID(line("."), col("."), 1), "name")).

You can define which highlight groups you want the illuminating to apply to. This can be done with a dict mapping a filetype to a list of highlight-groups in your vimrc such as:

let g:Illuminate_ftHighlightGroups = {
      \ 'vim': ['vimVar', 'vimString', 'vimLineComment',
      \         'vimFuncName', 'vimFunction', 'vimUserFunc', 'vimFunc']
      \ }

A blacklist of highlight groups can also be setup by adding the suffix :blacklist to the filetype. However, if the whitelist for that filetype already exists, it will override the blacklist.

let g:Illuminate_ftHighlightGroups = {
      \ 'vim:blacklist': ['vimVar', 'vimString', 'vimLineComment',
      \         'vimFuncName', 'vimFunction', 'vimUserFunc', 'vimFunc']
      \ }

illuminate can also be disabled for various filetypes using the following:

let g:Illuminate_ftblacklist = ['nerdtree']

Or you can enable it only for certain filetypes with:

let g:Illuminate_ftwhitelist = ['vim', 'sh', 'python']

By default the highlighting will be done with the highlight-group CursorLine since that is in my opinion the nicest. It can however be overridden using the following (use standard Vim highlighting syntax): Note: It must be in an autocmd to get around a weird Neovim behaviour.

augroup illuminate_augroup
    autocmd!
    autocmd VimEnter * hi link illuminatedWord CursorLine
augroup END

" or

augroup illuminate_augroup
    autocmd!
    autocmd VimEnter * hi illuminatedWord cterm=underline gui=underline
augroup END

Lastly, you can also specify a specific highlight for the word under the cursor so it differs from all other matches using the following higlight group:

augroup illuminate_augroup
    autocmd!
    autocmd VimEnter * hi illuminatedCurWord cterm=italic gui=italic
augroup END

Installation

This assumes you have the packages feature. If not, any plugin manager will suffice.

Neovim

mkdir -p ~/.config/nvim/pack/plugins/start
cd ~/.config/nvim/pack/plugins/start
git clone https://github.com/RRethy/vim-illuminate.git

Vim

mkdir -p ~/.vim/pack/plugins/start
cd ~/.vim/pack/plugins/start
git clone https://github.com/RRethy/vim-illuminate.git

FAQs

I am seeing by default an underline for the matched words

Try this: hi link illuminatedWord Visual. The reason for the underline is that the highlighting is done with CursorLine by default, which defaults to an underline.

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].