hrsh7th / nvim-insx Goto Github PK
View Code? Open in Web Editor NEWFlexible key mapping manager.
Flexible key mapping manager.
The <
operator is often use individually as a comparison operator. But the nvim-insx add <>
as default preset which will force the user to delete extra operator. This also let writing code like std::cout << "Hello World" << std::endl
harder when coding in C++. I will prefer letting user to manually add <
by their own instead of passing this preset as default.
nvim-autopairs can integrate with nvim-cmp by automatically adding parantheses when you confirm a completion on a function entry:
https://github.com/windwp/nvim-autopairs#mapping-cr
It would be nice to have something similar for this plugin.
When inserting empty brackets followed by brackets, dot-repeats will nest the latter by the prior.
vim.opt.runtimepath:prepend("path/to/nvim-insx")
require("insx.preset.standard").setup()
o[]()<Esc>.
becomes
[]()
[()]
o[](foo.html)<Esc>.
becomes
[](foo.html)
[(foo.html)]
markdown
[|]
]
[](|)
[]|
I'm trying to create a mapping for ]
in markdown that inserts a ()
after the square brackets (for links). This is the configuration I'm using to test this (it also supports Pandoc markdown citations, which are of the form [@citation_key]
and do not need parentheses afterwards):
local insx = require("insx")
local esc = require("insx.helper.regex").esc
insx.add(
"[",
require("insx.recipe.auto_pair").strings({
open = "[",
close = "]",
})
)
insx.add(
"<BS>",
require("insx.recipe.delete_pair").strings({
open_pat = esc("["),
close_pat = esc("]"),
})
)
insx.add(
"]",
require("insx.recipe.jump_next")({
jump_pat = {
[[\\\@<!\%#]] .. esc("]") .. [[\zs]],
},
})
)
insx.add("]", {
action = function(ctx)
ctx.move(ctx.row(), ctx.col() + 1)
if not ctx.data.citation then
ctx.send("()")
ctx.move(ctx.row(), ctx.col() - 1)
end
end,
enabled = function(ctx)
if not vim.tbl_contains({ "markdown", "text" }, ctx.filetype, {}) then
return false
end
if ctx.match([==[\[@[^]]*\%#[^]]*\]]==]) then
ctx.data.citation = true
return true
end
return ctx.match([==[\%#[^]]*\]]==])
end,
})
The issue is that there's no way to prioritize one rule over another, as far as I can tell. If I remove the general jump_next
rule, the one for Markdown works (but only in Markdown).
I'm coming from lexima.vim which prioritizes rules (either explicitly by weighting them or implicitly by doing things like applying filetype matches over general rules), but this doesn't seem to be possible in insx.
I don't think this is a bug, but it seems like there could be a use for having multiple mappings for the same key.
Hi!
Thank you for creating and maintaining this amazing plugin!
I found that when we set up insx for <space>
key, the abbrev feature does not work.
Here is a minimal configuration.
local tmp_dir = "/tmp"
local commit_hash = "c1d9efb592787f3f8c6d99db6ed5f51dd9475d4f"
-- fectch insx if not exists {{
local insx_path = tmp_dir .. "/insx"
if not (vim.uv or vim.loop).fs_stat(insx_path) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/hrsh7th/nvim-insx.git",
insx_path,
})
end
-- checkout commit_hash
vim.fn.system({
"git",
"-C",
insx_path,
"checkout",
commit_hash,
})
vim.opt.runtimepath:prepend(insx_path)
-- }}
-- setup insx
require("insx").add("<Space>", {
enabled = function()
return false
end,
action = function(ctx) end,
})
-- define abbreviations
if (vim.fn.has("nvim-0.10")) ~= 0 then
vim.keymap.set("ia", "fu", "fuhahahaha")
vim.keymap.set("ca", "sa", "sasumatu")
else
vim.cmd([[iabbrev <buffer> fu fuhahahaha]])
vim.cmd([[cabbrev <buffer> sa sasumatu]])
end
init.lua
) and yank-paste the above code to the file.NVIM_APPNAME=insx_abbr nvim -u init.lua
)fu<space>
to the buffer (and you can see that abbr does not work)sa<space>
(and you can see that ca
works)I tested on [email protected]
and [email protected]+ga41546d4a
, and the OS is macOS 14.
Thanks
I've been using this plugin for a long time and it is always been great. But there was one annoying problem that came with the standard preset: the '
single quote got auto-pairing when I was coding in Rust or OCaml. In Rust programming language, 'a
is used to denote the lifetime of a reference, and in OCaml, 'a
is used to represent a type variable. These two usages are very common, and getting automatic single quote auto pairing means that every time when I was working around with the type system, I have to press single quotes twice and delete the pair, then I can finally got a type, not an 'a'
character.
Actually it can be fixed by manually adding filetype to the single quote rule myself, but I don't want to copy and paste all the other default presets just to fix this issue. So if there is a way to inject a condition into the default preset and override a part of it, it can save me from getting a huge but redundant neovim dotfiles.
it would be useful to have auto-pairing in vim's cmdline as well
Using the presets, when typing a '
anywhere automatically adds another '
. This is usually great, but inside comments, this is rather annoying, since in comments, I often want to write something like "isn't" or "it's", and always get an unnecessary extra '
there.
I'd suggest either not auto-enclosing '
in comments, or adding some conditionals like for example only adding '
if the previous character is a non-letter.
')' and '}' are set to fast_wrap, but if I enter {}
with console.log(<cursor>foo)
, the order of the parentheses is reversed.
If you put a space inside the parentheses before executing, the problem does not occur.
local minx = require('minx')
minx.add(')', require('minx.recipe.fast_wrap')({ close = ')' }))
minx.add('}', require('minx.recipe.fast_wrap')({ close = '}' }))
markdown
``|
`
```|
```|`
When entering three consecutive backquotes in markdown, the following behavior is observed:
```|`
It would be appreciated if changes could be made to edit this as below, for writing the markdown code block:
```|
This feature is very similar to express/koa's middleware.
local delete_pair = {
action = function(ctx)
if not ctx.match('(|)') then
return ctx.next()
end
ctx.send('<BS><Del>')
end
}
local remove_cursor_around_spaces = {
action = function(ctx)
local before_space = ctx.before():match('%s+$') or ''
ctx.send(('<BS>'):rep(#before_space)
local after_space = ctx.after():match('^%s+') or ''
ctx.send(('<Del>'):rep(#after_space)
ctx.next()
end
}
local delete_pair_with_spaces = insx.compose(remove_cursor_around_spaces, delete_pair)
The following bug could be avoided using insx.recipe.substitute
.
local insx = require('insx')
local pair = require('insx.recipe.auto_pair')
insx.add('(', pair({
open = [[\\(]],
close = [[\)]]
}))
|
is a cursor. When I type (
before the backslash, I expect to complete the close bracket \)
.
\| ==> \(| ==> \(|\)
|
is a cursor. When I type (
before the backslash, I expect to complete the close bracket \)
and \
.
\| ==> \(| ==> \\(|\)
Currently the endwise recipe is very basic. I think it should be smarter.
However, I don't use endwise, so I don't know what kind of functionality is needed.
Since i updated my plugin, i got :
E5113: Error while calling lua chunk: .../pack/packer/start/nvim-insx/lua/insx/kit/Vim/Keymap.lua:29: attempt to call field 'keycode' (a nil value)
stack traceback:
.../pack/packer/start/nvim-insx/lua/insx/kit/Vim/Keymap.lua:29: in function 'normalize'
.../nvim/site/pack/packer/start/nvim-insx/lua/insx/init.lua:297: in function 'add'
...pack/packer/start/nvim-insx/lua/insx/preset/standard.lua:16: in function 'setup_insert_mode'
...pack/packer/start/nvim-insx/lua/insx/preset/standard.lua:10: in function 'setup'
/home/dk/.config/nvim//lua/plugins_config.lua:439: in main chunk
[C]: in function 'require'
/home/dk/.config/nvim/init.lua:21: in main chunk
Maybe from latest updates on the plugin ?
only this recipe should consider treesitter nodes.
n/a
n/a
n/a
n/a
n/a
I haven't been able to get the .mov currently in the README.md (https://user-images.githubusercontent.com/629908/212733495-f8e5486c-215c-4c01-b53c-b720b9779c3f.mov) to work as of this writing.
I've tried it on:
My guess is there are two snags, one of which is a problem with the data hosted by github for the .mov, and the other is the choice to host the data as a .mov in the first place, when .webm (with an open codec) would be the obvious cross-platform choice in 2023.
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.