# Visual Studio Code
## Key repeating on macOS
On macOS Monterey, fix the key repeating problem:
```console
$ defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false
```
## Input method
Install `im-select` for vim input method switching, See :
::::{tab-set}
:::{tab-item} macOS
:sync: macos
```console
$ 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!
```
:::
:::{tab-item} Windows
:sync: windows
Download the executable from , and put it to, e.g. `C:\app\im-select\`.
:::
::::
Check the installation:
```console
$ which im-select
/usr/local/bin/im-select
```
Set `im-select` as the input method switching command in VSCode:
::::{tab-set}
:::{tab-item} macOS
:sync: macos
```json
{
"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}"
}
```
:::
:::{tab-item} Windows
:sync: windows
```json
{
"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`:
```json
{
"editor.wrappingStrategy": "advanced"
}
```
## Code Formatting
### shell
Install `shfmt`:
::::{tab-set}
:::{tab-item} macOS
:sync: macos
By Homebrew:
```console
$ brew install shfmt
$ shfmt --version
3.8.0
```
Download directly for Intel silicon:
```console
$ 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:
```console
$ 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
```
:::
:::{tab-item} Ubuntu
:sync: ubuntu
Download directly:
```console
$ 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:
```json
{
"shellformat.path": "/usr/local/bin/shfmt"
}
```
### C
Install `clangd`:
::::{tab-set}
:::{tab-item} Ubuntu
:sync: ubuntu
```console
$ sudo apt install clangd
```
```console
$ 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:
```json
{
"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:
::::{tab-set}
:::{tab-item} Ubuntu
:sync: ubuntu
```console
$ sudo apt install bear
```
:::
::::
Run this if there is a `Makefile`:
```sh
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:
```json
{
"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`:
::::{tab-set}
:::{tab-item} Ubuntu
:sync: ubuntu
```console
$ 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.
```json
{
"files.participants.timeout": 500
}
```
## Install code command
Press {kbd}`Command+Shift+P` to open the command panel, then search and execute the following command:
```text
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))