🦎 A NeoVim plugin for highlighting visual selections like in a normal document editor!

Overview

🦎 HighStr.nvim

A NeoVim plugin for highlighting visual selections like in a normal document editor!

Repository's starts Issues License
Say thanks Latest commit GitHub repository size

Demo


TL;DR

HighStr.nvim is a NeoVim plugin written in Lua that aims to provide a the simple functionality of highlighting text like one would do in a normal document editor. To use it, install it with your favorite plugin manager, select something in visual mode and then run :HSHighlight. You can also add keybindings to the commands.

🌲 Table of Contents

🎁 Features

  • Highlight visual selection in any given pre-defined color.
  • Remove highlighting from lines in visual selection.
  • Users can set up foreground and background of any color.
  • Has a "smart" option to set foreground based on background.
  • Users can add any amount of colors.
  • Produce a verbose output for debugging (optional).
  • Export and import highlights!

πŸ“Ί Notices

Checkout the CHANGELOG.md file for more information on the notices below:

  • 16-08-21: Fixed #6: properly highlight imported highlights.
  • 30-07-21: Feat #1: import and export highlights!
  • 26-05-21: Fixed bug that prevented adding new colors and added option to remove all highlighting from the current buffer
  • 25-05-21: Just released!

πŸ“¦ Installation

Prerequisites

  • NeoVim nightly (>=v0.5.0)
  • A nice color scheme to complement your experience ;)

Adding the plugin

You can use your favorite plugin manager for this. Here are some examples with the most popular ones:

Vim-plug

Plug 'Pocco81/HighStr.nvim'

Packer.nvim

use "Pocco81/HighStr.nvim"

Vundle

Plugin 'Pocco81/HighStr.nvim'

NeoBundle

NeoBundleFetch 'Pocco81/HighStr.nvim'

Setup (configuration)

As it's stated in the TL;DR, there are already some sane defaults that you may like, however you can change them to match your taste. These are the defaults:

verbosity = 0,
saving_path = "/tmp/highstr/",
highlight_colors = {
	color_0 = {"#0c0d0e", "smart"},	-- Cosmic charcoal
	color_1 = {"#e5c07b", "smart"},	-- Pastel yellow
	color_2 = {"#7FFFD4", "smart"},	-- Aqua menthe
	color_3 = {"#8A2BE2", "smart"},	-- Proton purple
	color_4 = {"#FF4500", "smart"},	-- Orange red
	color_5 = {"#008000", "smart"},	-- Office green
	color_6 = {"#0000FF", "smart"},	-- Just blue
	color_7 = {"#FFC0CB", "smart"},	-- Blush pink
	color_8 = {"#FFF9E3", "smart"},	-- Cosmic latte
	color_9 = {"#7d5c34", "smart"},	-- Fallow brown
}

The way you setup the settings on your config varies on whether you are using vimL for this or Lua.

For init.lua

local high_str = require("high-str")

high_str.setup({
	verbosity = 0,
	saving_path = "/tmp/highstr/",
	highlight_colors = {
		-- color_id = {"bg_hex_code",<"fg_hex_code"/"smart">}
		color_0 = {"#0c0d0e", "smart"},	-- Cosmic charcoal
		color_1 = {"#e5c07b", "smart"},	-- Pastel yellow
		color_2 = {"#7FFFD4", "smart"},	-- Aqua menthe
		color_3 = {"#8A2BE2", "smart"},	-- Proton purple
		color_4 = {"#FF4500", "smart"},	-- Orange red
		color_5 = {"#008000", "smart"},	-- Office green
		color_6 = {"#0000FF", "smart"},	-- Just blue
		color_7 = {"#FFC0CB", "smart"},	-- Blush pink
		color_8 = {"#FFF9E3", "smart"},	-- Cosmic latte
		color_9 = {"#7d5c34", "smart"},	-- Fallow brown
	}
})

For init.vim

lua << EOF
local high_str = require("high-str")


high_str.setup({
	verbosity = 0,
	saving_path = "/tmp/highstr/",
	highlight_colors = {
		-- color_id = {"bg_hex_code",<"fg_hex_code"/"smart">}
		color_0 = {"#0c0d0e", "smart"},	-- Cosmic charcoal
		color_1 = {"#e5c07b", "smart"},	-- Pastel yellow
		color_2 = {"#7FFFD4", "smart"},	-- Aqua menthe
		color_3 = {"#8A2BE2", "smart"},	-- Proton purple
		color_4 = {"#FF4500", "smart"},	-- Orange red
		color_5 = {"#008000", "smart"},	-- Office green
		color_6 = {"#0000FF", "smart"},	-- Just blue
		color_7 = {"#FFC0CB", "smart"},	-- Blush pink
		color_8 = {"#FFF9E3", "smart"},	-- Cosmic latte
		color_9 = {"#7d5c34", "smart"},	-- Fallow brown
	}
})
EOF

For instructions on how to configure the plugin, check out the configuration section.

Updating

This depends on your plugin manager. If, for example, you are using Packer.nvim, you can update it with this command:

:PackerUpdate

πŸ€– Usage (commands)

All the commands follow the camel casing naming convention and have the HS prefix so that it's easy to remember that they are part of the HighStr.nvim plugin. These are all of them:

Default

  • :HSHighlight <integer>: highlights current visual selection and receives an <integer> that indicates which colors to use from the highlight_colors = {} table; if none is given, HighStr.nvim will pick color_1.
  • :HSRmHighlight <rm_all>: If the rm_all argument is given, removes all the highlighting in the current buffer. If not, does the same but for every line in visual selection.
  • :HSExport: exports highlights from the current session to <saving_path>. This command overrides previously saved highlights, so you may also use it for clearing them.
  • :HSImport: imports highlights from <saving_path>.

🐬 Configuration

Although settings already have self-explanatory names, here is where you can find info about each one of them and their classifications!

General

This settings are unrelated to any group and are independent.

  • verbosity: (Integer) if greater that zero, enables verbose output (print what it does when you execute any of the two command).
  • saving_path: (String) path to a directory for saving the highlights when they get exported. The directory shouldn't necessarily exist, however, the only condition is that it must end with a forward slash the path you give (/).

Highlight Colors

The table highlight_colors = {} contains all of the colors HighStr.nvim will use when you highlight something. The convention is simple: color_<a_number>. Each color is a table in which the first element represents the background of the color (the highlight it self), and the second one represents the foreground (the color of the text that's being highlighted). The second parameter may also be the word "smart", to change the color of the foreground based on the background in order to get a better contrast (e.g. if background is white, set foreground to black). Here is an example:

color_1 = {"#FFF9E3", "smart"}

Here we are setting a cool color called Cosmic Latte (looks like white), that we are assigning to color_1 and we are giving its parameters to a table: the first one is the highlight itself ("#FFF9E3") and in the second one ("smart") we are telling it to set a foreground that will make contrast with the background (black in this case).

Conditions:

  • The numbers that are assigned to the colors (e.g. color_2) should not be repeated, because it's what you'll use to "call" that highlight color.
  • The color it self (argument one in a color's table) should be in its hex value.

🧻 Key-bindings

There are no default key-bindings. However, you can set them on your own as you'd normally do! Here is an example mapping <F3> to highlight stuff and <F4> to remove the highlighting:

For init.lua

vim.api.nvim_set_keymap(
    "v",
    "<F3>",
    ":<c-u>HSHighlight 1<CR>",
    {
        noremap = true,
        silent = true
    }
)

vim.api.nvim_set_keymap(
    "v",
    "<F4>",
    ":<c-u>HSRmHighlight<CR>",
    {
        noremap = true,
        silent = true
    }
)

For init.vim

vnoremap <silent> <f3> :<c-u>HSHighlight 1<CR>
vnoremap <silent> <f4> :<c-u>HSRmHighlight<CR>

πŸ™‹ FAQ

  • Q: "What if I repeat a color's number?"

  • A: There would a conflict when calling :HSHighlight, however it will try and call any of those colors.

  • Q: "How can I view the doc from NeoVim?"

  • A: Use :help HighStr.nvim

πŸ«‚ Contribute

Pull Requests are welcomed as long as they are properly justified and there are no conflicts. If your PR has something to do with the README or in general related with the documentation, I'll gladly merge it! Also, when writing code for the project you must use the .editorconfig file on your editor so as to "maintain consistent coding styles". For instructions on how to use this file refer to EditorConfig's website.

πŸ’­ Inspirations

The following projects inspired the creation of HighStr.nvim. If possible, go check them out to see why they are so amazing :]

πŸ“œ License

HighStr.nvim is released under the GPL v3.0 license. It grants open-source permissions for users including:

  • The right to download and run the software freely
  • The right to make changes to the software as desired
  • The right to redistribute copies of the software
  • The right to modify and distribute copies of new versions of the software

For more convoluted language, see the LICENSE file.

πŸ“‹ TO-DO

High Priority

  • Store and Restore highlights on a per-file basis

Low Priority

  • Add tab completion to get more than 10 numbers.

Enjoy!

Comments
  • Defected imported selections

    Defected imported selections

    Hi,

    If I export selected lines/words, close file and reopen it and import color selections, it's not complete, and I don't sure if it problem with my configuration, or doing some wrong.

    -- HighStr.nvim -------------------------------------------------------------------------------------------------------------------------------------------
    local high_str = require("high-str")
    
    high_str.setup({
    	verbosity = 0,
    	saving_path = "/tmp/highstr/",
    	highlight_colors = {
    		-- color_id = {"bg_hex_code",<"fg_hex_code"/"smart">}
    		color_0 = {"#0c0d0e", "smart"},	-- Cosmic charcoal
    		color_1 = {"#e5c07b", "smart"},	-- Pastel yellow
    		color_2 = {"#7FFFD4", "smart"},	-- Aqua menthe
    		color_3 = {"#8A2BE2", "smart"},	-- Proton purple
    		color_4 = {"#FF4500", "smart"},	-- Orange red
    		color_5 = {"#008000", "smart"},	-- Office green
    		color_6 = {"#0000FF", "smart"},	-- Just blue
    		color_7 = {"#FFC0CB", "smart"},	-- Blush pink
    		color_8 = {"#FFF9E3", "smart"},	-- Cosmic latte
    		color_9 = {"#7d5c34", "smart"},	-- Fallow brown
    	}
    })
    vim.api.nvim_set_keymap(
        "v",
        "<F3>",
        ":<c-u>HSHighlight 1<CR>",
        {
            noremap = true,
            silent = true
        }
    )
    
    vim.api.nvim_set_keymap(
        "v",
        "<F4>",
        ":<c-u>HSRmHighlight<CR>",
        {
            noremap = true,
            silent = true
        }
    )
    

    ps_20210816184107 ps_20210816184314

    opened by roland-rollo 3
  • Cannot export the higlighting

    Cannot export the higlighting

    Hi, great plugin : )

    in my case i cannot save the highlightings

    I highlight something and then :HSExport path/

    but it outputs E488: Trailing characters

    I've tried with ~/path/path/ also creating the folder.

    Probably doing something wrong on my side.

    opened by Belamat 2
  • how to auto-enable/disable when entering/exiting visual mode

    how to auto-enable/disable when entering/exiting visual mode

    Is there a way to set up an autocmd (or something) to call HSHighlight when entering visual mode and then call HSRmHighlight when exiting visual mode? I have them mapped to F3/F4 as shown in the README but having 'the system' do it automatically would be even better.

    opened by hunleyd 2
  • = 5.3" in readme must be wrong">

    "Lua ver. >= 5.3" in readme must be wrong

    neovim 0.5 only builds with lua 5.1 or compatible (i e luajit 2.1 ). Can probably remove the line completely as it is also impossible to build neovim 0.5 without lua 5.1 or luajit.

    opened by bfredl 2
  • Removing all highlights in open buffer at once

    Removing all highlights in open buffer at once

    Just for future reference and anyone wondering how to achieve removing all highlights in the open buffer in one go, see below for global function snippet.

    function _G.highstr_highlight_remove_all()
      local api = vim.api
      local buffer_current_number = api.nvim_eval([[bufnr('%')]])
      local line_last = vim.fn.line('$')
    
      api.nvim_buf_clear_namespace(buffer_current_number, 0, 1 - 1, line_last)
    end
    

    You can call this function as follows: lua _G.highstr_highlight_remove_all()

    Cheers for the great plugin !

    opened by lcrockett 2
  • [Feature] Highlight all instances of selected word/text

    [Feature] Highlight all instances of selected word/text

    It would be great to add those commands:

    • Add/remove highlight to all of the instances of the selected word (normal mode) or string (visual mode)
    • In current buffer only
    • In all buffers
    • Jump to the next/previous string belonging to the same highlight group
    • In current buffer only
    • In all buffers
    opened by pidgeon777 0
  • [Bug] Setting `saving_path` option in Windows doesn't produce any effect

    [Bug] Setting `saving_path` option in Windows doesn't produce any effect

    The default value for saving_path is currently:

    saving_path = "/tmp/highstr/"
    

    But when configuring it like this in Windows:

    saving_path = "C:\\Work\\"
    

    then the cords.txt file is created in the C:\tmp\highstr directory.

    opened by pidgeon777 0
  • [ Feature Req ] Accept text object, and normal mode

    [ Feature Req ] Accept text object, and normal mode

    I find this plugin interesting. However, there are some improvements I would find useful:

    • Allowing highlight using text-motions would be interesting.
    • Allow, in normal mode, unhighlight the highlighting under cursor.
    • As in another feature request, ability to jump to the next or previous highlighting.

    What do you think?

    opened by Nekketsu 1
  • error

    error

    I[C]: in function 'nvim_buf_add_highlight'
    ^I...str/tools/tool-highlight/modules/highlight_selection.lua:58: in function 'highlight_visual_selection'
    ^I...ghStr.nvim/lua/high-str/tools/tool-highlight/service.lua:9: in function 'highlight'
    ^I...vim/lua/high-str/tools/tool-highlight/highlight/init.lua:9: in function 'highlight'
    ^I...vim/lua/high-str/tools/tool-highlight/highlight/init.lua:15: in function 'main'
    ^I...inuxmint/.vim/plugged/HighStr.nvim/lua/high-str/main.lua:13: in function <...inuxmint/.vim/plugged/HighStr.nvim/lua/high-str/main.lua:7> func
    tion: builtin#18 ...str/tools/tool-highlight/modules/highlight_selection.lua:58: Line number outside range
    
    
    opened by rbjnazz 0
Owner
Pocco81
Under dev dev
Pocco81
Jupyter notebook client in neovim

?? Jupyter-Nvim Read jupyter notebooks in neovim Note: The plugin is still in alpha stage ?? Usage Just open any *.ipynb file and voila! ✨ Contributin

Ahmed Khalf 85 Dec 29, 2022
Neovim integration for Google Keep, built using gkeepapi

Gkeep.nvim Neovim integration for Google Keep, built using gkeepapi Requirements Neovim 0.5 Python 3.6+ A patched font (optional. Used for icons) Tabl

Steven Arcangeli 143 Jan 2, 2023
Freaky fast fuzzy Denite/CtrlP matcher for vim/neovim

Freaky fast fuzzy Denite/CtrlP matcher for vim/neovim This is a matcher plugin for denite.nvim and CtrlP.

Raghu 113 Sep 29, 2022
Bringing emacs' greatest feature to neovim - Tetris!

nvim-tetris Bringing emacs' greatest feature to neovim - Tetris! This plugin is written in Fennel using Olical's project Aniseed for creating the proj

null 129 Dec 26, 2022
🌈 Generate color palettes based on Neovim colorschemes.

Iris Iris is a Neovim plugin that generates a normalized color palette based on your colorscheme. It is named for the goddess Iris of Greek mythology,

N. G. Scheurich 45 Jul 28, 2022
Interactive Redis: A Terminal Client for Redis with AutoCompletion and Syntax Highlighting.

Interactive Redis: A Cli for Redis with AutoCompletion and Syntax Highlighting. IRedis is a terminal client for redis with auto-completion and syntax

null 2.2k Dec 29, 2022
CLI for SQLite Databases with auto-completion and syntax highlighting

litecli Docs A command-line client for SQLite databases that has auto-completion and syntax highlighting. Installation If you already know how to inst

dbcli 1.8k Dec 31, 2022
A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.

mycli A command line client for MySQL that can do auto-completion and syntax highlighting. HomePage: http://mycli.net Documentation: http://mycli.net/

dbcli 10.7k Jan 7, 2023
Postgres CLI with autocompletion and syntax highlighting

A REPL for Postgres This is a postgres client that does auto-completion and syntax highlighting. Home Page: http://pgcli.com MySQL Equivalent: http://

dbcli 10.8k Jan 2, 2023
AthenaCLI is a CLI tool for AWS Athena service that can do auto-completion and syntax highlighting.

Introduction AthenaCLI is a command line interface (CLI) for the Athena service that can do auto-completion and syntax highlighting, and is a proud me

dbcli 192 Jan 7, 2023
cmdpxl: a totally practical command-line image editor

cmdpxl: a totally practical command-line image editor

Jieruei Chang 476 Jan 7, 2023
f90nml - A Fortran namelist parser, generator, and editor

f90nml - A Fortran namelist parser, generator, and editor A Python module and command line tool for parsing Fortran namelist files Documentation The c

Marshall Ward 110 Dec 14, 2022
Quickly open any path on your terminal window in your $EDITOR of choice!

Tmux fpp Plugin wrapper around Facebook PathPicker. Quickly open any path on your terminal window in your $EDITOR of choice! Demo Dependencies fpp - F

null 257 Dec 28, 2022
A ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line.

A ZSH plugin that enables you to use OpenAI's powerful Codex AI in the command line.

Tom DΓΆrr 976 Jan 3, 2023
A CLI Spigot plugin manager that adheres to Unix conventions and Python best practices.

Spud A cross-platform, Spigot plugin manager that adheres to the Unix philosophy and Python best practices. Some focuses of the project are: Easy and

Tommy Dougiamas 9 Dec 2, 2022
🐍The nx-python plugin allows users to create a basic python application using nx commands.

?? NxPy: Nx Python plugin This project was generated using Nx. The nx-python plugin allows users to create a basic python application using nx command

StandUP Communications 74 Aug 31, 2022
A minimalist Vim plugin manager.

A minimalist Vim plugin manager. Pros. Easy to set up: Single file. No boilerplate code required. Easy to use: Concise, intuitive syntax Super-fast pa

Junegunn Choi 30.2k Jan 8, 2023
Lsp Plugin for working with Python virtual environments

py_lsp.nvim What is py_lsp? py_lsp.nvim is a neovim plugin that helps with using the lsp feature for python development. It tackles the problem about

Patrick Haller 55 Dec 27, 2022