VSCodeVim / Vim

:star: Vim for Visual Studio Code
http://aka.ms/vscodevim
MIT License
13.76k stars 1.31k forks source link

run vim commands from command palette #6255

Open hackasaur opened 3 years ago

hackasaur commented 3 years ago

Is your feature request related to a problem? Please describe. I don't like to switch between command palette and vim command field. I have a habit of using :w to save or :set nonumber for hiding line numbers but most commands are available with auto suggestions in command palette. I know that I can bind : to open the command palette but then I can't type those few vim commands so I have to keep both, which feels redundant and sometimes confusing I think there should be single command field/palette for all actions to keep it simple.

Describe the solution you'd like users should be able to run vim commands from command palette and even define their own "aliases" for their common vscode commands, maybe something like this:

"vim.commandPaletteModeAlias": [
      {
          "before": [":w"],
          "commands": [
              "workbench.action.files.save,
          ]
      },
      {
          "before": [":tglActivity"],
          "commands": [
              "workbench.action.toggleActivityBarVisibility",
          ]
      }

so users can bind : to command palette and then use their favorite vim commands and vs code commands from one place and even make their own aliases easy to remember aliases.

Describe alternatives you've considered first I was thinking maybe if I use vim.normalModeKeyBindings I could set aliases for vscode commands like this so that I don't need to switch to command palette:

"vim.normalModeKeyBindings": [
    {
        "before": [":tglActivityBar"],
        "commands": [
            "workbench.action.toggleActivityBarVisibility",
        ]
    }

but even if it's possible the vim command field in the status bar does not give any auto suggestions so it will be hard to use so I think it's better to use the command palette.

EdwinVanRooij commented 3 years ago

I guess my request is somewhat related, so I'll post it here as well.

I'd loooove to be able to run commands from the command palette as well, but through mappings in my $HOME/.vimrc. For example, this is the .vimrc I use for Visual Studio:

nnoremap < :vsc Window.PreviousTab<cr>
nnoremap > :vsc Window.NextTab<cr>

In the example of @hackasaur, a line like nnoremap T :vsc workbench.action.toggleActivityBarVisibility<cr> could achieve toggling the activity bar visibility by pressing T in normal mode.

On second thought, I'm not sure how related this is. Let me know if I should move this suggestion into a new issue.

Thanks in advance!

mattstermiller commented 3 years ago

I'd loooove to be able to run commands from the command palette as well, but through mappings in my $HOME/.vimrc.

This is already implemented, but doesn't seem to be documented, which is a shame. I had to look at the code to discover this. All you have to do is put the full name of the vscode command on the right side of your mapping, like so (tested, working):

nnoremap < workbench.action.previousEditorInGroup
nnoremap > workbench.action.nextEditorInGroup
EdwinVanRooij commented 2 years ago

Ohhh fantastic, thank you @mattstermiller!

EdwinVanRooij commented 2 years ago

I noticed the extension was last updated 2 months ago:

image

Any idea as to when the fix to this issue will be released onto the marketplace?

mattstermiller commented 2 years ago

Any idea as to when the fix to this issue will be released onto the marketplace?

Do you mean the ability to map vscode commands in your vimrc? That has been part of the extension this entire time... I only discovered it 2 months ago.

If you mean the original request of this thread, the developers haven't even indicated that this is something they want to support.

EdwinVanRooij commented 2 years ago

Ohh sorry I just noticed that I posted my previous comment on the wrong issue. I meant to post it here: #4785

Got here through an email search, my bad!