smjonas / live-command.nvim Goto Github PK
View Code? Open in Web Editor NEWEasily create previewable commands in Neovim.
License: MIT License
Easily create previewable commands in Neovim.
License: MIT License
So this behavior is kinda hard to explain and i dont fully understand it myself. Basically when saving "dd" to a macro it behaves very weirdly when the text is the same. It starts from the second to last row and goes up. When i changed to only a few rows being the same it started from the last of the similar rows and counted upwards. Once it had finished it started going down as normal
A bonus bug i found is that if you have recorded "dd" to q and then override it (for example i wrote "testing" at the end of the line), the preview will show both the previous macro to delete and the new macro. Although when you click enter the result is as you expect, but the preview is wrong.
Lastly I am sorry that i didnt have screenkey. I couldnt get it to work on fedora wayland :/ You have to take my word that i recorded "dd"
this is the minimal example i used (thank god for NVIM_APPNAME)
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
vim.g.mapleader = " " -- make sure to set `mapleader` before lazy so your mappings are correct
require("lazy").setup({
{"smjonas/live-command.nvim",
opts = {
commands = {
Norm = { cmd = "norm" },
Reg = {
cmd = "norm",
-- This will transform ":5Reg a" into ":norm 5@a"
args = function(opts)
return (opts.count == -1 and "" or opts.count) .. "@" .. opts.args
end,
range = "",
},
},
}
}
})
my config is just calling the setup function and when start nvim i get this error
E5113: Error while calling lua chunk: ...packer\start\live-command.nvim/lua\live-command\init.lua:309: commands: expected table, got nil
stack traceback:
[C]: in function 'error'
vim/shared.lua:699: in function 'validate'
...packer\start\live-command.nvim/lua\live-command\init.lua:309: in function 'validate_config'
...packer\start\live-command.nvim/lua\live-command\init.lua:346: in function 'setup'
...ers\marzouk\AppData\Local\nvim/lua\user\live-command.lua:13: in main chunk
[C]: in function 'require'
C:\Users\marzouk\AppData\Local\nvim\init.lua:31: in main chunk
with Norm
with G
Do you have a recommendation for storing and loading macros with lua?
Please let me know, what you think of those ideas and how to structure them into actionable items (for investigation).
This plugin is almost ready to be released and I am currently looking for testers. What you can do to help out:
:Norm
and Reg
commands and look out for any highlighting or performance issues.Thank you, I really appreciate any help / feedback from you guys!
I encountered a small issue when using Reg in combination with numb. When i try to write 5Reg q it jumps to the fifth row and executes the query there. There is probably nothing to be done about this but id thought i should let you know anyway, feel free to close this
If cmdheight is set to 0, the lualine status bar gets drawn over/behind my cmdline (can't really tell) on each key pressed.
If you have come up with your own commands other than :Norm
or :Reg
, please share them with the community here! Feel free to add a short demo video.
Really cool plugin! I started taking it for a spin and one issue I noticed is that the preview is not correct if some line does not contain a match for eg f
.
For example lets say you have the buffer:
foo
bar
and you type :%Norm foix
. Then before pressing <CR>
the preview looks like:
fxoo
xbar
whereas after pressing <CR>
you actually get:
fxoo
bar
I used live-command to wrap vim-abolish:
use {'smjonas/live-command.nvim', commit='ce4b104ce702c7bb9fdff863059af6d47107ca61', config=function()
require("live-command").setup {
defaults = {
-- inline_highlighting = false,
},
commands = {
Norm = { cmd = "norm" },
S = { cmd = "Subvert"}, -- must be defined before we import vim-abolish
},
}
end}
With an input file of:
result
Result
RESULT
And when previewing this command:
%S/result/outcome
Ideally the display would be like neovim's :%s preview meaning resultoutcome
Disabling inline highlighting helps with that issue, but then whole lines are highlighted and it's not clear anymore what was changed.
Making a word-by-word diff would help in this case, I guess.
Can this plugin be used to preview :g
? For example lets say I have the buffer:
foo
bar
barx
foo
xbar
and I want to delete any line containing bar
which could be done with :g/bar/d<CR>
. However if I add the entry G = { cmd = 'g' }
to the config of this plugin. It only previews the command on the current line when I type :G/bar/d
, even though :g
acts on all lines.
I tried debugging it with safari devtools but couldn't really find anything conclusive. the video file (e.g. https://user-images.githubusercontent.com/40792180/194180320-691efe71-0743-40e5-b0d7-454f142a9235.mp4) just refuses to load and it seems security related.
tpope/vim-abolish provides a useful :Subvert command that does smart substitution.
I've configured it with live-command as so:
use {
"smjonas/live-command.nvim",
config = function()
require("live-command").setup {
commands = {
LSubvert = { cmd = "Subvert" },
},
}
end,
}
but I'm getting an error when I try :LSubvert/send_wire/SendWire/
:
Error executing Lua callback: ...packer/start/live-command.nvim/lua/live-command/init.lua:281: Vim(substitute):E486: Pattern not found: \v\C%(send_wire|SEND_WIRE|SendWire)
stack traceback:
[C]: in function 'cmd'
...packer/start/live-command.nvim/lua/live-command/init.lua:281: in function 'execute_command'
...packer/start/live-command.nvim/lua/live-command/init.lua:295: in function <...packer/start/live-command.nvim/lua/live-command/init.lua:288>
The plugin works when I provide a range though, e.g., :%LSubvert/send_wire/SendWire/
.
I can provide a Docker container for reproducing this issue if needed.
There are probably a million ways the highlighting algorithm can be improved.
Here are some examples:
In progress
oneword
, output: hey
, expected highlights: a single replacement highlight created by joining multiple highlights, any deletions should be removed. This would involve detecting word boundaries. Status: in progress, see #8.Planned
foo
, output: o
, expected highlights: a single replacement highlight (the suffix o
should not have been truncated)Completed
timestamp, _ := strconv.Atoi(line[0])
, output: timestamp = strconv.Atoi(line[0]),
, check highlights! Fixed in f713c59.I'm still using https://github.com/junegunn/vim-plug/.
Do you know how to install live-command.nvim with that ?
It would be great having this info in the README. I think it is using packer.nvim in your installation instructions but I'm not sure about that.
For example, I selected two lines and typed :Norm de
, and then deleted the previous two characters. This made it so another word got deleted on each line. I then pressed <Esc>
to cancel, which didn't revert one of the deletions.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.