-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add CamelCaseMotion plugin #3483
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dope!
@@ -101,6 +101,7 @@ export class Position extends vscode.Position { | |||
|
|||
private _nonWordCharRegex: RegExp; | |||
private _nonBigWordCharRegex: RegExp; | |||
private _nonCamelCaseWordCharRegex: RegExp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should move away from having position.ts
the dumping ground for all positioning related logic as it's a bit of a mess.
As the changes you introduced to this file are specific to camel case, I wonder if we should create a new file under /plugins camelcase.position.ts
?
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not opposed to the idea in principle, but if I were to move I'd either have to duplicate or make public all the get*Word*WithRegex
functions and maybe the getAllPositions
family of functions since they're shared among all the word-based motions. Your call, I'm happy either way!
|
||
// prettier-ignore | ||
const firstSegment = | ||
'(' + // OPEN: group for matching camel case words |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ermagod. Thank you for writing comments.
Thanks for the quick review @jpoon! I'll make these changes a bit later today |
Made CR changes! Though I didn't adjust |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip the position refactoring. Left one tiny comment if you could address. LGTM otherwise.
package.json
Outdated
@@ -449,6 +449,11 @@ | |||
"description": "Override the 'ignorecase' option if the search pattern contains upper case characters.", | |||
"default": true | |||
}, | |||
"vim.camelCaseMotion": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to make this more hierarchic. Can you make this vim.camelCaseMotion.enable
instead? Such that if we do end up creating more configs for camel case, they can live under vim.camelCaseMotion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! I've switched the setting over as you suggested and pushed the new changes.
Hey @jkillian, TravisCI finished with status TravisBuddy Request Identifier: 4d2d4a10-32f9-11e9-909a-37b9af0e35d8 |
Is there any way to configure the keybinds of this PR? (Also, freakin' AWESOME.) |
Glad you like it @ELLIOTTCABLE 😄 You should be able to change the keybindings following the docs here. For example, to make
You can also modify the |
Ah! Any issues you forsee with using this to remap the default motion to being by-camelcase? "vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["w"],
"after": ["<leader>", "w"]
},
{
"before": ["<leader>", "w"],
"after": ["w"]
},
] |
Not entirely sure @ELLIOTTCABLE, I'd say give it a go and see how it works for you 😄 One thing that might be tricky is remapping |
Ugh, that's a good point. And unfortunate. Might need integrated support to pull off operator-motions. v.v |
@ELLIOTTCABLE did you eventually find a way to bind camel case motion to the default keys and have composed commands working? |
Once PR #4735 gets merged it will allow you to do operator-pending mode remaps so you will be able to do this: "vim.operatorPendingModeKeyBindingsNonRecursive": [
{
"before": ["w"],
"after": ["<leader>", "w"]
},
{
"before": ["<leader>", "w"],
"after": ["w"]
},
] It needs to be non recursive otherwise it would loop between the two until 'maxmapdepth'. Also bear in mind that this will work well with PR #4735 but after PR #4995 gets merged this won't work because the "vim.operatorPendingModeKeyBindingsNonRecursive": [
{
"before": ["w"],
"after": ["<Plug>CamelCaseMotion_w"]
},
{
"before": ["<leader>", "w"],
"after": ["w"]
},
] |
What this PR does / why we need it:
Adds a CamelCamelCase motion plugin inspired by https://github.com/bkad/CamelCaseMotion. Adds support for the following motions when enabled:
<leader>w
<leader>e
<leader>b
<operator>i<leader>w
commands.In addition to camelCase, the plugin should also work correctly for snake_case.
Which issue(s) this PR fixes:
Fixes #1220
Fixes #2808 (likely)
Special notes for your reviewer:
There's a gnarly regex in there that's admittedly hard to review, but it's well-documented and can be played around with in Regex101 if using the latest Chrome. I chose to use a regex instead of trying to use VSCode's built in subword navigation or some other mechanism because it made the rest of the implementation quite clean and similar to existing motions.
The aforementioned regex uses some lookbehinds, and thus requires Node 9.0+. This shouldn't be a problem since the latest VSCode bundles Node 10.2. I did bump the docker image to use Node 10 as well for consistency, though I'm not sure this was strictly necessary.
Let me know if any changes to this PR are needed! Hope you don't mind getting a PR for this feature out of the blue 😄