Skip to content

Vim Config

Song Zheng edited this page Oct 7, 2022 · 37 revisions

Intro

Vim config

SYSTEM INFO

  • For OSX users:
    • Make sure you are using iterm2. This terminal supports true colors, which renders the UI more clearly and is better for your eyes. The default mac terminal does not support true colors.
  • Make sure you are using vim version > 8.2. You should see vim version when you open vim. If not, you need to upgrade:
    • sudo add-apt-repository ppa:jonathonf/vim
    • sudo apt update
    • sudo apt install vim
  • Make sure you have the following programs installed:
    • ripgrep - used for fast searching
      • Method 1: sudo apt-get install ripgrep - This installs rg for all users (YAY!)
        • Run lsb_release -a to see what ubuntu version you are on.
      • Method 2: Should install rust first to get the lastest version of ripgrep via cargo install ripgrep
        • Also needs sudo apt install build-essential to avoid linker cc errors during installation.
        • This only installs rg in your userspace, so no other users will have this command.
  • Install NodeJS.
  • Install bat for fzf preview with syntax highlighting. cargo install --locked bat

Steps

  1. Install vim plug
  2. Open ~/.vimrc file. Set paste mode :set paste
  3. Copy / paste our vimrc config into your ~/.vimrc file.
  4. Save :w
  5. Reload your new configs by running :source ~/.vimrc (alternatively, close and reopen vim)
  6. Run :PlugInstall
  7. Run :CocInstall coc-tsserver coc-json coc-html coc-css
  8. Run :CocInstall coc-eslint coc-prettier
  9. Copy the config below to ~/.vim/coc-settings.json
  10. Close vim and reopen!

Post-setup

  1. Add export FZF_DEFAULT_COMMAND="rg --files --hidden" to ~/.bashrc or ~/.zshrc depending on which shell you are using (echo $0 will tell you).
    You want to configure fzf to use ripgrep so it automatically follows your .gitignore files.

Important Disclaimers

  • leader key is set to , and only usable in normal mode.
  • Jumping between windows - No need a CTRL-w prefix. Just CTRL-h to go to left window, jkl for the other directions.
  • There are no swp files. Make sure you commit your code frequently (as you should be doing)

Common usage

  • Emmet Plugin
    • Type h1. To autocomplete the tag, type ctrl-Y, (control y and then ,).
  • ctrl-p to open up file search to navigate between files quickly
    • ctrl-v to vertical split the search result
  • :Gwrite to commit the current file.
  • ,1 to refresh your vimrc and install plugin. No need to open and close!

~/.vim/coc-settings.json

{
  "coc.preferences.formatOnSaveFiletypes": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "tsserver.formatOnType": true,
  "coc.preferences.formatOnType": true,
  "javascript.validate.enable": false
}

Learnings

System Setup

Tutorials

Clone this wiki locally