Visual Studio Code

https://code.visualstudio.com/

Key repeating on macOS

On macOS Monterey, fix the key repeating problem:

$ defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false

Input method

Install im-select for vim input method switching, See https://github.com/daipeihust/im-select:

$ curl -Ls https://raw.githubusercontent.com/daipeihust/im-select/master/install_mac.sh | sudo sh
* Downloading im-select...
* im-select is installed!
*
*
*
* now run "im-select" in your terminal!

Download the executable from https://github.com/daipeihust/im-select/raw/refs/heads/master/win/out/x64/im-select.exe, and put it to, e.g. C:\app\im-select\.

Check the installation:

$ which im-select
/usr/local/bin/im-select

Set im-select as the input method switching command in VSCode:

{
  "vim.autoSwitchInputMethod.enable": true,
  "vim.autoSwitchInputMethod.defaultIM": "com.apple.keylayout.ABC",
  "vim.autoSwitchInputMethod.obtainIMCmd": "/usr/local/bin/im-select",
  "vim.autoSwitchInputMethod.switchIMCmd": "/usr/local/bin/im-select {im}"
}
{
  "vim.autoSwitchInputMethod.enable": true,
  "vim.autoSwitchInputMethod.defaultIM": "1033",
  "vim.autoSwitchInputMethod.obtainIMCmd": "C:\\\\app\\\\im-select\\\\im-select.exe",
  "vim.autoSwitchInputMethod.switchIMCmd": "C:\\\\app\\\\im-select\\\\im-select.exe {im}"
}

Don’t forget the double back slashes.

Word wrapping

For chinese characters, the soft wrapping exceeds the max width of view. To fix that, you need to change wrapping strategy from simple to advanced:

{
  "editor.wrappingStrategy": "advanced"
}

Code Formatting

shell

Install shfmt:

By Homebrew:

$ brew install shfmt
$ shfmt --version
3.8.0

Download directly for Intel silicon:

$ curl -LO https://github.com/mvdan/sh/releases/download/v3.11.0/shfmt_v3.11.0_darwin_amd64
$ chmod +x shfmt_v3.11.0_darwin_amd64
$ cp shfmt_v3.11.0_darwin_amd64 /usr/local/bin/shfmt
$ shfmt --version
v3.11.0

Download directly for Apple silicon:

$ curl -LO https://github.com/mvdan/sh/releases/download/v3.13.1/shfmt_v3.13.1_darwin_arm64
$ chmod +x shfmt_v3.13.1_darwin_arm64
$ sudo cp shfmt_v3.13.1_darwin_arm64 /usr/local/bin/shfmt
$ shfmt --version
v3.13.1

Download directly:

$ curl -LO https://github.com/mvdan/sh/releases/download/v3.11.0/shfmt_v3.11.0_linux_amd64
$ chmod +x shfmt_v3.11.0_linux_amd64
$ sudo cp shfmt_v3.11.0_linux_amd64 /usr/local/bin/shfmt
$ shfmt --version
v3.11.0

Configure VSCode to use shfmt for formatting shell scripts:

{
  "shellformat.path": "/usr/local/bin/shfmt"
}

C

Install clangd:

$ sudo apt install clangd
$ clangd --version
Ubuntu clangd version 14.0.0-1ubuntu1.1
Features: linux+grpc
Platform: x86_64-pc-linux-gnu

Install clangd plugin in VSCode, then set:

{
  "clangd.path": "/usr/bin/clangd"
}

clangd need a file compile_commands.json to analyze the sources, which can usually be generated by your build system like CMake. Alternatively, you can generate it use this tool:

$ sudo apt install bear

Run this if there is a Makefile:

bear -- make

If you have a simple project, a compile_flags.txt file can be used to set compile flags mannually.

For ms-vscode.cpptools plugin, the .clang-format file can be put outside the project. You need to set the correct path of this file, for example:

{
  "C_Cpp.clang_format_style": "file:~/workspace/.clang-format"
}

protobuf

Proto Tools use clang-format to format protobuf, so it may be needed, along with protoc:

$ sudo apt install protobuf-compiler
$ protoc --version
libprotoc 3.12.4
$ sudo apt install clang-format
$ clang-format --version
Ubuntu clang-format version 14.0.0-1ubuntu1.1

File Operations Paticipants

Sometimes the participants are doing time-consuming things, halting file operations like creating, renaming and deleting. Measure in ms, set to 0 to disable them.

{
  "files.participants.timeout": 500
}

Install code command

Press Command+Shift+P to open the command panel, then search and execute the following command:

Shell Command: Install 'code' command in PATH

Font ligatures

In Maple fonts, the following words surrounded by brackets are rendered into badges, if font ligature is turned on:

  • [TRACE]

  • [DEBUG]

  • [INFO]

  • [WARN]

  • [ERROR]

  • [FATAL]

  • [TODO]

  • [FIXME]

  • [NOTE]

  • [HACK]

  • [MARK]

  • [EROR]

  • [WARNING]

There are two words with no brackes, but two right parenthesises:

  • todo))

  • fixme))