Is it possible to have multi-character surrounds? (Plus a different, unrelated question.) #232
Replies: 2 comments
-
Hi there!
Here are a few suggestions/alternatives:
As for the slurping and barfing, I actually haven't heard of that before (nor do I know of any existing plugins that do that); perhaps I will want to make it happen (though probably not as a part of this plugin, as it seems to involve moving things around as opposed to simply changing what the delimiters are), as it is a problem that I have run into a few times 🤔 Could probably use Tree-sitter or something to automatically decide what to "slurp up" as well, or perhaps use Vim motions to do that instead. |
Beta Was this translation helpful? Give feedback.
-
Nvim-surrounds already supports multi-character surrounds, only that you have to implement it youself. The bottom is my config, and I hope it can help you. Let me explain a bit. For example, if I want to place the current line into a theorem environment, then I will press Another example. We have a sentence like the following. Now I want to bold the word
Alternatively, you can also use
|
Beta Was this translation helpful? Give feedback.
-
I hope I'm using the correct terminology here, but what I'm aiming at is basically whether it is possible to replicate something like this:
This is supposed to show that the visual selection "a = b" is surrounded by "\left(" and "\right)", meaning I can use "m(" to refer to the pair "\left(" and "\right)" (ideally for adding, changing, and removing).
My goal would be to basically replicate the (La)TeX specific mappings from vim-sandwich, as shown here: https://github.com/machakann/vim-sandwich/wiki/Filetype-tex.
Sorry for the long text that follows:
I also have another, rather unrelated question. Ever since I switched from Emacs to (Neo)vim for basically all of my text editing, I've been looking for a replacement for smartparens (https://github.com/Fuco1/smartparens).
In addition to adding, deleting, and changing ‘surrounds’, like what this plugin can do, there are also features like ‘slurping’, ‘barfing’, ‘splitting’, and ‘joining’ (among others, but those are the things I miss most). What those things mean is basically the following (I'll try to illustrate with simple examples; old → new, and ^ marking the cursor position):
Slurping (forward), meaning ‘baz’ is ‘pulled in’:
Barfing (forward), meaning ‘baz’ is ‘spit out’ again:
(This is also explained here: https://ebzzry.com/en/emacs-pairs/#slurpandbarf).
Splitting:
Joining:
Are operations like these at all in the scope of this plugin?
‘Slurping’ and ‘barfing’, although more cumbersome, can basically be replicated by using something like nvim-gomove (https://github.com/booperlv/nvim-gomove), visually selecting the
]
, and then just moving it around, but I haven't found a way to ‘split’ or ‘join’ without manually typing everything out, of course. But then you might get stuff like(the part under the → means I'm entering insert mode), because an auto-close/auto-pair plugin interferes, which is kind of frustrating.
My ‘idea’ for an implementation would basically involve adding a ‘join’ and a ‘split’ operator (like the ‘add’, ‘delete’, and ‘change’ operators), give it the ‘surround’ you want to use (i.e. manually), and then remove/insert the corresponding pair, like this (just for this example: yJ = ‘join’ [you join], yS = ‘split’ [you split]):
Ideally, you could also do something like this:
and maybe this (the function/operator would default to using the ‘surround’ on the left if they're different but part of the same alias)
As far as I understand, vim-sexp (https://github.com/guns/vim-sexp) can do ‘slurping’ and ‘barfing’ (there it's called ‘capturing’ and ‘emitting’), but the plugin seems to be kind of old (and in viml), would duplicate a lot of functionality I don't need because plugins like this one can already do it, and joining and splitting doesn't seem to be supported, at all.
On the other hand, there seem to be various parinfer-plugins (https://shaunlebron.github.io/parinfer/), but parinfer AFAIK only works for Lisp (dialects) and does these kinds of things automatically, somehow (‘slurping’ and ‘barfing’, at least; no idea whether joining and splitting works).
Beta Was this translation helpful? Give feedback.
All reactions