New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
camel case motion text object #460
Comments
I've marked this as a feature request. I'm not sure yet what we would map this to seeing how its an extension to Vim. |
@muellan, you're requesting this to be a new vrapper plugin, right? |
Yes, like the surround plugin or the one for the function argument text object, so a "subword text object plugin". |
Vim has an You asked if there was a way for vim to support underscore or camelCase boundaries. That's how vim does it. Otherwise, you'd have to resort to mappings (http://stackoverflow.com/a/8949552). Anyway, that's my long-winded way of saying that I think a plugin is the right solution for this and I don't think you can really achieve what you want by simply customizing vim or vrapper. |
+1 for a CamelCaseMotion plugin |
This creates a plugin which defines camelCase and snake_case navigation. It's still a work-in-progress but I think I'm ready for some outside opinions to see if I got the use case right.
Hey @mmbradle and @muellan, I finally had time to create a rough implementation of this and I wanted to get your thoughts. I looked at https://github.com/bkad/CamelCaseMotion and http://www.vim.org/scripts/script.php?script_id=1905 and tried coming up with something similar that made sense. So it doesn't exactly mimic either one and I wanted to see if I altered too many things or if it can still meet your needs. Here's what it does right now (or will when I get the key bindings working correctly):
Vimscript 1905 used I guess I figured that if you didn't want to do any sub-word navigation, you'd still want And if neither of you respond because this request is almost 2 years old, I'll just delete all this code. 😆 |
Great news! I definitely still want this. I created a command that lets me map vrapper normal mode keys to eclipses built-in subword navigation. But my 'text object' mapping hacks based on this are of course far from perfect. |
There's one thing preventing me from including it in the next unstable update and it's that I can't get the @albertdev recommended that I use the |
That all sounds great to me. And I still want this as well. I'm used to using comma but could switch to something else if needs be. Underscore works as well, it is a little more intuitive than comma (In my opinion) but it is harder to get to, so I'd say the pros/cons balance each other out. I also agree that I do not want the original behavior of I'd slightly prefer with one key for both snake and camel case. I really like the v3i_ idea. The main use case for me is renaming one part of a descriptive function or variable name, such as renaming
BTW, if you make this too good, then I'll want your implementation in vanilla VIM. |
code figure out which one is relevant.
collide with other commands. Handles more scenarios now.
I've updated the unstable update site with a new build (0.67.20160418) which includes this subword plugin so you guys can try it out. It now detects camelCase and snake_case implicitly so it only uses one key, but I changed that one key to So currently, the plugin does the following: The Of course, it's only after pushing out this update that I find defects. I've been testing this with a camelCase word and snake_case word each on their own line. After installing this plugin, I learned that my regex doesn't quite handle |
I'm still having issues with '\e' not jumping to the next (normal) word when the cursor is already on the last letter of the last (snake/camel) word.
Just tried the plugin - great work so far!
|
One more thing: If CamelCase and snake_case are mixed like this: |
handle the scenario myself. This fixes some corner cases I wasn't handling.
Ok, I've updated the unstable update site again with a new build (0.67.20160419) with some of those issues fixed. You're right, I'm currently looking for the existence of a |
…ord. I kept telling myself I'd come up with a clever regex that would handle every possible scenario but this solution is more readable and works as far as I can tell.
I've updated the unstable update site with some more fixes, please try it again. Also, you said you defined a custom |
Talking about mapping, have you tried |
Remapping is working fine now. I forgot to remove one of my old hacks to emulate subword navigation. |
I finally figured out the Here's what I was using in my
|
Meanwhile I've been experimenting with support for @keforbes Let me know if you discover anything odd about those |
Yeah, I was playing with the idea of adding this to
but then I'd need access to the For my use case, the |
I've updated the unstable update site with a new build (0.67.20160426) which includes this fix. Please give it a try and let me know how it goes. Also, make sure you define your |
Users could bind everything themselves but it's just boilerplate. This command will automate the bindings for them. It works in 4 or 5 ways: - running `:subwordmappings` with no parameters will require you to press `<Leader>b` for the back motion, `i<Leader>` for the textobj. - running `:subwordmappings ,` will assign the back motion to `,b`. The textobject is triggered by `i,`. - running `:subwordmappings , _` will assign the back motion to `,b` but the textobject to `i_`. - finally, the first parameter also accepts `''` to indicate that no mapping prefix should be used, hence binding subword-back to `b`. The (optional) second parameter works like before, if not present it is set to `<Leader>`. Related to #460.
I've added a special command to set up those mappings:
Now that I've committed it I'm wondering if I shouldn't reverse the parameters, but I'll wait for you guys' feedback before doing so. Also note that you can pass more than one character (e.g. @keforbes The possibilities dazzled me though - I'm wondering if we need plugins to explicitly declare variables or if it's essentially free-form like Vim, and when or how it would need to be set (Vrapper has no concept of after / before or even a single config load at startup so concepts are really different from Vim). |
I have mixed feelings about this. I agree it's nice to provide default key bindings so users don't have to add them to their @muellan, @mmbradle, what are your thoughts? Do you like having a single command |
I like the Plug solution. Either that or default leader mappings and the possibility to define the leader key. |
@keforbes You forgot the third option: let the plugin bind default mappings unless you set some special variable (or somehow detect that the user hasn't mapped these Do note that the forked version of the plugin also had something like this. From its documentation:
The original plugin on the other hand simply bound everything to Advantage for the latter is that I don't need to invent a "Variable API", downside is that I need to search through all current mappings. @muellan Your reply seems cut short? |
Before I forget: these options are not mutually exclusive. The custom |
That's true, you can either use |
I've updated the unstable update site with a new build (0.67.20160429) which includes support for |
One little annoyance / defect: |
@muellan, I just released version 0.68.0 over the weekend. Can you install that version and try it again? I think that issue has already been fixed. |
Just installed version 0.68.0; it is fixed. |
There is still one issue: |
@muellan, I've fixed the issue with text objects when the cursor is on the first character of a word. I also fixed the corresponding issue when the cursor is on the last character of a word. And also if the cursor was on the last character of a subword. I'll let you know when I've updated the unstable update site so you can test it out. |
@muellan, ok, I've updated the unstable update site with 0.69.20160629 so you can test out my changes. Please let me know how it goes. |
works fine now - thanks! |
It would be nice to have text objects for CamelCase editing ('dc,w' : 'CamelCase' -> 'Case') like seen here https://github.com/bkad/CamelCaseMotion.
Having some objects for underscore-separated words would also be great ('dc_w' : 'abc_def' -> 'def')
The text was updated successfully, but these errors were encountered: