- ๐ฑ Iโm currently learning Nix
- ๐ซ Reach me at [email protected]
- โ Other links:
iron-e / nvim-libmodal Goto Github PK
View Code? Open in Web Editor NEWCreate new "modes" for Neovim!
License: Other
Create new "modes" for Neovim!
License: Other
Hi! I'm having a similar issue as #31 but for the TextChanged
autocmd:
local M = {}
M.mode = {
d = function() vim.cmd.delete() end
}
local text_changes = 0
vim.keymap.set('n', 'M', function()
vim.api.nvim_create_autocmd('TextChanged', {
callback = function()
text_changes = text_changes + 1
vim.notify('text_changes: ' .. text_changes)
end,
})
require('libmodal').mode.enter('Mode', M.mode)
end)
Hello, The ^V (visual block mode) is missing from the galaxyline config example. To fix just add this line:
['^V'] = {'V-BLOCK', _COLORS.blue},
Thanks,
-mp
Error detected while processing LspAttach Autocommands for "*":
Error during nvim-libmodal mode:
...ocal/share/nvim/lazy/nvim-libmodal/lua/libmodal/Mode.lua:296: attempt to compare number with string
let me be honest, i'm a noob.
i don't understand the source code, is it something wrong i'm doing?
Hi @Iron-E,
This plugin is something I have been wanting to find for quite a while.
I was about to start playing with kana/vim-submode
which doens't seem to be maintained anymore but thankfully I found this project too.
Thanks so much for such a cool plugin. I was able to write my first vim plugin thanks to some copy paste from your tabmode project.
Please take a look: https://github.com/DavidGamba/nvim-window-mode
I couldn't figure out how to handle errors (DavidGamba/nvim-window-mode#1) so when there is an error in the command then it exits the mode. I would like to stay in the mode I am in regardless of the error. Thankfully neovim is displaying the error so at least I can see why I am no longer in that mode.
For my plugin I need to be able to send key codes from Lua without the active Mode interfering. I'm not completely sure how the event loop inside a mode works, but even me setting a variable manually like this
if userInput == 'd' then
vim.g.fooModePassthrough = true
vim.api.nvim_input("d")
vim.g.fooModePassthrough = false
end
would be sufficient for me. Is this possible?
Neovim 0.7 allows mapping to functions from Lua. Submodes always supported this (since they are not actually keymappings) but Layers should support this also
In every Lua style guide this one:
local foo =
{
bar = 2,
}
considered as a bad stlyle, and this one:
local foo = {
bar = 2,
}
as a good one:
Hello!
Really love the plugin (I can't believe this hasn't blown up... such a good idea)
I wanted to ask a quick question/or maybe suggest a feature: I am currently working on building a plugin that allows the user to write musical notation inside of nvim. One mode (called score mode) will allow the user's curser to draw in musical symbols by performing all of the steps required to insert the specific UTF characters. Thus it needs to be able to move around and retain the cursor functionality.
I realize I could do this with a layer BUT I lose the super cool named indicator... I also want to create several submodes under this so an indicator would allow the user to keep track of where they are.
So I was curious as to HOW the plugin accesses nvim's Indicator (and is able to write --INSERT-- or --MY_MODE--) and is it possible to have a mode that also retains the cursor... OR is it possible to have a layer that allows you the indicator. (either would work).
Thanks!
To reproduce:
M.mode = {
k = function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) end,
j = function() vim.api.nvim_win_set_cursor(0, { 2, 0 }) end,
}
vim.keymap.set('n', 'M', function()
vim.api.nvim_create_autocmd('CursorMoved', {
callback = function()
vim.notify('Cursor moved')
end,
})
require('libmodal').mode.enter('Mode', M.mode)
end)
M
to enter custom modek
/j
a couple of times (notice that no notification is sent from the autocmd)<esc>
to leave modek
/j
: now the notification is sentAs far as i know this is the most basic use of this plugin:
In my vimrc:
lua require'foo'
in lua/foo.lua
local libmodal = require('libmodal')
This causes pasting into the command prompt (i.e. :
-> cmd+v
/whatever you bind paste to) to do nothing.
The ability to switch to nvim-libmodal
without altering a configuration at all is desired. Unfortunately, this won't be possible until Neovim 0.5 as several important features are waiting for release in the master
branch.
Hi! I'm trying to use vim.v.count
in a mode mapping. However, it seems to always be 0.
To reproduce:
local my_mode = {
g = function()
vim.notify('count: ' .. vim.v.count)
end
}
vim.keymap.set('n', 'M', function()
require('libmodal').mode.enter('My mode', my_mode)
end)
M
3g
count: 0
Hi! First of all, thank you for making this super cool plugin!
I'm trying to create a custom mode using nvim-libmodal in which the cursor moves. However, the cursor movement isn't actually rendered until after leaving the mode.
Here's just a small example setup to illustrate the issue:
local libmodal = require 'libmodal'
vim.o.cursorline = true
vim.o.showmode = false
local my_mode = {
g = function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) end,
}
vim.keymap.set('n', 'M', function()
libmodal.mode.enter('my_mode', my_mode)
end)
To reproduce:
M
to enter my_mode
g
to trigger custom actiong
I'm on Neovim nightly v0.10.0-dev-2355+g1c7b0b9d5
Mappings with modifiers like ctrl
/meta
don't seem to work:
local M = {}
M.mode = {
n = function()
vim.notify('This works')
end,
['<c-n>'] = function()
vim.notify("This doesn't work")
end,
['<m-n>'] = function()
vim.notify("This throws error: 'attempt to compare number with string'")
end
}
vim.keymap.set('n', 'M', function()
require('libmodal').mode.enter('My mode', M.mode)
end)
M
to enter custom moden
produces notification 'This works'
<c-n>
doesn't produce a notification<m-n>
throws an errorError message:
E5108: Error executing lua: ...k/packer/start/nvim-libmodal/lua/libmodal/utils/Help.lua:41: Expected lua string
stack traceback:
[C]: in function 'nvim_strwidth'
...k/packer/start/nvim-libmodal/lua/libmodal/utils/Help.lua:41: in function 'new'
...te/pack/packer/start/nvim-libmodal/lua/libmodal/Mode.lua:217: in function 'new'
...te/pack/packer/start/nvim-libmodal/lua/libmodal/init.lua:35: in function 'enter'
/Users/rgdpro/.config/nvim/lua/my/whichkey-functions.lua:38: in function 'windowlayer'
...g/nvim/lua/plugins/windows-splits-tabs-buffer-motion.lua:71: in function <...g/nvim/lua/plugins/windows-splits-tabs-buffer-motion.lua:70>
Part of the stack trace is when Help message was constructed?
It's trying to get "nvim_strwidth" of a function? Here's my libmodal.mode.enter.
Before everything, AWESOME PLUGIN! many thanks to you good sir. ๐๐ผ
Issue:
I added this function that enters a layer:
local function t(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
_G.windowlayer = function()
local ok, libmodal = pcall(require, "libmodal")
if not ok then
return
end
libmodal.mode.enter("WindowMode", {
h = t("normal <C-w><"),
j = t("normal <C-w>-"),
k = t("normal <C-w>+"),
l = t("normal <C-w>>"),
["="] = t("normal <C-w>="),
H = t("normal <Cmd>WinShift left<CR>"),
J = t("normal <Cmd>WinShift down<CR>"),
K = t("normal <Cmd>WinShift up<CR>"),
L = t("normal <Cmd>WinShift right<CR>"),
x = t("normal <Cmd>WinShift swap<CR>"),
["<"] = t("normal :BufferLineMovePrev<CR>"),
[">"] = t("normal :BufferLineMoveNext<CR>"),
})
end
It seems when I press the x
key, it doesn't wait for a response unlike when I run :WinShift swap
in command line.
I'm a newb but I can try helping if this is really an issue, just point me where to fix this. Thanks!
Hi, I wanted to try out your plugin but didn't found an example how to show the mods in lualine, then I saw that you use feline and saw that it's archived by the owner, do you plan to switch to some other plugin like lualine?
If yes, I would love to see your configuration for nvim-libmodal for it.
This may be by design, but the OOP api for creating layer makes it seem like they should be reusable.
Repro
I created this simple layer using the OOP api:
local layer = libmodal.layer.new({})
local count = 1
layer:map("n", "a", function()
print("From layer - " .. tostring(count))
count = count + 1
end, {})
layer:map("n", "<esc>", function()
layer:exit()
end, {})
vim.keymap.set("n", "<leader>l", function()
layer:enter()
end, {})
Expected
I can enter and exit the layer multiple times. When the layer is active the a
keybind prints the message
Actual
The layer works fine the first time it is entered, but if it is exited and re-entered afterwards, none of the keybinds defined in the layer work.
It feels like a layer should be able to be exited and re-entered without having to set all the keybinds on the layer object every-time it is exited.
I like the plugin very much. Thanks alot for creating! Since you do setups functional anyway, why not provide one for your plugin initialisation?
This would enable stuff like conditional setups for users etc.
Reasons to do:
Another related reason (bad practice/historical reasons): nvim-treesitter/module-template#1
Potentially related discussion for galaxyline: nvimdev/galaxyline.nvim#134
Relevant content for change:
if vim.g.loaded_libmodal == nil
--finish stuff
end
vim.g.loaded_libmodal = 1;
if vim.o.timeout == nil -- timeout is an option, which should always exist => could be a bug in your code
vim.o.timeout = true;
end
--highlight default link LibmodalPrompt ModeMsg --please check how pure lua plugins do this or the colorbuddy source
--highlight default link LibmodalStar StatusLine
Of course you could also use the more optimal vim.api functions for setting and getting variables as described in the nvim-lua-guide.
Hi agan! I'm trying to switch between multiple libmodal modes. However, exiting libmodal seems to require one <Esc>
press per mode switched. My expected behaviour is that pressing <Esc>
would immediately take me to Normal mode, just like how all Vim modes work. Do you agree? If not, is there some other way to exit libmodal
? There doesn't seem to be a require('libmodal').mode.exit()
that I can create a mapping for ๐
To reproduce:
local M = {}
M.mode1 = {
m = function()
vim.notify('Mode 1')
end,
n = function()
require('libmodal').mode.enter('My mode 2', M.mode2)
end
}
M.mode2 = {
m = function()
vim.notify('Mode 2')
end,
n = function()
require('libmodal').mode.enter('Mode 1', M.mode1)
end
}
vim.keymap.set('n', 'M', function()
require('libmodal').mode.enter('Mode 1', M.mode1)
end)
M
to enter Mode 1m
: "Mode 1" is notifiedn
n
to enter Mode 2m
: "Mode 2" is notified<Esc>
twice to reach Normal modeAwesome work @Iron-E! But it'd be best if I can make this work.
Hi again! I'm trying to expose the keymaps table to the consumers of my plugin. Here's a simplified example:
local options = {
local libmodal = require('libmodal')
local M = {}
local options = {
mode_keymaps = {
n = function() vim.notify('foo') end,
u = vim.cmd.undo, -- THIS DOESN'T CURRENTLY WORK
}
}
vim.keymap.set('n', 'M', function()
require('libmodal').mode.enter('Mode 1', mode_keymaps)
end)
function M.setup(opts)
options = vim.tbl_deep_extend('force', options, opts or {})
end
The problem is the line u = vim.cmd.undo
. Since libmodal passes the current mode as an agrument, that argument gets passed to vim.cmd.undo
, causing the following error:
...ocal/share/nvim/lazy/nvim-libmodal/lua/libmodal/Mode.lua:125: invalid key: input
I could solve this by requiring my users to wrap each callback in a function
like this:
u = function() vim.cmd.undo() end
But it feels like an ugly solution. I would prefer if I could abstract away libmodal. So I tried creating a function that iterates over all the mappings and wraps them with a function:
local function clean_mappings(mappings)
local new_mappings = {}
for keymap, fn in pairs(mappings) do
new_mappings[keymap] = function() fn() end
end
return new_mappings
end
This solves the agove problem. However, I also want to use a mapping to switch mode with libmodal.mode.switch
. That means that the Mode
type argument passed to switch
es returned function gets lost.
Do you have any suggestions as to how I could solve this? Or is there any way for libmodal to determine whether it should or shouldn't pass an argument to the callback when calling it?
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.