Vim: Ability to define custom ex commands

Created on 1 Jan 2020  路  9Comments  路  Source: VSCodeVim/Vim

Is your feature request related to a problem? Please describe.
I use neovim integration, but I am unable to define the custom ex commands I use in neovim, and the commands defined in my ~/.config/nvim/init.vim are not respected. To give you a flavour, these are the ones I currently have defined for neovim:

command! W   :w
command! Wa  :wa
command! Wq  :wq
command! Wqa :wqa
command! E   :e

Describe the solution you'd like
I am able to define custom ex commands either in VSCode settings.json or have the ones in my neovim config respected.

Describe alternatives you've considered

Additional context
I'd be happy to have a go at implemeting this myself if this is something you'd accept a PR on and someone could point me in the right direction.

kinfeature

Most helpful comment

Just wanted to add that custom ex commands are an important part of my Vim workflow, and I would also love to see these supported in VSCodeVim! For example, in my Vim config I have:

command! Etodo edit ~/Desktop/todo.txt
command! BO BufOnly

The first lets me use :Etodo<Enter> to jump to my todo doc, and the second allows me to use :BO<Enter> to invoke a script that closes other buffers. I could define keyboard shortcuts for these things, but there's a point at which I can't remember any more shortcuts! I also use them for more complex things (e.g. where an argument is required), but I'd be satisfied even with basic support.

By the way, I think this would be useful outside of the nvim integration as well, e.g. I'd love to just be able to define something like this:

    "vim.exModeCommands": [
        {
            "before": [":BO"],
            "commands": ["workbench.action.closeOtherEditors"],
        }
    ],

Or maybe this is possible? I wasn't able to find anything like this in the docs or other issues.

Cheers!

All 9 comments

On further investigation - after running my own amended version of the extension with the patch in #4456 applied - I was able to get a bit more information.

It looks like running :command! W w _does_ in fact create a command :W, but unfortunately the :W command doesn't work. It gives produces an error about a missing filename:

image

I think this is because:

When running :w in VSCode the command is caught and handled by VSCodeVim using the VSCode API. It never reaches neovim, and doesn't need to.

However when running :W the command is not understood by VSCodeVim, so it is forwarded on to neovim.

Neovim then maps :W to :w and runs that command _in_ neovim.

The neovim :w command can't work as the file isn't actually open in neovim. It needs to be the VSCodeVim version of the command that's run.

So on reflection I think this is likely to be a trickier task than I initially thought, unless someone who knows the codebase well thinks otherwise?

Just wanted to add that custom ex commands are an important part of my Vim workflow, and I would also love to see these supported in VSCodeVim! For example, in my Vim config I have:

command! Etodo edit ~/Desktop/todo.txt
command! BO BufOnly

The first lets me use :Etodo<Enter> to jump to my todo doc, and the second allows me to use :BO<Enter> to invoke a script that closes other buffers. I could define keyboard shortcuts for these things, but there's a point at which I can't remember any more shortcuts! I also use them for more complex things (e.g. where an argument is required), but I'd be satisfied even with basic support.

By the way, I think this would be useful outside of the nvim integration as well, e.g. I'd love to just be able to define something like this:

    "vim.exModeCommands": [
        {
            "before": [":BO"],
            "commands": ["workbench.action.closeOtherEditors"],
        }
    ],

Or maybe this is possible? I wasn't able to find anything like this in the docs or other issues.

Cheers!

Similarly, I would really like to be able to define custom commands like :bn and :bp to move between tabs.

@kendallroth :tabn/:tabp do this. :bn and :bp should probably be built-in aliases for the same, since VSCode doesn't have the concept of a buffer separate from a tab.

@J-Fields I apologize for not already knowing that (did I miss in docs?)! Yeah, since there is no difference/concept it would make it easier/quicker by a few characters 馃槃

did I miss in docs?

If you did, I wouldn't blame you - our docs need serious work lol

@kendallroth #5518

Excellent, thank you for that! I really, really appreciate the improvements to my workflow that combining Vim and VSCode bring...great package!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

orn688 picture orn688  路  3Comments

jaredly picture jaredly  路  3Comments

gerardmrk picture gerardmrk  路  3Comments

edwintorok picture edwintorok  路  3Comments

triztian picture triztian  路  3Comments