Skip to content

Instantly share code, notes, and snippets.

@elsonwu
Last active October 5, 2020 03:31
Show Gist options
  • Save elsonwu/dcec6a316130aeab06080e2b608f0929 to your computer and use it in GitHub Desktop.
Save elsonwu/dcec6a316130aeab06080e2b608f0929 to your computer and use it in GitHub Desktop.
Learn some Vim

Learn some Vim

The goal - 20% of the features covers the 80% daily usage

Why you shoud learn Vim?

  • Basically it's everywhere, only if you're using Unix/Linux/macOS.
    • Edit your confuguration on the servers.
    • Some magic, so many text editors were dead in the history, but it isn't.
  • High efficiency
    • No mouse or trackpad needed.
    • Running fast, but less resource is required.
    • Coding faster, less unnecessary finger movement.

How to learn

  • Why it's so hard to learn
    • Because of it isn't like the normal text editor, it has differnet mode.
    • Everyone has their own setup, but it makes it hard to know why they set it up like that.
  • Focus on what you need only

Show my own setup

Basic

  • Installation, macOS
  • New file, edit, save
  • Movement
  • Copy & paste

Plugins

  • vimrc
  • vim-plug
  • Key bindings
  • Cases study
    • Open folder
    • Open file manager, adding files, deleting files, opening files
    • Switch, close tabs
    • Jump
    • Block selection
    • Unit test
    • Terminal
    • Git pull, git commit, git push

Next

  • Use it, VSCode + Vim

  • vimtutor

  • Useful links

Basic

  • different mode, normal mode, visual mode, insert mode, command mode, :h vim-modes for more detail
  • :q, :q! :wq, :w <file path>

Without plugins

  • movement

    • hjkl
    • gg, G
    • 0, ^, $
    • f, F
    • *
    • /<regex>
    • /\v<regex>
    • :<number>
  • selection

    • v, <ctrl>v, V
    • w, W
    • %
    • vi(, viw, vi", vi'
    • v%
  • selection + paste

    • yyp
  • others

    • u, U
    • J
  • set nu

  • practice

    • search for a setting
    • copy & paste
    • comment out for a setting

With useful plugins

Understand the .vimrc

  • basic setting
  • builtin func all in lowercase, user-defined function must be capital letter
  • :h is our friend
" lsp support
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'ajh17/VimCompletesMe'

" language specific
Plug 'fatih/vim-go', { 'tag': '*' }
Plug 'rust-lang/rust.vim'
Plug 'leafgarland/typescript-vim'

" utils
Plug 'prabirshrestha/asyncomplete-file.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'preservim/nerdtree'
Plug 'itchyny/lightline.vim'
Plug 'mhinz/vim-startify'
Plug 'jiangmiao/auto-pairs'
Plug 'valloric/MatchTagAlways'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'ap/vim-buftabline'
Plug 'qpkorr/vim-bufkill'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-surround'
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }

" color theme
Plug 'romainl/flattened'

" unit test
Plug 'janko/vim-test' 
Plug 'tpope/vim-dispatch'
  • practice

    • Open from a folder - vim . or mvim . or with alfred
    • <leader>wh
    • file creation, rename, update
    • search files by filename, FZF
    • search files' content by keywords, Find
    • show currentn active buffer's path in the menu, <leader>ff
    • easymotion, <leader><leader>s
    • switch window, <ctrl>n, <ctrl>p
    • jump between buffers <ctrl>w+hjkl
    • delete <leader>bw, <ctrl>wq
    • code folding, setting, zf, zo, zc
    • copy & paste
    • replace ' to "
      • with surround
      • for the whole file :%s
      • for the selection only
    • change letter's case, uppercase, lowercase (constant)
    • format with ==, <leader>fmt
    • comment, gc, gcc
    • run unit test
  • set it up from very beginning

VSCode with Vim extension

  • vim-easymotion
  • vim-surround

What's the next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment