Vim emulation for Visual Studio Code.
VSCodeVim is a Visual Studio Code extension that enables Vim keybindings, including:
c3w
, daw
, 2dd
, etc)jj
to <Esc>
, :
to command panel, etc.)/
and ?
Please report missing features/bugs on GitHub, which will help us get to them faster.
Ask us questions, talk about contributing, or just say hi on Slack!
Make a donation to VSCodeVim here!
Donations help convince me to work on this project rather than my other (non-open-source) projects. I'd love to work on VSCodeVim full time, but I need money to live!
The plugin will be automatically enabled after installing it and reloading VSCode. The plugin can only be disabled from the Extension manager in VSCode, with no quick way to switch between modal and modeless editing.
Just like real vim, your editor will now be in Normal mode, which is reported to VSCode's status bar. From here, all your regular vim commands will work as normal, hooray!
All common Vim commands are supported. For an in-depth look at what Vim features are supported, check out the roadmap. Vimscript isn't supported, so you aren't able to load your .vimrc
or use .vim
plugins. You have to replicated these using our Settings and Emulated plugins.
If key repeating isn't working for you, execute this in your Terminal.
defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false # For VS Code
defaults write com.microsoft.VSCodeInsiders ApplePressAndHoldEnabled -bool false # For VS Code Insider
We also recommend going into System Preferences -> Keyboard and cranking up the Key Repeat and Delay Until Repeat settings to improve your speed.
VSCodeVim will take over your control keys, just like real vim, so you get the full vim experience. This behaviour can be adjusted with the useCtrlKeys
and handleKeys
settings.
Below is an example of a settings.json file for VSCode settings applicable to this extension. Continue on below for more in-depth documentation.
{
"vim.easymotion": true,
"vim.incsearch": true,
"vim.useSystemClipboard": true,
"vim.useCtrlKeys": true,
"vim.hlsearch": true,
"vim.insertModeKeyBindings": [
{
"before": ["j","j"],
"after": ["<Esc>"]
}
],
"vim.otherModesKeyBindingsNonRecursive": [
{
"before": ["<leader>","d"],
"after": ["d", "d"]
},
{
"before":["<C-n>"],
"after":[],
"commands": [
{
"command": ":nohl"
}
]
}
],
"vim.leader": "<space>",
"vim.handleKeys":{
"<C-a>": false,
"<C-f>": false
}
}
The following is a subset of the supported settings; the full list is described in the Contributions
tab for this extension, or in our package.json.
These settings are specific to VSCodeVim.
"vim.startInInsertMode"
"vim.overrideCopy"
true
)"vim.useSystemClipboard"
false
)"vim.searchHighlightColor"
rgba(150, 150, 150, 0.3)
)"vim.useSolidBlockCursor"
We have removed this option, due to it making VSCodeVim's performance suffer immensely.
"vim.substituteGlobalFlag"
gdefault
setting./g
flag in a substitute command replaces all occurrences in the line.
Without this argument, replacement occurs only for the first occurrence in each line."vim.substituteGlobalFlag"
is true
, the 'g' is default on.
This means that all matches in a line are substituted instead of one.
When a 'g' flag is given to a ":substitute" command, this will toggle the substitution
of all or one match."vim.useCtrlKeys"
ctrl+c
, ctrl+[
=> <Esc>
ctrl+f
=> Full Page Forwardctrl+d
=> Half Page Backctrl+b
=> Half Page Forwardctrl+v
=> Visual Block Modetrue
)"vim.handleKeys"
useCtrlKeys
set to true so that other vim bindings work. "vim.handleKeys": {
"<C-a>": false,
"<C-f>": false
}
"vim.visualstar"
false
)We now have neovim integration for Ex-commands. If you want to take advantage of this integration, set "vim.enableNeovim"
to true
, and set your "vim.neovimPath"
. If you don't have neovim installed, install neovim here. If you don't want to install neovim, all of the old functionality should still work as is (we would really suggest neovim installing though. The new Ex support is super cool, and we'd like to integrate neovim more in the future).
Please leave feedback on neovim here.
Here's some ideas on what you can do with your newfound neovim integration!
There's several different settings you can use to define custom remappings. Also related are the useCtrlKeys
and handleKeys
settings.
"vim.insertModeKeyBindings"
/"vim.otherModesKeyBindings"
Bind jj
to <Esc>
in insert mode:
"vim.insertModeKeyBindings": [
{
"before": ["j", "j"],
"after": ["<Esc>"]
}
]
Bind :
to show the command palette:
"vim.otherModesKeyBindingsNonRecursive": [
{
"before": [":"],
"after": [],
"commands": [
{
"command": "workbench.action.showCommands",
"args": []
}
]
}
]
Bind ZZ
to save and close the current file:
"vim.otherModesKeyBindingsNonRecursive": [
{
"before": ["Z", "Z"],
"after": [],
"commands": [
{
"command": "workbench.action.files.save",
"args": []
},
{
"command": "workbench.action.closeActiveEditor",
"args": []
}
]
}
]
Or bind ctrl+n to turn off search highlighting and <leader>w
to save the current file:
"vim.otherModesKeyBindingsNonRecursive": [
{
"before":["<C-n>"],
"after":[],
"commands": [
{
"command": ":nohl",
"args": []
}
]
},
{
"before": ["leader", "w"],
"after": [],
"commands": [
{
"command": "workbench.action.files.save",
"args": []
}
]
}
]
"vim.insertModeKeyBindingsNonRecursive"
/"otherModesKeyBindingsNonRecursive"
:noremap
)j
to gj
. Notice that if you attempted this binding normally, the j in gj would be expanded into gj, on and on forever. Stop this recursive expansion using insertModeKeyBindingsNonRecursive and/or otherModesKeyBindingNonRecursive. `"vim.otherModesKeyBindingsNonRecursive": [
{
"before": ["j"],
"after": ["g", "j"]
}
]
Almost like vim-airline in VSCode!
"vim.statusBarColorControl"
false
)Once this is set, you need to set "vim.statusBarColors"
as well with these exact strings for modenames. The colors can be adjusted to suit the user.
"vim.statusBarColorControl": true,
"vim.statusBarColors" : {
"normal": "#005f5f",
"insert": "#5f0000",
"visual": "#5f00af",
"visualline": "#005f87",
"visualblock": "#86592d",
"replace": "#000000"
}
Configuration settings that have been copied from vim.
Vim settings are loaded in the following sequence:
:set {setting}
vim.{setting}
from user/workspace settings."vim.ignorecase"
true
)"vim.smartcase"
true
)"vim.hlsearch"
false
)"vim.incsearch"
true
)"vim.autoindent"
true
)"vim.timeout"
1000
)"vim.showcmd"
true
)"vim.textwidth"
gq
.80
)"vim.leader"
<leader>
map to in key remappings?\
)⚡ Multi-Cursor mode is currently in beta. Please report things you expected to work but didn't to our feedback thread.
You can enter multi-cursor mode by:
gb
, a new shortcut we added which is equivalent to cmd-d on OSX or ctrl-d on Windows. (It adds another cursor at the next word that matches the word the cursor is currently on.)Now that you have multiple cursors, you should be able to use Vim commands as you see fit. Most of them should work. There is a list of things I know of which don't here. If you find yourself wanting one of these, please add it to our feedback thread.
Each cursor has its own clipboard.
Pressing Escape in Multi-Cursor Visual Mode will bring you to Multi-Cursor Normal mode. Pressing it again will return you to Normal mode.
Easymotion is based on vim-easymotion. To activate easymotion, you need to make sure that easymotion
is set to true
in settings.json (as the default is false
).
Once easymotion is active, you can initiate motions using the following commands. After you initiate the motion, text decorators/markers will be displayed and you can press the keys displayed to jump to that position. leader
is configurable and is \
by default.
Motion Command | Description |
---|---|
<leader> <leader> s <char> |
Search character |
<leader> <leader> f <char> |
Find character forwards |
<leader> <leader> F <char> |
Find character backwards |
<leader> <leader> t <char> |
Til character forwards |
<leader> <leader> T <char> |
Til character backwards |
<leader> <leader> w |
Start of word forwards |
<leader> <leader> b |
Start of word backwards |
<leader> <leader> e |
End of word forwards |
<leader> <leader> g e |
End of word backwards |
You can customize the appearance of your easymotion markers (the boxes with letters) using the following settings:
Setting | Description |
---|---|
vim.easymotionMarkerBackgroundColor |
The background color of the marker box. |
vim.easymotionMarkerForegroundColorOneChar |
The font color for one-character markers. |
vim.easymotionMarkerForegroundColorTwoChar |
The font color for two-character markers, used to differentiate from one-character markers. |
vim.easymotionMarkerWidthPerChar |
The width in pixels allotted to each character. |
vim.easymotionMarkerHeight |
The height of the marker. |
vim.easymotionMarkerFontFamily |
The font family used for the marker text. |
vim.easymotionMarkerFontSize |
The font size used for the marker text. |
vim.easymotionMarkerFontWeight |
The font weight used for the marker text. |
vim.easymotionMarkerYOffset |
The distance between the top of the marker and the text (will typically need some adjusting if height or font size have been changed). |
Surround plugin based on tpope's surround.vim plugin is used to work with surrounding characters like parenthesis, brackets, quotes, and XML tags.
t
or <
as <desired char>
or <existing char>
will do tags and enter tag entry mode.
Surround can be disabled by setting vim.surround : false
Surround Command | Description |
---|---|
d s <existing char> |
Delete existing surround |
c s <existing char> <desired char> |
Change surround existing to desired |
y s <motion> <desired char> |
Surround something with something using motion (as in "you surround") |
S <desired char> |
Surround when in visual modes (surrounds full selection) |
Some examples:
"test"
with cursor inside quotes type cs"' to end up with 'test'
"test"
with cursor inside quotes type ds" to end up with test
"test"
with cursor inside quotes type cs"t and enter 123> to end up with <123>test</123>
test
with cursor on word test type ysaw) to end up with (test)
Commentary in VSCodeVim works similarly to tpope's vim-commentary but uses the VSCode native "Toggle Line Comment" and "Toggle Block Comment" features.
Usage examples:
gc
- toggles line comment. For example gcc
to toggle line comment for current line and gc2j
to toggle line comments for the current line and the next line.gC
- toggles block comment. For example gCi)
to comment out everything within parenthesis.Indent Objects in VSCodeVim are identical to michaeljsmith/vim-indent-object and allow you to treat blocks of code at the current indentation level as text objects. This is very useful in languages that don't use braces around statements, like Python.
Provided there is a new line between the opening and closing braces / tag, it can be considered an agnostic cib
/ci{
/ci[
/cit
.
Command | Description |
---|---|
<operator>ii |
This indentation level |
<operator>ai |
This indentation level and the line above (think if statements in Python) |
<operator>aI |
This indentation level, the line above, and the line after (think if statements in C/C++/Java/etc) |
Awesome Features You Might Not Know About
Vim has a lot of nooks and crannies. VSCodeVim preserves some of the coolest nooks and crannies of Vim. And then we add some of our own! Some of our favorite include:
gd
- jump to definition. Astoundingly useful in any language that VSCode provides definition support for. I use this one probably hundreds of times a day.gq
- on a visual selection - Reflow and wordwrap blocks of text, preserving commenting style. Great for formatting documentation comments.gb
- which adds another cursor on the next word it finds which is the same as the word under the cursor.af
- a command that I added in visual mode, which selects increasingly large blocks of text. e.g. if you had "blah (foo [bar 'ba|z'])" then it would select 'baz' first. If you pressed af
again, it'd then select [bar 'baz'], and if you did it a third time it would select "(foo [bar 'baz'])".gh
- another custom VSCodeVim command. This one is equivalent to hovering your mouse over wherever the cursor is. Handy for seeing types and error messages without reaching for the mouse!(The mnemonic: selecting blocks is fast af!
ctrl
(e.g. ctrl+f
, ctrl+v
) commands workSet the useCtrlKeys
setting to true
.
You can try setting vim.foldfix
to true
. Note, however, that it is a hack. It works fine, but there are side effects. We are unable to fix this issue properly due to VSCode API limitations. Go to here for updates on the issue.
Take a look here.
<esc>
! Or I'm in a snippet and I want to close intellisense!Press shift+<esc>
to close all of those boxes.
This project is maintained by a group of awesome people and contributions are extremely welcome
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。