1: posts
Reading ModeRO
$ cat 20200712_vsvim02.md

#A Vim user’s guide to VS Code, part 2

Date:2020-07-12 (Sun)
>Adding extensions, configuring editor behavior, and mapping keys for a Vim-oriented VS Code setup.

This is the second part of my VS Code setup for Vim users.
This time I’m focusing on switching tabs and moving between the editor, sidebar, and terminal.

##In this article

  • Adding extensions
  • Editing settings.json

##Adding extensions

I’ve kept experimenting since the first post and added a few extensions that looked useful.
I want to introduce that first.

An extension to open pdf files in VSCode.
That's about it, but it's still pretty handy.

An extension that enables path completion.
But, there are sometimes when it doesn't work properly.
Is there some setting for that...?

A stylish extension to beautify the file tree icons in the sidebar.
That's important though, the appearance matters.

An extension that shows indentation with colors.
It's convenient that in languages where indentation is important, such as Python, the indentation automatically becomes the scope of the for loop, making it easier to understand.
It seems like it will be tough if I don't get used to this.

An extension that displays pairs of parentheses in the same color.
With languages like Go, parentheses often become nested structures with many parentheses, so it's convenient for them to be visualized.

Introduced as a visualization extension together with the aforementioned two.
It's limited to CSV, but it's a convenient extension that displays items in the same column in the same color.
With this, you can confirm things much more easily without opening Excel or similar programs.

There are other extensions that can be installed, but since they are only for specific file formats, I will introduce them separately.

##Editing settings.json

So, continuing from the previous time, we will add more settings to settings.json.
This time, we will explain the content of each item, and we will show the entire JSON file at the end.

###Vim settings

  • "vim.surround": true,

I discovered that vim-surround can be used with just this setting.
This walkthrough shows how to use it.

  • "vim.highlightedyank.enable": true,
  • "vim.highlightedyank.color": "rgba(100, 170, 240, 0.5)",
  • "vim.highlightedyank.duration": 150,

A setting to highlight text momentarily when copying.
Turn ON with true in the first line, specify the color in the second line, and specify the highlight time in the third line.
I've chosen a color that sort of blends with the Iceburg theme.

  • "vim.whichwrap": "h,l,<,>,[,]"

A setting for moving across lines when moving the cursor left or right.
"h,l" for moving with the h and l keys, "<,>" for moving with the arrow keys (Normal mode), "[,]" for moving with the arrow keys (Insert mode).

  • "vim.statusBarColorControl": true,

Enable the setting to customize the status bar color.
The colors themselves are set to something like an Iceburg look.

JSON
{
  "vim.statusBarColors.normal": ["#161821", "#818596"],
  "vim.statusBarColors.insert": ["#84A0C6", "#161821"],
  "vim.statusBarColors.visual": ["#B4BE82", "#161821"],
  "vim.statusBarColors.visualline": ["#B4BE82", "#161821"],
  "vim.statusBarColors.visualblock": ["#B4BE82", "#161821"],
  "vim.statusBarColors.replace": ["#E2A478", "#161821"],
  "vim.statusBarColors.commandlineinprogress": ["#818596", "#161821"],
  "vim.statusBarColors.searchinprogressmode": ["#818596", "#161821"],
  "vim.statusBarColors.easymotionmode": ["#818596", "#161821"],
  "vim.statusBarColors.easymotioninputmode": ["#818596", "#161821"],
  "vim.statusBarColors.surroundinputmode": ["#818596", "#161821"]
}

With just this setting, the colors don't switch smoothly.
Therefore, you will need to tweak the Iceburg theme files.
Open the JSON files in the following folder.

~/.vscode/⁨extensions⁩/⁨cocopon.iceberg-theme-1.1.0/themes/icebarg.color-theme.json

Comment out these three lines:

  • "statusBar.debuggingForeground": "#6b7089",
  • "statusBar.foreground": "#6b7089",
  • "statusBar.noFolderForeground": "#6b7089",

###Normal mode keybindings

JSON
{
  "before": ["<Enter>"],
  "commands": ["editor.action.insertLineAfter"]
}

Set it so that the Enter key can insert a newline in Normal mode.
It's handy to be able to use it somewhat.

###Visual mode keybindings

JSON
{
    "before": [
        "<Leader>",
        "j"
    ],
    "after": [
        "<Esc>"
    ]
},

I'm a bit puzzled about the keybinding.
Since the Esc key to switch from Visual mode to Normal mode is far away, I tried this keybinding.
When switching from Insert mode to Normal mode, I use jj, but actually, maybe it's better to use \<Leader\>+j for that too.
However, since I've been using jj in NeoVim so far, it's quite difficult to transition...
Let me think about it for a bit.

###Choosing a theme

  • "workbench.iconTheme": "material-icon-theme",

When you install the Material Icon Theme, it comes with certain settings enabled by default.

So far, the settings.json has been as follows.

JSON
{
  "editor.minimap.enabled": false,
  "editor.renderWhitespace": "all",
  "files.trimTrailingWhitespace": true,
  "vim.leader": "<space>",
  "vim.useSystemClipboard": true,
  "vim.useCtrlKeys": true,
  "vim.easymotion": true,
  "vim.surround": true,
  "vim.visualstar": true,
  "vim.hlsearch": true,
  "vim.highlightedyank.enable": true,
  "vim.highlightedyank.color": "rgba(100, 170, 240, 0.5)",
  "vim.highlightedyank.duration": 150,
  "vim.whichwrap": "h,l,<,>,[,]",
  "vim.statusBarColorControl": true,
  "vim.statusBarColors.normal": ["#161821", "#818596"],
  "vim.statusBarColors.insert": ["#84A0C6", "#161821"],
  "vim.statusBarColors.visual": ["#B4BE82", "#161821"],
  "vim.statusBarColors.visualline": ["#B4BE82", "#161821"],
  "vim.statusBarColors.visualblock": ["#B4BE82", "#161821"],
  "vim.statusBarColors.replace": ["#E2A478", "#161821"],
  "vim.statusBarColors.commandlineinprogress": ["#818596", "#161821"],
  "vim.statusBarColors.searchinprogressmode": ["#818596", "#161821"],
  "vim.statusBarColors.easymotionmode": ["#818596", "#161821"],
  "vim.statusBarColors.easymotioninputmode": ["#818596", "#161821"],
  "vim.statusBarColors.surroundinputmode": ["#818596", "#161821"],
  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before": ["u"],
      "commands": [
        {
          "command": "undo"
        }
      ]
    },
    {
      "before": ["<C-r>"],
      "commands": [
        {
          "command": "redo"
        }
      ]
    },
    {
      "before": ["x"],
      "after": ["\"", "_", "x"]
    },
    {
      "before": ["s"],
      "after": ["\"", "_", "s"]
    },
    {
      "before": ["j"],
      "after": ["g", "j"]
    },
    {
      "before": ["k"],
      "after": ["g", "k"]
    },
    {
      "before": ["n"],
      "after": ["n", "z", "z"]
    },
    {
      "before": ["N"],
      "after": ["N", "z", "z"]
    },
    {
      "before": ["*"],
      "after": ["*", "z", "z"]
    },
    {
      "before": ["#"],
      "after": ["#", "z", "z"]
    },
    {
      "before": ["<Enter>"],
      "commands": ["editor.action.insertLineAfter"]
    },
    {
      "before": ["<Leader>", "c"],
      "commands": [
        {
          "command": "editor.action.commentLine"
        }
      ]
    },
    {
      "before": ["<Leader>", "w"],
      "after": [],
      "commands": [
        {
          "command": "workbench.action.files.save",
          "args": []
        }
      ]
    },
    {
      "before": ["<Leader>", "q"],
      "after": [],
      "commands": [
        {
          "command": "workbench.action.closeActiveEditor",
          "args": []
        }
      ]
    },
    {
      "before": ["<Leader>", "x"],
      "after": [],
      "commands": [
        {
          "command": "editor.action.formatDocument",
          "args": []
        }
      ]
    },
    {
      "before": ["<Leader>", "l"],
      "after": ["$"]
    },
    {
      "before": ["<Leader>", "h"],
      "after": ["^"]
    },
    {
      "before": ["<Leader>", "m"],
      "after": ["%"]
    },
    {
      "before": ["<Leader>", "z"],
      "commands": [":noh"]
    }
  ],
  "vim.insertModeKeyBindingsNonRecursive": [
    {
      "before": ["j", "j"],
      "after": ["<Esc>"]
    },
    {
      "before": [";", ";"],
      "commands": ["editor.action.triggerSuggest"]
    }
  ],
  "vim.visualModeKeyBindingsNonRecursive": [
    {
      "before": ["<Leader>", "j"],
      "after": ["<Esc>"]
    },
    {
      "before": ["<Leader>", "l"],
      "after": ["$"]
    },
    {
      "before": ["<Leader>", "h"],
      "after": ["^"]
    },
    {
      "before": ["<Leader>", "m"],
      "after": ["%"]
    },
    {
      "before": [">"],
      "commands": ["editor.action.indentLines"]
    },
    {
      "before": ["<"],
      "commands": ["editor.action.outdentLines"]
    }
  ],
  "workbench.colorTheme": "Iceberg",
  "workbench.iconTheme": "material-icon-theme"
}

##Editing keybindings.json

Next, we will go through the settings for keybindings.json.
Here, we will register shortcuts other than the editor on VSCode.

JSON
{
    "key": "ctrl+h",
    "command": "workbench.action.previousEditor"
}

{
    "key": "ctrl+l",
    "command": "workbench.action.nextEditor"
}

Setting to move to the adjacent tab.
Press ctrl+h to move left, ctrl+l to move right.

JSON
{
    "key": "ctrl+j",
    "command": "selectNextSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
}

{
    "key": "ctrl+k",
    "command": "selectPrevSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
}

{
    "key": "ctrl+j",
    "command": "workbench.action.quickOpenSelectNext",
    "when": "inQuickOpen",
}

{
    "key": "ctrl+k",
    "command": "workbench.action.quickOpenSelectPrevious",
    "when": "inQuickOpen ",
}

Settings to move the command palette and supplementary items up and down using ctrl+j and ctrl+k.
A setting that is essential for operating using just a keyboard.

JSON
{
    "key": "ctrl+t",
    "command": "workbench.action.terminal.toggleTerminal",
    "when": "editorTextFocus"
}

{
    "key": "ctrl+t",
    "command": "workbench.action.focusActiveEditorGroup",
    "when": "terminalFocus"
}

Commands for switching between editor screen and terminal screen.
They are frequently used when programming.

That's it for now.
Here’s my current keybindings.json:

JSON
[
  {
    "key": "ctrl+h",
    "command": "workbench.action.previousEditor"
  },
  {
    "key": "ctrl+l",
    "command": "workbench.action.nextEditor"
  },
  {
    "key": "ctrl+j",
    "command": "selectNextSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+k",
    "command": "selectPrevSuggestion",
    "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
  },
  {
    "key": "ctrl+j",
    "command": "workbench.action.quickOpenSelectNext",
    "when": "inQuickOpen"
  },
  {
    "key": "ctrl+k",
    "command": "workbench.action.quickOpenSelectPrevious",
    "when": "inQuickOpen "
  },
  {
    "key": "ctrl+t",
    "command": "workbench.action.terminal.toggleTerminal",
    "when": "editorTextFocus"
  },
  {
    "key": "ctrl+t",
    "command": "workbench.action.focusActiveEditorGroup",
    "when": "terminalFocus"
  }
]

##Wrapping up

I’m still figuring out how to make good use of the sidebar, so I’ve left that for another time.
I’ll keep experimenting and share any bindings or workflows that prove useful.

## Comments

"20200712_vsvim02.md" [readonly]2L, 12097B
utf-8100%