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

Tab completion #7202

Closed
mo8it opened this issue Nov 22, 2022 · 26 comments · Fixed by #10199
Closed

Tab completion #7202

mo8it opened this issue Nov 22, 2022 · 26 comments · Fixed by #10199
Labels
completions Issues related to tab completion configuration Issue related to nu's configuration
Milestone

Comments

@mo8it
Copy link

mo8it commented Nov 22, 2022

Describe the bug

Tab completion seems to be broken starting with version 0.71.

See this comment: https://fosstodon.org/@jntrnr/109389406197343536

How to reproduce

  1. Open nushell
  2. Type ls (with space)
  3. Press Tab
  4. The completion options appear
  5. Press Tab again
  6. Nothing happens!
  7. Press Shift + Tab
  8. Completion moves to last option!

Expected behavior

Shift + Tab moves in the other direction, but Tab seems to be broken! It should go to the next completion. This was the behavior before version 0.71.

Screenshots

No response

Configuration

❯ version | transpose key value | to md --pretty

key value
version 0.71.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.65.0 (897e37553 2022-11-02)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.65.0 (4bc8f24d3 2022-10-20)
pkg_version 0.71.0
build_time 2022-11-09 17:52:12 +01:00
build_rust_channel release
features default, trash, which, zip
installed_plugins

Additional context

Tried with --config "" to ignore my config, but it is the same behavior.

@kamirr
Copy link
Contributor

kamirr commented Nov 22, 2022

Works on main for me.

key value
version 0.71.1
branch main
commit_hash e0577e1
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.63.0 (4b91a6ea7 2022-08-08)
rust_channel 1.63.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.63.0 (fd9c4297c 2022-07-01)
pkg_version 0.71.1
build_time 2022-11-22 23:13:59 +01:00
build_rust_channel release
features database, default, trash, which, zip
installed_plugins

@fdncred
Copy link
Collaborator

fdncred commented Nov 22, 2022

I believe this is the PR that changed this functionality. The intent Dan was going for was to have the arrow keys be the menu navigation instead of the tab key by default.

This is how you can circumvent this behavior. Use a keybinding like this one.

    {
       name: trigger-completion-menu
       modifier: none
       keycode: tab
       mode: emacs
       event: { 
         until: [
           { send: menu name: completion_menu }
           { send: menunext }
           { edit: complete }
         ]
       }
    }

and I have completion_menu defined in my menus section of the config.nu defined this way.

    {
      name: completion_menu
      only_buffer_difference: false
      marker: $"(char -u 1f4ce) "
      type: {
          layout: columnar
          columns: 4
          col_width: 20   # Optional value. If missing all the screen width is used to calculate column width
          col_padding: 2
      }
      style: {
          text: { fg: "#33ff00" }
          selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b}
          description_text: yellow
      }
    }

@mo8it
Copy link
Author

mo8it commented Nov 22, 2022

Using Tab to navigate is like using Alt + Tab to navigate in the desktop. It is something natural for almost every terminal user. I don't think that it is something that people have to configure.
Also: Why does Shift + Tab work? It is not even consistent.
Please revert that change then. Thanks a lot!

@fdncred
Copy link
Collaborator

fdncred commented Nov 22, 2022

FWIW, I agree with you and I think this one line change should be reverted. However, I was trying to point out to you that it could be configured to act like you want it to now so you don't have to wait and see if it eventually gets reverted or not.

@mo8it
Copy link
Author

mo8it commented Nov 22, 2022

Sorry if I was harsh. Thanks for helping ❤️

@sholderbach sholderbach added completions Issues related to tab completion configuration Issue related to nu's configuration labels Nov 23, 2022
@sholderbach
Copy link
Member

I think the core intent of the underlying change was to support filling common prefixes while avoiding the surprising automatic completion of everything should your typing narrow the search space, but I think the broken Tab action is just an artifact of landing the config changes. We should resolve that first (and then polish the underlying completion setup) but I think reverting the change would cause another regression.

@valpackett
Copy link
Contributor

IMO instead of the surprising automatic completion, the default should be like how most shells work: "if there's only one result available, Tab completes, otherwise Tab completes up to the common prefix and then cycles".

The keybinding thing above gets closer to that than ever before! Except for doing things when the menu is already open and you're typing more.

@upsala1
Copy link

upsala1 commented Dec 21, 2022

I also encountered this issue today and fixed it by changing the mode of the keybind with name: completion_menu from
mode: emacs to mode: [emacs vi_normal vi_insert]. I am using vi mode and for the completion_previous keybind it was already set to the list including vi_normal and vi_insert. I hope this is somewhat clear

@amtoine
Copy link
Member

amtoine commented Feb 8, 2023

i think i'm able to reproduce this in nushell version 0.75.1 on bea7ec3 👍

@dschrempf
Copy link

Hi! Cycling with the TAB key is still not working. For example cd f <TAB> will not cycle through folder1, folder2, etc. I am using the vi mode.

@fdncred
Copy link
Collaborator

fdncred commented May 9, 2023

I have no issues tabbing on the latest main branch (0.79.1) in Windows or Linux, haven't tried Mac yet.
tabbing

@amtoine
Copy link
Member

amtoine commented May 9, 2023

just built the latest revision but this does not work on my end 🤔

my config

should be 2a484a3e7...

╭────────────────────┬──────────────────────────────────────────╮
│ version │ 0.79.1 │
│ branch │ main │
│ commit_hash │ 0ea973b78b57bb01ae0b58ecd1c02fda21184043 │
│ build_os │ linux-x86_64 │
│ build_target │ x86_64-unknown-linux-gnu │
│ rust_version │ rustc 1.67.1 (d5a82bbd2 2023-02-07) │
│ rust_channel │ 1.67.1-x86_64-unknown-linux-gnu │
│ cargo_version │ cargo 1.67.1 (8ecd4f20a 2023-01-10) │
│ build_time │ 2023-05-07 10:44:01 +02:00 │
│ build_rust_channel │ release │
│ features │ default, zip │
│ installed_plugins │ │
╰────────────────────┴──────────────────────────────────────────╯

@dschrempf
Copy link

dschrempf commented May 9, 2023

My config.nu file is minimal:

let-env config = {
  edit_mode: vi
}

Could this be the issue? Do we need to configure tab cycling somehow? Maybe I missed something above. Cycling backwards with Shift+TAB works.

EDIT: Also, I am on version 0.79.0.

@amtoine
Copy link
Member

amtoine commented May 9, 2023

@dschrempf
i'm not sure it has to do with any config 🤔
i've tried in nu --no-config-file and it does not work 😮

@fdncred
Copy link
Collaborator

fdncred commented May 9, 2023

Could this be the issue?

Yes, it could be because there are keybindings and menus in the default_config.nu.

Namely, these keybindings

    {
      name: completion_menu
      modifier: none
      keycode: tab
      mode: [emacs vi_normal vi_insert]
      event: {
        until: [
          { send: menu name: completion_menu }
          { send: menunext }
        ]
      }
    }
    {
      name: completion_previous
      modifier: shift
      keycode: backtab
      mode: [emacs, vi_normal, vi_insert] # Note: You can add the same keybinding to all modes by using a list
      event: { send: menuprevious }
    }

and this menu

      {
        name: completion_menu
        only_buffer_difference: false
        marker: "| "
        type: {
            layout: columnar
            columns: 4
            col_width: 20   # Optional value. If missing all the screen width is used to calculate column width
            col_padding: 2
        }
        style: {
            text: green
            selected_text: green_reverse
            description_text: yellow
        }
      }

I know for a fact, that for me, with nu -n --no-std-lib the tab will not work for menu navigation and you have to use the arrow keys.

@dschrempf
Copy link

Isn't it weird to require special configuration to make tab cycling work?

@fdncred
Copy link
Collaborator

fdncred commented May 9, 2023

Isn't it weird to require special configuration to make tab cycling work?

Not if the default is to use arrow keys.

Having said that, we might should change our default.

@dschrempf
Copy link

dschrempf commented May 10, 2023

I see! Thanks for your help! Consider my vote on the TAB-cycle side 😄 !

EDIT: It is a bit weird though that back-cycling with Shift-TAB works out of the box. I also do not see any problem with using both ways to cycle as defaults.

@dschrempf
Copy link

For reference: Using you menu and keybinding snippet, TAB cycling works.

I also noticed an inconsistency in the keybinding configuration: one list uses commas, the other doesn't. I am aware that both ways are valid syntax, but it is a bit confusing to use both syntaxes right next to each other, isn't it?

@fdncred
Copy link
Collaborator

fdncred commented May 10, 2023

one list uses commas, the other doesn't

I'm sure it came from me copy-n-pasting it into my config from someon else's example years ago. I don't pay much attention to it but I'm also not against standardizing it.

I'm not sure if anyone would object to tab/shift-tab being the defaults if someone wants to take that on. I'm not sure if it's reedline's defaults or nushell's defaults that we're using right now.

@Abdillah
Copy link
Contributor

Abdillah commented Jun 21, 2023

@fdncred In my case adding { send: menunext } config doesn't solve the problem in v0.80.0. Even with --no-config-file.

@fdncred
Copy link
Collaborator

fdncred commented Jun 21, 2023

I use tab all the time. I don't understand what the issue is. I use this in my config file.

menu

  {
    name: completion_menu
    only_buffer_difference: false
    marker: $"(char -u '1f4ce') "
    type: {
      layout: columnar
      columns: 4
      col_width: 20   # Optional value. If missing all the screen width is used to calculate column width
      col_padding: 2
    }
    style: {
      text: { fg: "#33ff00" }
      selected_text: { fg: "#0c0c0c" bg: "#33ff00" attr: b}
      description_text: yellow
    }
  }

keybinding

  {
    name: trigger-completion-menu
    modifier: none
    keycode: tab
    mode: [emacs vi_normal vi_insert]
    event: { 
      until: [
        { send: menu name: completion_menu }
        { send: menunext }
        { edit: complete }
      ]
    }
  }

@Abdillah
Copy link
Contributor

That actually works. But, I have double let-env unfortunately. Thanks!

@Abdillah
Copy link
Contributor

Also, for everyone, this should works when nushell generate default configuration for us.
The --no-config-file indeed remove the tab completion.
And I vote for Tab as default because it has minimal movement (than arrow key).

@mpizenberg
Copy link

I'd also be interested in having support for tab cycling by default. I like my config files clean and as small as possible.

@amtoine
Copy link
Member

amtoine commented Sep 3, 2023

this missing feature has annoyed me enough 😆
can you check if #10199 solves this? 😇

fdncred pushed a commit that referenced this issue Sep 4, 2023
should close #7202

# Description
i have been annoyed enough by this missing feature, so let's add that to
Nushell without requiring any user configuration 😏

# User-Facing Changes
this PR should allow tab completion cycling everytime, without requiring
the user to use the default config files or add the following
keybindings to their config
```nushell
    {
        name: completion_menu
        modifier: none
        keycode: tab
        mode: [emacs vi_normal vi_insert]
        event: {
            until: [
                { send: menu name: completion_menu }
                { send: menunext }
                { edit: complete }
            ]
        }
    }
```

### 🧪 try it out
from the root of the repo, one can try `<tab>` in each of the following
cases:
- `cargo run -- -n` to load Nushell without any config
- `cargo run -- --config
crates/nu-utils/src/sample_config/default_config.nu --env-config
crates/nu-utils/src/sample_config/default_env.nu` to load the default
configuration
- `cargo run` to load the user configuration

## before
- `<tab>`, `ls <tab>` and `str <tab>` only work with the second `cargo
run`, i.e. when loading the default config files

## after
- `<tab>` should cycle through the available commands
- `ls <tab>` should cycle through the available files and directories
- `str <tab>` should cycle the subcommands of `str`

in all three cases

# Tests + Formatting

# After submitting
@hustcer hustcer added this to the v0.85.0 milestone Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completions Issues related to tab completion configuration Issue related to nu's configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.