1
1
# live-command.nvim
2
- ![ version] ( https://img.shields.io/badge/version-1.2.1 -brightgreen )
2
+ ![ version] ( https://img.shields.io/badge/version-2.0.0 -brightgreen )
3
3
4
- Text editing in Neovim with immediate visual feedback: view the effects of any command on your buffer contents live. Preview macros, the ` :norm ` command & more!
4
+ > :exclamation : Version 2.0 has been released with breaking changes! Be sure to check out the [ migration guide] ( ./migrate_to_v2.md ) .
5
+
6
+ Text editing in Neovim with immediate visual feedback: see the effects of any command on your buffer in real-time. Preview macros, the ` :norm ` command, and more!
5
7
6
8
![ live-command.nvim demo video] ( https://user-images.githubusercontent.com/40792180/235201812-adc95327-65cc-4ae4-8c2e-804853dd0c02.gif )
7
9
<p ><sub >Theme: <a href =" https://github.com/folke/tokyonight.nvim " >tokyonight.nvim</a ></sub ></p >
8
10
9
11
## :sparkles : Motivation and Features
10
- In version 0.8, Neovim has introduced the ` command-preview ` feature.
11
- Contrary to what "command preview" suggests, previewing any given
12
- command does not work out of the box: you need to manually update the buffer text and set
13
- highlights * for every command* .
12
+ In Neovim version 0.8, the ` command-preview ` feature was introduced.
13
+ Despite its name, it does not enable automatic previewing of any command.
14
+ Instead, users must manually update the buffer text and set highlights * for each command* they wish to preview.
14
15
15
- This plugin tries to change that: it provides a ** simple API for creating previewable commands**
16
- in Neovim. Just specify the command you want to run and live-command will do all the
17
- work for you. This includes viewing ** individual insertions, changes and deletions** as you
18
- type.
16
+ This plugin addresses that limitation by offering a ** simple API for creating previewable commands**
17
+ in Neovim. Just specify the command you want to preview and live-command will handle the rest.
18
+ This includes viewing ** individual insertions, changes and deletions** as you type.
19
19
20
20
## Requirements
21
21
Neovim 0.8+
22
22
23
- ## :rocket : Getting started
24
- Install using your favorite package manager and call the setup function with a table of
25
- commands to create. Here is an example that creates a previewable ` :Norm ` command:
23
+ ## :inbox_tray : Installation
24
+ Install via your favorite package manager and call the ` setup ` function:
25
+
26
+ <details >
27
+ <summary>lazy.nvim</summary>
28
+
26
29
``` lua
27
30
use {
28
31
" smjonas/live-command.nvim" ,
29
- -- live-command supports semantic versioning via tags
30
- -- tag = "1 .*",
32
+ -- live-command supports semantic versioning via Git tags
33
+ -- tag = "2 .*",
31
34
config = function ()
32
- require (" live-command" ).setup {
33
- commands = {
34
- Norm = { cmd = " norm" },
35
- },
36
- }
35
+ require (" live-command" ).setup ()
37
36
end ,
38
37
}
39
38
```
39
+ </details >
40
40
41
- ## :gear : Usage and Customization
42
- Each command you want to preview requires a name (must be upper-case) and the name of
43
- an existing command that is run on each keypress.
41
+ <details >
42
+ <summary>vim-plug</summary>
44
43
45
- Here is a list of available settings:
46
-
47
- | Key | Type | Description
48
- | ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------
49
- | cmd | string | The name of an existing command to preview.
50
- | args | string? \| function(arg: string?, opts: table) -> string | Arguments passed to the command. If a function, takes in the options passed to the command and must return the transformed argument(s) ` cmd ` will be called with. ` opts ` has the same structure as the ` opts ` table passed to the ` nvim_create_user_command ` callback function. If ` nil ` , the arguments are supplied from the command-line while the user is typing the command.
51
- | range | string? | The range to prepend to the command. Set this to ` "" ` if you don't want the new command to receive a count, e.g. when turning ` :9Reg a ` into ` :norm 9@a ` . If ` nil ` , the range will be supplied from the command entered.
52
-
53
- ### Example
54
- The following example creates a ` :Reg ` command which allows you to preview the effects of macros (e.g. ` :5Reg a ` to run macro ` a ` five times).
44
+ ``` vim
45
+ Plug 'smjonas/live-command.nvim'
46
+ ```
47
+ In your ` init.lua ` , call the setup function:
55
48
``` lua
56
- local commands = {
57
- Reg = {
58
- cmd = " norm" ,
59
- -- This will transform ":5Reg a" into ":norm 5@a"
60
- args = function (opts )
61
- return (opts .count == - 1 and " " or opts .count ) .. " @" .. opts .args
62
- end ,
63
- range = " " ,
64
- },
65
- }
49
+ require (" live-command" ).setup ()
50
+ ```
51
+ </details >
66
52
53
+ ## :rocket : Getting started
54
+ ### Basic Usage
55
+ The easiest way to use ** live-command** is with the provided ` :Preview ` command.
56
+ For example, ` :Preview delete ` will show you a preview of deleting the current line.
57
+ You can also provide a count or a range to the command, such as ` :'<,'>Preview norm A; ` , which
58
+ shows the effect of appending a semicolon to every visually selected line.
59
+
60
+ ### Creating Previewable Commands
61
+ For a more convenient experience, ** live-command** allows you to define custom previewable commands.
62
+ This can be done by passing a list of commands to the ` setup ` function.
63
+ For instance, to define a custom ` :Norm ` command that can be previewed, use the following:
64
+ ``` lua
67
65
require (" live-command" ).setup {
68
- commands = commands ,
66
+ commands = {
67
+ Norm = { cmd = " norm" },
68
+ },
69
69
}
70
70
```
71
- \
72
- All of the following options can be set globally (for all created commands), or per command.
73
71
74
- To change the default options globally, use the ` defaults ` table. The defaults are:
72
+ Each command you want to preview needs a name (which must be uppercase) and
73
+ an existing command to run on each keypress, specified via the ` cmd ` field.
74
+
75
+ ## :gear : Customization
76
+
77
+ All of the following options can be set globally (affecting all custom commands), or per command.
78
+
79
+ To change the default options globally, use the ` defaults ` table. The default settings are:
75
80
76
81
``` lua
77
82
require (" live-command" ).setup {
@@ -93,28 +98,28 @@ require("live-command").setup {
93
98
94
99
Default: ` true `
95
100
96
- Whether highlights should be shown. If ` false ` , only text changes are shown.
101
+ Determines whether highlights should be shown. If ` false ` , only text changes are shown, without any highlights .
97
102
98
103
---
99
104
100
105
` inline_highlighting: boolean `
101
106
102
107
Default: ` true `
103
108
104
- If ` true ` , differing lines will be compared in a second run of the diff algorithm. This
105
- can result in multiple highlights per line. Otherwise, the whole line will be highlighted as
106
- a single change highlight .
109
+ If ` true ` , differing lines will be compared in a second run of the diff algorithm
110
+ to identify smaller differences. This can result in multiple highlights per line.
111
+ If set to ` false ` , the whole line will be highlighted as a single change.
107
112
108
113
---
109
114
110
115
` hl_groups: table<string, string|boolean> `
111
116
112
117
Default: ` { insertion = "DiffAdd", deletion = "DiffDelete", change = "DiffChange" } `
113
118
114
- A list of highlight groups per edit type (insertion, deletion or change) used for highlighting buffer changes.
115
- The table will be merged with the defaults so you can omit any keys that are the same as the default.
116
- If a value is set to ` false ` , no highlights will be shown for that type. If ` hl_groups.deletion ` is ` false ` ,
117
- deletion edits will not be undone which is otherwise done to make the text changes visible .
119
+ A table mapping edit types (insertion, deletion or change) to highlight groups used for highlighting buffer changes.
120
+ This table is merged with the defaults, allowing you to omit any keys that match the default.
121
+ If a value is set to ` false ` , no highlights will be shown for that type.
122
+ If ` hl_groups. deletion` is ` false ` , deletion edits will not be undone, so deleted text won't be highlighted .
118
123
119
124
---
120
125
0 commit comments