Hacking with Vim

Hacking with

vim

-- Excitedly Presented To YOU By Wayne Ye

The history

  • Vi - Invented By Bill Joy @ 1976
  • Vim - Improved by Bram Moolenaar @ 1991
Amiga-Keyboard

People love it for decades

 

  • "I've been using Vim for 20 years and still learning it."
  • "I can't breath without it!"
  • "Vim rocks!"

The Learning Curve...

learning-curve

Benefit?

  • Type less, do more!!!
  • Mouse-less!!!
  • Ultimate productivity!!!

Showtime!!!

Starting using

vim
Now!

Ultisnips

Plugin address: https://github.com/SirVer/ultisnips

Dragging lines

This trick is accomplished by adding the following lines into vimrc:

" Alt+j/k to move current line/selected lines up and down
nnoremap  :m+==
nnoremap  :m-2==
inoremap  :m+==gi
inoremap  :m-2==gi
vnoremap  :m'>+gv=gv
vnoremap  :m-2gv=gv

Macros

The json conversion I did during the tech session was accomplished by the following key combinations:

  1. gg #Make sure current cursor is at the buffer beginning.
  2. qa # Start recording macros "a"
  3. i # Insert
  4. "
  5. f= #Forward to the char "="
  6. i" # Insert double quote before "="
  7. ESC #Back to normal mode
  8. l #Move to "="
  9. r: #Replace "=" with ":"
  10. a" #Append a double quote after ":"
  11. A", # Append " and , at the end of line
  12. j0 #Move to the beginning of the next line
  13. 28@a #Repeat this operation for 28 times

Learn more: Macros - Vim Tips Wiki

Match & Until

cst # Change surround tag, pretty useful when editing HTML

vit # View in current tag

dit # Delete content in current tag

f$ # Forward to the first occurrence of $ within current line

F$ # Backward to the first occurrence of $ within current line

dt$ # Delete content until matching the first occurrence of $ within current line

vt$ # View (Select) content until matching the first occurrence of $ within current line

Search & Replace

Vim is extremely powerful in dealing with searching and replacing, the trick I've done in the session is just tip of the iceberg, I typed :g/#/d to remove all comments in a Ruby file.

Vimium

This is a awesome Chrome extension, the home page is: https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb?hl=en

My vimrc

http://WayneYe.com/vimrc