Comments (3)
The issue comes from the fact that, in a list, every item is both a pattern and a substitution. The code is supposed to switch from the first to the second and from the second to the first, which means s/<or>/<and>/ and the replacement gets the < characters, because they're not special in the replacement part.
aaahh of course, thanks that makes total sense.
And the helpers work perfectly as well. I just put them to good use. (And probably agreed on avoiding parametrizing unless there are more axes to deal with).
Thanks again for both the tip and the plugin!
from switch.vim.
Thank you for your kind words :).
Regarding the issue, I don't think the problem is with case normalization -- in fact, if you put ['\<or\>', '\<and\>']
, I think you'll get the same result, or at least I get it locally.
The issue comes from the fact that, in a list, every item is both a pattern and a substitution. The code is supposed to switch from the first to the second and from the second to the first, which means s/\<or\>/\<and\>/
and the replacement gets the <
characters, because they're not special in the replacement part. The list version is useful for simple transformations, but doesn't work that hot when you need to use regexes.
What I can recommend in this case is using the hash form, which is basically what the plugin generates, without the \<
parts:
let g:switch_custom_definitions = [
\ { '\C\<and\>': 'or', '\C\<or\>': 'and' },
\ { '\C\<And\>': 'Or', '\C\<Or\>': 'And' },
\ { '\C\<AND\>': 'OR', '\C\<OR\>': 'AND' },
\ ]
Having said that, It feels like it'd be useful to also make a helper like switch#NormalizedCaseWords
to also add the word boundaries. (Plus a switch#Words
one for the same thing without case normalization). I'll try it out.
from switch.vim.
I've tried adding two more helper functions -- take a look, try them out, let me know what you think:
Lines 201 to 225 in 23243cf
I could add one parameterized function instead, but I'd like to keep the old one for compatibility, so I've held off. Plus, the more "programmatic" of an interface I come up with, the harder it might be for someone with little Vimscript experience.
In the future, if there's a third dimension to parameterize by, I'll introduce a common function with a dict parameter and keep the old ones as fronts.
from switch.vim.
Related Issues (20)
- Switch.vim pollutes search history HOT 2
- help with a bash switch? HOT 6
- Add case insesitivity HOT 2
- Does not working eruby_tag_type in eruby filetype. HOT 4
- [wiki] Anyone know how to write a substitution for React props? HOT 3
- Invert logical expression, using De Morgan Law HOT 1
- "." repeats always forward, even if the last used command was "SwitchReverse" HOT 2
- Undefined variable: g:switch_builtins and invalid expression error on startup when opening a Ruby file and loading the plugin through NeoBundle HOT 2
- Enable js toggles for typescript, typescript.tsx filetypes HOT 2
- increase/decrease number HOT 2
- Switching all the flags at once HOT 2
- Possible to call normal commands in switch definition? HOT 10
- Enable switching booleans anywhere on the line and returning to original cursor position HOT 6
- Introduce a way to set priority/precedence? HOT 9
- Idea: Multiple switch alternatives HOT 3
- Comparison to swapit HOT 2
- can you please add a configuration example for lua HOT 2
- NormalizedCaseWords does not work for capitalized words HOT 2
- Patch to allow reverse action (and count) in lambda substitutions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from switch.vim.