Skip to content
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

Smart tab (aka tabout) #4443

Merged
merged 2 commits into from
Aug 1, 2023
Merged

Conversation

dead10ck
Copy link
Member

@dead10ck dead10ck commented Oct 24, 2022

This adds new commands that will traverse up to the parent tree-sitter node and move to either the beginning or the end. It also adds an optional feature I've called "smart tab" which will run the latter command when tab is pressed, unless the cursor is preceded only by whitespace, in which case it will insert a tab as normal. With the default bindings, S-tab can be pressed to explicitly only insert a tab. This can be used to emulate a tabout behavior.

asciicast

Some things I'm unsure about in the approach:

  • In the menu, the tab key is bound to cycling through menu items. This cuts the usefulness of this feature because when the auto complete menu pops up, it doesn't work any more. To get around this, I added a config option to ignore the tab key in the menu component, but this feels a little bit hacky to me. I'm not really sure what else to do though.
  • Key mappings. Really not sure what to bind these to in the default mappings. Personally I've found it so useful that I've bound the new movement commands to tab in normal mode as well, although due to the terminal conflict with C-i, this would clearly be a controversial choice in the default bindings.

This change is based on top of #4425 and #6156

@dead10ck dead10ck force-pushed the supertab branch 2 times, most recently from 04ef07a to 73f4299 Compare October 24, 2022 05:03
Cargo.toml Outdated Show resolved Hide resolved
helix-view/src/editor.rs Outdated Show resolved Hide resolved
@kirawi kirawi added A-helix-term Area: Helix term improvements A-core Area: Helix core improvements S-waiting-on-review Status: Awaiting review from a maintainer. labels Oct 25, 2022
@dead10ck dead10ck force-pushed the supertab branch 4 times, most recently from 13875aa to 163e4dc Compare November 1, 2022 04:50
@dead10ck dead10ck force-pushed the supertab branch 3 times, most recently from 5eddb01 to 7d144f2 Compare November 21, 2022 17:49
@dead10ck dead10ck force-pushed the supertab branch 3 times, most recently from 1c11a25 to 30c15da Compare December 5, 2022 16:21
@dead10ck dead10ck force-pushed the supertab branch 2 times, most recently from 829015b to 2d90e8e Compare February 5, 2023 17:03
@dead10ck dead10ck force-pushed the supertab branch 2 times, most recently from 50146c9 to c46bc36 Compare February 28, 2023 05:26
@dead10ck dead10ck force-pushed the supertab branch 2 times, most recently from 03af146 to e8ef964 Compare August 1, 2023 03:41
Implement `smart_tab`, which optionally makes the tab key run the
`move_parent_node_start` command when the cursor has non- whitespace to
its left.
@dead10ck
Copy link
Member Author

dead10ck commented Aug 1, 2023

Ok I think I got all the comments 🙂

@the-mikedavis the-mikedavis merged commit 15e07d4 into helix-editor:master Aug 1, 2023
6 checks passed
@dead10ck dead10ck deleted the supertab branch August 1, 2023 15:40
@dpc
Copy link
Contributor

dpc commented Feb 27, 2024

For reference:

[keys.normal]
tab = "move_parent_node_end"
S-tab = "move_parent_node_start"

[editor.smart-tab]
enable = true

[keys.insert]
S-tab = "move_parent_node_start"

[keys.select]
tab = "extend_parent_node_end"
S-tab = "extend_parent_node_start"

BTW. I might have missed it, but it might be worthwhile documenting the more elaborated setup somewhere in the docs. And also having to customize 5 bindings to set it up feels kind of ... Vimish. I wish there was something like editor.smart-tab.enable = "full" or something that would do it automatically.

@David-Else
Copy link
Contributor

@dpc I have:

[keys.normal]
"tab" = "expand_selection"
"S-tab" = "shrink_selection"

No need for any extra select mode bindings as it selects already. I am not sure about your editor.smart-tab.enable = "full" idea.

@dpc
Copy link
Contributor

dpc commented Feb 27, 2024

No need for any extra select mode bindings as it selects already.

How does it work in selection mode? (I haven't tried, but I'm curious what exactly is responsible for it working, more than the effect)

I have this feature enabled and configured since it was a PR, so I might have missed something, but when I google and look through the docs I only find https://docs.helix-editor.com/master/configuration.html#editorsmart-tab-section that doesn't explain (or advertise) this feature much at all, and doesn't seem to enable any extra binding that made a big difference when I was first trying it out.

@dead10ck
Copy link
Member Author

@dpc I have:

[keys.normal]
"tab" = "expand_selection"
"S-tab" = "shrink_selection"

No need for any extra select mode bindings as it selects already. I am not sure about your editor.smart-tab.enable = "full" idea.

Not really sure what this has to do with @dpc 's question. These bindings aren't for smart tab, and the bindings they're asking about aren't in the default key map.

@dpc the reason this isn't in the default key map is because it needs a terminal with support for the Kitty keyboard protocol to work, and we don't want to require that in the default bindings.

But smart tab is enabled by default, so you don't need that part.

@dead10ck
Copy link
Member Author

editor.smart-tab.enable = "full"

We've also been disinclined to make configuration "kits" like this because they require special case logic and have confusing semantics with respect to overrides.

@dpc
Copy link
Contributor

dpc commented Feb 28, 2024

@dpc the reason this isn't in the default key map is because it needs a terminal with support for the Kitty keyboard protocol to work, and we don't want to require that in the default bindings.

I'm confused - seems to me like all I'm binding is tab and S-tab. Is it the S-tab being not a valid keycode+modifier combo or something?

Anyhow, would it make sense to expand https://docs.helix-editor.com/master/configuration.html#editorsmart-tab-section with recommended settings or something? Hmmm... are even the settings i have recommended? :D . I just copied them from some previous comment in the past and it worked great.

@dead10ck
Copy link
Member Author

dead10ck commented Feb 28, 2024

I'm confused - seems to me like all I'm binding is tab and S-tab. Is it the S-tab being not a valid keycode+modifier combo or something?

Yeah, in standard terminals, Shift + Tab does not work. Also, tab is ambiguous with Ctrl-i, which is the binding for going forward in the jump history, so binding to tab in normal mode overwrites that binding.

Anyhow, would it make sense to expand https://docs.helix-editor.com/master/configuration.html#editorsmart-tab-section with recommended settings or something? Hmmm... are even the settings i have recommended? :D . I just copied them from some previous comment in the past and it worked great.

Sure, we'd appreciate a PR 🙂

dpc added a commit to dpc/helix that referenced this pull request Feb 29, 2024
@dpc
Copy link
Contributor

dpc commented Feb 29, 2024

@dead10ck #9762 , happy to tweak to improve.

dpc added a commit to dpc/helix that referenced this pull request Feb 29, 2024
dpc added a commit to dpc/helix that referenced this pull request Mar 1, 2024
pascalkuthe pushed a commit that referenced this pull request Mar 1, 2024
Desdaemon pushed a commit to Desdaemon/helix that referenced this pull request Mar 4, 2024
postsolar pushed a commit to postsolar/helix that referenced this pull request Apr 4, 2024
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
Vulpesx pushed a commit to Vulpesx/helix that referenced this pull request Jun 7, 2024
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Helix core improvements A-helix-term Area: Helix term improvements S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants