How can I change the cursor keys in the VIM extension for vscode - visual-studio-code

I use the Colemak DH mod layout, which moves around the default keys used for navigation in normal mode. I was wondering if there was any way to remap the hjkl cursor key combo to mnei, or better yet, neio. I am not actually using vim, but rather using the VIM extension for vscode. I've been looking around the internet, but I couldn't find anything.

I know of two ways of doing so:
Approach 1 importing .vimrc
That's what I'm currently using. I have the following settings in the VSCode config, that make VIM plugin to load the specified vimrc file
"vim.vimrc.enable": true,
"vim.vimrc.path": "$HOME/.vim/vimrc_vscode",
And then in vimrc_vscode:
nnoremap j h
nnoremap k j
nnoremap h k
vnoremap j h
vnoremap k j
vnoremap h k
Approach 2 VS code settings
You can use the "non recursive" remapping setting to swap the keys the way you want.
Example (swap j and k):
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["j"],
"after": ["k"]
},
{
"before": ["k"],
"after": ["j"]
}
]
See more at https://github.com/VSCodeVim/Vim#viminsertmodekeybindingsnonrecursivenormalmodekeybindingsnonrecursivevisualmodekeybindingsnonrecursiveoperatorpendingmodekeybindingsnonrecursive

Related

Is there a particular key to enter one character and exit insert mode in vim vscode extension?

I find myself adding a single letter during edits. Is there any way to add a character and exit insert mode just like replacing r but not deleting the character in Vs code vim extension?
pressing i <character> <Esc> each and every time defeats the purpose of being productive.
I have also looked for mapping and tried but not sure how they work.
Any help is appreciated.
From normal mode, you can put yourself in insert mode, type a space, exit back to normal mode, then put yourself in replace mode. That way you find your cursor on a blank space in replace mode, where you can simply type the character you want to add.
Here's how to do it (replace "your-desired-mapping-here" by the mapping that you like, for example: M)
vscode vim plugin way: (add this to your settings.json)
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["<your-desired-mapping-here>"],
"after": ["i", " ", "<ESC>", "r"]
}
]
vim way: (add this to your .vimrc)
nnoremap <your-desired-mapping-here> i <esc>r
note: please notice the space after i in the vim way.

disable vscode change tab on 'gt'

I use VIM extension in VSCode. One of my favourite commands is to use gt<character> (ie: 'gtc' to jump to the nearest 'c' character) to jump to a specific character. In a recent update, when I press "gt", VSCode changes tab rather than allowing me to complete my vim command. Does anyone know how to disable this behaviour? Is it coming from VSCode or the VIM extension?
In vim gt is used to go to next tab and gT is used to go to previous tab. As vscode vim implements the functionality of vim, you can expect the same behaviour in Vscode if you are using the the vim plugin.
The feature you are looking for can be accomplished by f i.e. to go to next c character press fc.
You can use ; to cycle forward in the direction of the search and , to cyle opposite to direction of the search.
For example, ; goes to next occurrence of same character in the line and , goes to previous occurrence.
Then there is F to go to previous occurrence of a character. Here the direction of search is backwards, therefore ; goes to previous occurrence of same character in the line and , goes to next occurrence.
If you're using VSCodeVim, their GitHub page has examples for things like this. Simply edit your settings.json to remap "g,t" to "f" in normal mode:
"vim.normalModeKeyBindingsNonRecursive": [
{ "before": ["g", "t"], "after": ["f"], },
]
You may or may not want to do the same for "vim.visualModeKeyBindings" if you use it while making selections as well.

How to remap <cr> to go to line number in VSCodeVim

In vim I used to map the enter key <cr> to go to line number instead of the letter G using the following settings
nnoremap <expr> <cr> v:count == 0 ? "\<cr>" : "G"
I tried to achieve the same result in vim for VSCode but I couldn't.
Is there a way that manage me from doing so without enabling the experimental feature neovim integration inside VSCode

Vim Keymap with Multiplicity on VS Code

I have remapped some vim keys in VS Code (using Vim emulation) but I can't manage to use them with multiplicity.
What this means is that when you normally press 3dd it deletes 3 lines. I have keymapped the normal version of the function dd like this
{
"before": ["<Leader>","c","l"],
"after": ["d","d"]
}
but it doesn't work if I press 3-leader-c-l.
How do you keymap keys with that functionality?

Jump to Closing tag in VS Code?

I can't seem to find a way to select the beginning of a bracket and jump to the end of it through some key combination or something in VS Code. For example, in atom, this is done with Ctrl + m.
I know there is a way to jump to the beginning and end of a bracket or curlybraces with Cmd + Shift + \ but that does not work for tags. Any ideas?
It is possible to do, but either using Ctrl + Shift + P -> "Emmet: Go to Matching Pair" or by manually setting a shortcut for it (Ctrl + K Ctrl + S).
Unfortunately there is currently no support for it out of the box.
You can use Cmd + % to jump tags in VSCode if you add the following to your keybindings.json.
{
"key":"cmd+shift+5",
"command": "editor.emmet.action.matchTag"
}
Go to: File > Preferences > Keyboard Shortcuts and click the underlined link to edit keybindings.json.
For those using VIM keys: you are already used to pressing % to jump to matching parens and tags. So, hopefully, Cmd + % will be close enough to your existing muscle memory to make this transition painless.
For those who are using Vim plugin and Mac, Leader+% is working well for me.
You can setup in your Vim json file setting.json by adding:
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["<leader>", "%"],
"commands": [
{
"command": "editor.emmet.action.matchTag"
}
]
}
]
PS. I mentioned Mac user because cmd+shift+5 is for capturing the screen in Mac.
You can jump to the matching bracket with Ctrl+Shift+\
For more reference, you can refer: Visual Studio Code Navigation
I think you are asking about Breadcrumb Keyboard Navigation
In this case you can simply press Ctrl+Shift+. to go to elements before or after the current element.
There is no support for this out of the box. Though if you are willing to use extensions, there is: https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag which among other things, gives you ability to use command: Jump to matching tag which you can bind to a key.