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

  • Insert Mode

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

    • i : change mode to the InsertMode (before the cursor)
    • a : change mode to the InsertMode (append)
    • v : change mode to the VisualMode
    • ^ : move cursor to the front of the line
    • $ : move cursor to the back of the line
    • x : remove character
    • dd : remove line
    • u : undo
    • :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
- zi # toggle folding 


3. Plugins

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