Open rsslldnphy opened 4 years ago
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:
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!
For anyone else who stumbles across this, I wrote up a stackoverflow answer that provides kind of a hacky workaround:
https://stackoverflow.com/a/67560051/2378475
It's far from perfect (some of the downsides are discussed in the comment), but it works, and is good enough for the custom commands that are stuck in my muscle memory.
Since this is still open and it was really conflicting with my workflow, I decided to hack it so at least it works in my machineâ„¢.
The expression parser registers the command like this:
[['w', 'rite'], WriteCommand.argParser],
So what we need is another command registered like:
[['W', 'rite'], WriteCommand.argParser],
Please note the uppercase W
. You can pull the repo, edit the code and package the extension, or you can edit the bundle since it's a simple change, I went for the later since I'm lazy.
Edit:
~/.vscode/extensions/vscodevim.vim-1.23.2/out/extension.js
Search for "rite"
, you can think of that as a keyword that will point you straight to the point where you have to make the edits and copy pasting that array:
Yeah, it's not ideal and if I update to a new version I'll have to do it again, but it works as intended, not like the other workaround I've seen :shrug: So just sharing this with you guys in case it helps anyone until we get native support.
@PaNaVTEC Amazing, thank you so much
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: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.