8000 GitHub - yaolindlut/Vim: :star: Vim for Visual Studio Code
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

yaolindlut/Vim

 
 

Repository files navigation


VSCodeVim

Vim emulation for Visual Studio Code

http://aka.ms/vscodevim https://travis-ci.org/VSCodeVim/Vim

VSCodeVim is a Visual Studio Code extension that enables:

  • Keybindings and command combinations (c3w, daw, 2dd, etc)
  • Modes: normal, insert, command-line, visual, visual line, visual block
  • Command remapping (jj to <Esc>, : to command panel, etc.)
  • Incremental search with / and ?
  • Marks
  • Popular vim plugin features built-in (easymotion, surround, commentary)
  • Multi-cursor support, run vim commands everywhere!
  • Refer to our roadmap for a full list

Please report missing features/bugs on GitHub and join us on Slack.

Contents

Getting started

VSCodeVim is automatically enabled following installation and the reloading of VSCode.

Vim compatibility

All common Vim commands are supported. For a detailed list of supported features, refer to our roadmap. Vimscript is not supported, so you aren't able to load your .vimrc or use .vim plugins. You have to replicate these using our Settings and Emulated plugins.

Mac setup

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 increasing the Key Repeat and Delay Until Repeat settings to improve your speed.

Windows setup

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.

Settings

Quick example settings

Below is an example of a settings.json file for VSCode settings applicable to this extension.

{
    "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 in the extensions menu of VSCode.

VSCodeVim settings

These settings are specific to VSCodeVim.

"vim.startInInsertMode"

  • Have VSCodeVim start in Insert Mode rather than Normal Mode.
  • We would be remiss in our duties as Vim users not to say that you should really be staying in Normal mode as much as you can, but hey, who are we to stop you?

"vim.overrideCopy"

  • Override VSCode's copy command with our own, which works correctly with VSCodeVim.
  • If cmd-c or ctrl-c is giving you issues, set this to false and complain here.
  • Type: Boolean (Default: true)

"vim.useSystemClipboard"

  • Enable yanking to the system clipboard by default
  • Type: Boolean (Default: false)

"vim.searchHighlightColor"

  • Set the color of search highlights.
  • Type: Color String (Default: rgba(150, 150, 150, 0.3))

"vim.substituteGlobalFlag"

  • Similar to Vim's 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.
  • When "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"

  • Enable Vim ctrl keys thus overriding common VSCode operations such as copy, paste, find, etc. Enabling this setting will result in the following keybindings:
    • ctrl+c, ctrl+[ => <Esc>
    • ctrl+f => Full Page Forward
    • ctrl+d => Half Page Back
    • ctrl+b => Half Page Forward
    • ctrl+v => Visual Block Mode
    • etc.
  • Type: Boolean (Default: true)

"vim.cmdLineInitialColon"

  • Set this to have VSCodeVim mimick Vim, showing the ':' colon character in the Vim command line when it is called.
  • Type: Boolean (Default: false)

"vim.handleKeys"

  • Delegate certain keybindings to be handled natively by VSCode instead of by the VSCodeVim extension
  • Complete list of key combinations supported by this setting can be found under the keybindings section of our package.json. Each key that has a vim.use<C-...> in the when argument can be delegated back to vscode by setting "<C-...>": false.
  • Example: user wants to use ctrl+f for find (native VSCode behaviour), but wants to have useCtrlKeys set to true so that other vim bindings work:
    "vim.handleKeys": {
        "<C-a>": false,
        "<C-f>": false
    }

"vim.visualstar"

  • In visual mode, start a search with * or # using the current selection
  • Type: Boolean (Default: false)

"vim.cursorStylePerMode"

  • Configure a specific cursor style per mode; omitted modes will use default cursor type
  • Supported modes: normal, insert, replace, visual, visualline, and visualblock
  • Supported cursors: line, block, underline, line-thin, block-outline, and underline-thin
    "vim.cursorStylePerMode" : {
        "normal": "underline",
        "insert": "line-thin",
        "replace": "block-outline"
    }

"vim.disableExtension"

  • Disable VSCodeVim (Note: this is different from disabling extension through VSCode)
  • This setting can be changed through the settings or via toggleVim command in the Command Palette
  • Type: Boolean (Default: false)

Neovim Integration

⚠️ Experimental feature. Please leave feedback on neovim integration here.

We now have neovim integration for Ex-commands. To enable,

  1. install neovim
  2. add the following configurations:
"vim.enableNeovim": true
"vim.neovimPath": <path to neovim>

Here's some ideas on what you can do with neovim integration:

Key remapping

There's several different mechanisms you can use to define custom remappings. Also see the useCtrlKeys and handleKeys settings.

"vim.insertModeKeyBindings"/"vim.otherModesKeyBindings"

  • Keybinding overrides to use for insert and other (non-insert) modes.
  • 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": []
                }
            ]
        }
    ]
  • 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"

  • Non-recursive keybinding overrides to use for insert and other (non-insert) modes (similar to :noremap)
  • Example: Bind 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"]
        }
    ]

Status bar color settings

Almost like vim-airline in VSCode!

"vim.statusBarColorControl"

⚠️ Experimental feature. Due to VSCode API limitations, this function modifies settings.json in the workspace resulting in latency and a constant changing diff in your working directory (see issue#2124).

  • Control status bar color based on current mode
  • Type: Boolean (Default: false)

Once enabled, configure "vim.statusBarColors".

    "vim.statusBarColorControl": true,
    "vim.statusBarColors" : {
        "normal": "#005f5f",
        "insert": "#5f0000",
        "visual": "#5f00af",
        "visualline": "#005f87",
        "visualblock": "#86592d",
        "replace": "#000000"
    }

Vim settings