vim-operator-surround
vim-operator-surround copied to clipboard
Backslash blocks don't work well
I would like to have a \langle ... \rangle
surround for use in latex.
Hence I have defined:
let g:operator#surround#blocks = {
\ '-' : [
\ {'block': ['\langle', '\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': ['<', '>']},
\ ] }
And the following block with vim-textobj-user:
call textobj#user#plugin('latex', {
\ 'code': {'pattern': ['\\langle\>', '\\rangle\>'], 'select-a': 'a<', 'select-i': 'i<' },
\ })
This allows me to change ()
to \langle\rangle
using sra(<
.
However I cannot change back. That is sra<(
beeps and does nothing.
If I change to 'block': ['\\langle', '\\rangle']
I can do sra<(
,
but then the original command inserts the wrong thing \\langle\\rangle
I seems to me this could be fixed by making sure we always search literaly, rather than using regex, when changing or deleting a surround.
A workaround appears to be adding an extra surround for searching:
let g:operator#surround#blocks = {
\ '-' : [
\ {'block': ['\langle', '\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': ['<','>']},
\ {'block': ['\\langle', '\\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': []},
\ ] }
Hi.
Strings in block
are used as regular expression here. So backslash must be escaped with extra backslash. I think below works.
let g:operator#surround#blocks = {
\ '-' : [
\ {'block': ['\\langle', '\\rangle'], 'motionwise': ['char', 'line', 'block'], 'keys': ['<', '>']},
\ ] }
['\\langle\>', '\\rangle\>']
may be better as you mentioned.
The problem with this one seems to be when inserting the brackets. Here it is not used as a regular expression, but inserted verbatim, right?
Ah, I understood. That's true. I'll consider how to resolve this issue..
I think, if searching could be made non regular expression, that would solve it. Likely it's not really needed if this hasnthasn't been a problem before.
Exactly the solution resolves this issue. However, it breaks other block definitions which rely on regular expression. I think it is good to enable to define inserted block text explicitly as below.
let g:operator#surround#blocks = {
\ '-' : [
\ {
\ 'block': ['\\langle', '\\rangle'],
\ 'block_text': ['\langle', '\rangle'],
\ 'motionwise': ['char', 'line', 'block'],
\ 'keys': ['<', '>']},
\ ] }
What do you think?
That would certainly work :-) I guess I just can't imagine any cases where you'd want to insert a regular expression verbatim as a bracket.
On Fri, Oct 9, 2015, 11:03 AM Linda_pp [email protected] wrote:
Exactly the solution resolves this issue. However, it breaks other block definitions which rely on regular expression. I think it is good to enable to define inserted block explicitly as below.
let g:operator#surround#blocks = {\ '-' : [\ {\ 'block': ['\langle', '\rangle'],
\ 'block_text': ['\langle', '\rangle'],
\ 'motionwise': ['char', 'line', 'block'],\ 'keys': ['<', '>']},\ ] }
What do you think?
— Reply to this email directly or view it on GitHub https://github.com/rhysd/vim-operator-surround/issues/25#issuecomment-146806760 .
e.g. HTML tag