Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tzachar/highlight-undo.nvim
Highlight changed text after Undo / Redo operations
https://github.com/tzachar/highlight-undo.nvim
lua neovim neovim-plugin
Last synced: 8 days ago
JSON representation
Highlight changed text after Undo / Redo operations
- Host: GitHub
- URL: https://github.com/tzachar/highlight-undo.nvim
- Owner: tzachar
- License: apache-2.0
- Created: 2023-06-08T09:39:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-06T08:03:35.000Z (6 months ago)
- Last Synced: 2024-08-02T18:37:13.113Z (3 months ago)
- Topics: lua, neovim, neovim-plugin
- Language: Lua
- Homepage:
- Size: 17.6 KB
- Stars: 263
- Watchers: 6
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-neovim-pluginlist - tzachar/highlight-undo.nvim - undo.nvim) ![](https://img.shields.io/github/last-commit/tzachar/highlight-undo.nvim) ![](https://img.shields.io/github/commit-activity/y/tzachar/highlight-undo.nvim) (Other Standard Feature Enhancement / Undo)
README
# highlight-undo.nvim
Highlight changed text after any action which modifies the current buffer. This
plugin was originaly written to support Undo / Redo highlighting, but is now
expanded to support any other action.Purely lua / nvim api implementation, no external dependencies needed.
## In Action
![recording](https://github.com/tzachar/highlight-undo.nvim/assets/4946827/81b85a3b-b563-4e97-b4e1-7a48d0d2f912)
## Installation
Using Lazy:
```lua
{
'tzachar/highlight-undo.nvim',
opts = {
...
},
},
```## Setup
You can manually setup `highlight-undo` as follows:
```lua
require('highlight-undo').setup({
duration = 300,
keymaps = {
Keymap_name = {
-- most fields here are the same as in vim.keymap.set
desc = "a description",
hlgroup = 'HighlightUndo',
mode = 'n',
lhs = 'lhs',
rhs = 'optional, can be nil',
opts = {
-- same as opts to vim.keymap.set. if rhs is nil, there should be a
-- callback key which points to a function
},
},
},
})
```### Plugin Load Order
As this plugin hijacks kemaps, there might be issues with other plugin with
similar behavior. Make sure this plugin is loaded last. For example, using
`lazy.nvim`, you can just specify the following:```lua
{
'tzachar/highlight-undo.nvim',
keys = { { "u" }, { "" } },
}
```## Keymaps
Specify which keymaps should trigger the beginning and end of tracking changes
([see here](#how-the-plugin-works)). By default, the plugin starts tracking
changes before and after the following keymaps:
* `u` -- for Undo
* `` -- for Redo
* `p` -- for paste
* `P` -- for PasteTo disable any of the defaults, add a `disabled = true` entry to the appropirate
keymap. For example, to disable the default highlight for Paste:```lua
require('highlight-undo').setup({
keymaps = {
Paste = {
disabled = true,
},
},
})
```Keymaps are specified in the same format as `vim.keymap.set` accepts: mode, lhs,
rhs, opts. Maps are passed verbatim to `vim.keymap.set`. A different possibility
is when you just want to hijack an existing keymap, you can then just specify
the `lhs` and `highligh-undo` will remap `lhs` and trigger the original action
afterwards.For example, adding `p` (which exists by default), is as easy as:
```lua
require('highlight-undo').setup({
keymaps = {
paste = {
desc = "paste",
hlgroup = 'HighlightUndo',
mode = 'n',
lhs = 'p',
rhs = 'p',
opts = {},
},
},
})
```
Note that `lhs` and `rhs` are identical.## `hlgroup`
Specify the highlighting group to use.
By default, `highlight-undo` will use `HighlightUndo` for the undo action and
`HighlightRedo` for the redo action. Both of these groups, are defined when the
plugin is loaded. If the groups are already defined elsewhere in your config
then they will not be overwritten. You can also use others groups, if desired.## `duration`
The duration (in milliseconds) to highlight changes. Default is 300.
## How the Plugin Works
`highlight-undo` will remap the `u` and `` keys (for undo and redo, by default) and
hijack the calls. By utilizing `nvim_buf_attach` to get indications for changes in the
buffer, the plugin can achieve very low overhead.