How to make vim extension in visual code studio to use binding that repeats change for next match - visual-studio-code

How can I make vim extension in VSC make to use my keybinding?
In my .vimrc I got those lines:
" s* - CRTL + D like behavior
nnoremap <silent> s* :let #/='\<'.expand('<cword>').'\>'<CR>cgn
xnoremap <silent> s* "sy:let #/=#s<CR>cgn
How could I add them to my VSC?
Tried to add to my settings.json something like below, but got no idea how to add it properly every time I got an error:
Failed to handle key `*`: command '"sy:let #/=#s<CR>cgn' not found
"vim.normalModeKeyBindings": [
{
"before": [
"s",
"*"
],
"commands": [
":nohl:let #/='\\<'.expand('<cword>').'\\>'<CR>cgn",
],
"silent": true
},
{
"before": [
"s",
"*"
],
"commands": [
"\"sy:let #/=#s<CR>cgn",
],
"silent": true
},
]

Related

How to map "Go To Implementation" using VsCode Vim?

I want to map something like gi to open a Typescript interface implementation for example. In VsCode the shortcut is Ctrl + F12 and I tried to add a map like this inoremap gi <C-F12> in .vimrc file but that does not work.
I also tried to do that in my settings.json but still no results.
"vim.insertModeKeyBindings": [
{
"before": ["g", "I"],
"after": ["<C-F12>"]
}
]
How can I do that?
You can achieve that by mapping a shortcut to a VSCode command, not a set of keys. If you look at VSCode shortcuts, you can see that the Go To Definition action is related to a command so you can take that command and map to a vim shortcut in your settings.json file.
In the example I will map gI to editor.action.goToImplementation which is the related command.
"vim.insertModeKeyBindings": [
{
"before": ["g", "I"],
"commands": ["editor.action.goToImplementation"]
}
],
"vim.normalModeKeyBindings": [
{
"before": ["g", "I"],
"commands": ["editor.action.goToImplementation"]
}
]

Hide search highlighting doesn't work VScode Vim

I'm starting to learn vim in VSCode and I have the following settings.json
{
"window.zoomLevel": 1,
"vim.insertModeKeyBindings": [
{
"before": [
"<C-c>"
],
"after": [
"<Esc>"
]
}
],
"vim.hlsearch": true,
"vim.normalModeKeyBindingsNonRecursive":[
{
"before":[
"<leader>",
"/"
],
"commands":[
":nohl"
]
},
{
"before":[
"<space>"
],
"after":[
"<leader>"
]
}
]
}
The problem is the ,/ part. It doesn't hide the highlighted search, it recognizes the leader key but after pressing /, the command :nohl is not executed.
I don't see what's wrong with the code, any help is appreciated.

How do I rebind Y to yank to the end of the line when using VS Code's Vim extension?

I'm using VS Code's neovim integration with neovim installed from snap. I want Y to work the same way as D and C. In ~/.config/nvim/init.vim I would add
map Y y$
How do I do this in VS Code? I've tried
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["Y"],
"after": ["y$"]
},
],
and
"vim.normalModeKeyBindings": [
{
"before": ["Y"],
"after": ["y$"]
}
],
but neither worked.
Turns out you need to specify and separate each key into an individual "", so that would be:
"vim.normalModeKeyBindings": [
{
"before": ["Y"],
"after": ["y", "$"]
}
]

Open specific file using key when using vscode / vim

I often work in a specific file and would like to have that file opened when pressing a shortcut. I tried several combinations but seem to hit a wall..
// file settings.json
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["leader","t"],
"commands": [
"vscode.open"
],
"args": "notes/todo.md"
}
]
Any hint on how i can get this working? When executing the above code i get a illegal argument 'resource'
Using normal vim keywords solves the problem.
{
"before": [
"leader", "t"
],
"commands": [
":edit file:///notes/todo.md"
]
}

Why is vscode vim.otherModesKeyBindingNonRecursive an unknown configuration?

I had this setting for couple of weeks now but it stopped working today. This is a setting for vscode vim easymotion. I dont know what happened. I havent change anything. Does anyone know why?
OS macOS high Sierra.
Vscode Version 1.24.1 (1.24.1).
Vscodevim v0.14.0 .
"vim.otherModesKeyBindingsNonRecursive": [
{
"before": [
"s"
],
"after": [
"leader",
"leader",
"s"
]
}
],
It looks like otherModesKeyBindingsNonRecursive has been replaced. See pull request 2726 on the VSCodeVim project. Instead see the current Key Remapping section in the project's README:
Custom remappings are defined on a per-mode basis.
"vim.insertModeKeyBindings"/"vim.normalModeKeyBindings"/"vim.visualModeKeyBindings"
Their example usage:
Bind : to show the command palette:
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": [":"],
"commands": [
{
"command": "workbench.action.showCommands",
}
]
}
]