CheatSheet | VIM


1. Setup vim

  1. Install Vundle

    • git clone [GitHub - VundleVim/Vundle.vim: Vundle, the plug-in manager for Vim](https://github.com/VundleVim/Vundle.vim.git) ~/.vim/bundle/Vundle.vim
  2. color scheme setup

mkdir -p ~/.vim/colors
cd ~/.vim/colors
curl -O https://raw.githubusercontent.com/nanotech/jellybeans.vim/master/colors/jellybeans.vim
  1. write .vimrc

    • wget https://raw.githubusercontent.com/jjeaby/jscript/master/.vimrc

    • Added Plugin 'preservim/nerdcommenter'

  2. install plugins in vimrc

    • :PluginInstall
  3. Shell

# install Vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# setup jellybean color scheme
mkdir -p ~/.vim/colors
cd ~/.vim/colors
curl -O https://raw.githubusercontent.com/nanotech/jellybeans.vim/master/colors/jellybeans.vim
# copy .vimrc
cp ~/configuration/vim/.vimrc ~/.vimrc
vim -c 'PluginInstall' -c 'qa!' 
  1. Reference



2. shortcuts

  • Normal Model

    • Change Mode

      • : : change mode to the CommandMode (before the cursor)

      • i : change mode to the InsertMode (before the cursor)

      • a : change mode to the InsertMode (append)

      • v : change mode to the VisualMode

        • ctrl+v : change mode to VisualBlockMode

        • shift+v : change mode to VisualLineMode

    • Move cursor

      • ^ : move cursor to the front of the line

      • $ : move cursor to the back of the line

      • x : remove character

      • dd : remove line

      • u : undo

  • Insert Mode

    • ESC # shift to command mode
    • ctrl + t : add indent
    • ctrl + d : remove indent
  • Command Mode (: in lastline)

    • :w : save (write on the disk)
    • :q : in command mode, quit
  • Visual Mode (--VISUAL-- in lastline)

    • y : copy in visual mode
    • d : cut in visual mode
    • yy : copy line in visual moed
    • p : paste in visual mode
    • < : indent selected lines
    • > : un-indent selected lines
  • Commands for multiple windows

- :split # split in horizontal
- :vsplit # split in vertical

- ctrl + w + w # move to next window
- ctrl + w + p # move to previous window
  • Fold and Expand
- :set foldmethod=indent # in .vimrc
- zi # toggle folding 


3. Further Techniques

  • 3.1 Comment-Out multiple lines

    • (1) ctrl+v : enter into the VISUAL_BLOCK mode and select lines to comment out
    • (2) shift+i : change editor to INSERT mode and put #
      • this will add a hash to the first line
    • (3) Then press esc , it will insert a # character on all other selected lines
  • 3.2 Coping from vim to clipboard over SSH

    • TBD


9. Plugins

  • NerdTree
:nerd + tab # turn on nerdtree
ctrl+w+w # move focus between editor and file tree
m + a # add a child file