Git Product home page Git Product logo

Comments (8)

moll avatar moll commented on August 27, 2024 1

I finally got around to tweaking my configuration to use case-insensitive matches and can confirm they work! Thank you again, Andrew from the past!

from switch.vim.

AndrewRadev avatar AndrewRadev commented on August 27, 2024

I don't think there's any way to "preserve case" automatically for all situations. If nothing else, you might actually want to change the case. A much longer discussion on the topic starts here.

Generally, I'd just recommend that you triplicate your definitions with lowercase, titlecase and uppercase versions. Considering you have a large list, I guess you'd prefer some easier way to do that, so maybe something like what I suggest in that thread:

let g:switch_definitions =
      \ [
      \   ['normalize_case', ['true', 'false']]
      \ ]

Though, I'm not sure how relevant this proposal is. Maybe more like:

let g:switch_definitions =
      \ [
      \   switch#NormalizedCase(['true', 'false'])
      \ ]

Or something. Of course, I'd have to actually get around to implementing something like that. What do you think of the idea?

from switch.vim.

moll avatar moll commented on August 27, 2024

Ah, okay, I can imagine that someone might want, depending on the language, to switch between capitalized and non-capitalized strings. Fair enough.

I don't have a strong preference to either option. The former might lend itself to easier scripting, but if the latter isn't noticably slower to call hundreds of times per Vim startup, go with which you believe to be better.

from switch.vim.

moll avatar moll commented on August 27, 2024

The more switches I have in my vimrc, the less VimL is suitable for them. :P
Fortunately the switch structures are plain arrays and maps, which means I can move them to a JSON file. Mentioning this that if you go with helper methods, then loading switches from JSON won't be that easy.

Just in case: I use a random JSON parser in Vim to load bigger data structures, so I'm not talking about adding JSON support to Switch.vim itself. ;)

from switch.vim.

AndrewRadev avatar AndrewRadev commented on August 27, 2024

I've implemented case normalization, in the way I explained, with the switch#NormalizedCase helper. The commit is 7f19508. If you take a look, you'll notice I've written some documentation on the helper, but also put some info on what the underlying data format is. Which means that you should be able to use this to generate the definitions from JSON as you're doing.

Could you try it out and let me know if it makes sense?

from switch.vim.

moll avatar moll commented on August 27, 2024

Sweet. Will try. Thanks.

Any particular reason you went with underscore prefixed keys instead of something else? Like $type?

from switch.vim.

AndrewRadev avatar AndrewRadev commented on August 27, 2024

No particular reason. Anything I put in there could also be used as a "normal" substitution. Can't say whether one is more common than the other, but worst case scenario I guess you could do something like {_type: 'normal', _definition: ...}. Although if I decide to do nesting... Well, I'll think about it.

from switch.vim.

AndrewRadev avatar AndrewRadev commented on August 27, 2024

I think case normalization is working, so I'll go ahead and close this issue for now.

from switch.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.