introduction to vim
DESCRIPTION
TRANSCRIPT
Vim - The Hacker’s Editor
Vysakh Sreenivasan
vysakh.quora.comvysakh0 - twitter/facebook
April 29, 2013
Vim
Table of Contents
1 VimHistoryVi BasicsAdvancedPluginsResources and Links
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 2 / 35
Vim
Billion Dollar Editor
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 3 / 35
Vim
What is the big deal?
Vi, that got its start in 1976.- Grand Daddy!Moving: if IDEs walk, vim swingsDefault in most OSesIncreases Productivity!!Most Hackers use!The last editor you would use!
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 4 / 35
Vim
What is the big deal?
Vi, that got its start in 1976.- Grand Daddy!Moving: if IDEs walk, vim swingsDefault in most OSesIncreases Productivity!!Most Hackers use!The last editor you would use!
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 4 / 35
Vim
What is the big deal?
Vi, that got its start in 1976.- Grand Daddy!Moving: if IDEs walk, vim swingsDefault in most OSesIncreases Productivity!!Most Hackers use!The last editor you would use!
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 4 / 35
Vim
What is the big deal?
Vi, that got its start in 1976.- Grand Daddy!Moving: if IDEs walk, vim swingsDefault in most OSesIncreases Productivity!!Most Hackers use!The last editor you would use!
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 4 / 35
Vim
What is the big deal?
Vi, that got its start in 1976.- Grand Daddy!Moving: if IDEs walk, vim swingsDefault in most OSesIncreases Productivity!!Most Hackers use!The last editor you would use!
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 4 / 35
Vim
What is the big deal?
Vi, that got its start in 1976.- Grand Daddy!Moving: if IDEs walk, vim swingsDefault in most OSesIncreases Productivity!!Most Hackers use!The last editor you would use!
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 4 / 35
Vim
How do Vim users feel :)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 5 / 35
Vim History
Line and Screen Editors
History of Text editors in a nutshell
Basic Line editor - Ed editor - made by Ken Thompson
Advanced line editor Ex editor
Screen Editor - you could see stuff while editing :) Vi
An improved Vi - Vim
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
Vim History
Line and Screen Editors
History of Text editors in a nutshell
Basic Line editor - Ed editor - made by Ken Thompson
Advanced line editor Ex editor
Screen Editor - you could see stuff while editing :) Vi
An improved Vi - Vim
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
Vim History
Line and Screen Editors
History of Text editors in a nutshell
Basic Line editor - Ed editor - made by Ken Thompson
Advanced line editor Ex editor
Screen Editor - you could see stuff while editing :) Vi
An improved Vi - Vim
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
Vim History
Line and Screen Editors
History of Text editors in a nutshell
Basic Line editor - Ed editor - made by Ken Thompson
Advanced line editor Ex editor
Screen Editor - you could see stuff while editing :) Vi
An improved Vi - Vim
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
Vim History
Line and Screen Editors
History of Text editors in a nutshell
Basic Line editor - Ed editor - made by Ken Thompson
Advanced line editor Ex editor
Screen Editor - you could see stuff while editing :) Vi
An improved Vi - Vim
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
Vim Vi Basics
Fire up Vim
vim filenameOpens up vim with a filename.
:w - to save:q - to quit:wq or :x - to save and quit:q! - to quit without saving.:e filename - to open another file:r filename - to read content from one file into current file
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 7 / 35
Vim Vi Basics
Modes
Insert - Only for typing!!!i to insert in the cursor positionI to insert in the beginning of linea to append after cursor positionA to append at the end of the lineo to insert a new line belowO to insert a new line above
Command - delete/copy/paste/movement/..Ctrl + C or Ctrl+ [ or esc
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 8 / 35
Vim Vi Basics
Modes contd..
Ex mode - Similar to ex editor
:wq - begins with a colon, followed by commands.:g/re/p - grep was inspired from ex editor. This prints the lines whichhas ”re”
Visual - For Selectionv Selects charactersV Selects rows/lines
Ctrl+v Selects block/column
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 9 / 35
Vim Vi Basics
Panes
ctrl+w+s or :sp - split horizontallyctrl+w+v or :vsp - split verticallyctrl+w+w - move next pane
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 10 / 35
Vim Vi Basics
Tabs
:tabe filename To open a file in a new tabgt To move to next tab
gT To move to prev tab
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 11 / 35
Vim Vi Basics
Movements
j - points downwards!k - the straight k line points upwards
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 12 / 35
Vim Vi Basics
More on Movements..
gg - go to first lineG - go to last line4G - go to 4th line{ and } movements to the beginning or end of the paragraphrespectively.( and ) to beginning or end of the sentence.
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 13 / 35
Vim Vi Basics
More on Movements..
w - go to the beginning of next worde - go to the end of the next wordb - go the beginning of the previous word0 - go to the beginning of the line$ - go to the end of the line
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 14 / 35
Vim Vi Basics
Copy/Delete/Paste
y - yank/copyies, yy - copies the line, yw - copies the wordd - deletes, dd - deletes the line, dw - deletes the wordc - change, cc deletes the line and go to insert modep - paste the copied/deleted textx - delete character under the cursorX - delete character before the cursor
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 15 / 35
Vim Vi Basics
Combination of keys
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 16 / 35
Vim Vi Basics
Combination of keys
10p - paste ten times.d$ - delete till the end of the line4yw - copy four wordsggdG - deletes the entire file (goes to first line (gg), starts deleting(d) till the last line G)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 17 / 35
Vim Vi Basics
More on key combo
diw - delete the word where the cursor is in. dw - deletes letters fromcursor till next word.ciw - changes the word where cursor is in.di’ d“ di{ di( di[ replaces words inside ’ ” { ( [
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 18 / 35
Vim Vi Basics
Search, Replace
Search /searchwordSearch current word *Search and Replace :%s/search/replace/g
% - every lines (without that, only current line)s - substituteg - replace all occurences (without that, only firstoccurence)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 19 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
Play around with ex editor/ex mode
ex filename (will open the file)i (to insert words). (in the next line will end inserting)p (to print current line)%p (to print all lines)a (to append at the bottom). (full stop in next will end appending)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 20 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
t$ (copy current line to the end of the file)1,3m5 (move 1-3 lines after 5th line)c (to change the current line)w (to write/save changes)wq (to save and quit)q (to quit)e filename (to edit the file)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 21 / 35
Vim Vi Basics
tip
Ctrl+win insert mode will backspace the word you are typing. Also works in shell.
JCapital j will join two lines.
gfIf the cursor is on a word sample, the command gf would open the filesample if it is present in current directory
giGo back to the place where you are editing. Handy command when youare in the middle of your typing and go to command mode to fix issues.
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 22 / 35
Vim Advanced
Omni complete
Ctrl + n or Ctrl + p (in insert mode, handy when calling functions)Ctrl + x + k - dictionary completionCtrl + x + f - file name autocompletion
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 23 / 35
Vim Advanced
Macros
Records set of actions - qm or qa or qb (begin with q)To repeat the recorded macro - @m or @a or @b (begin with @followed by the letter)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 24 / 35
Vim Advanced
Marks
Mark your position in the file - ml or mb or mq (begin with m)Go to the marked position - ’l or ’b or ’q (begin with ’ followed bycorresponding letter)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 25 / 35
Vim Advanced
Jumps
Ctrl + o - to go the previous position in your files.ctrl + i - to go to the next position in your files.:jumps - to see all the jumps
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 26 / 35
Vim Advanced
Registers
”kyy - Copying the current line to k register”kp - Pasting the line from k register”Kyy - Appending to the k register”kp - Paste the lines from k register
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 27 / 35
Vim Advanced
norm in ex mode
:1,3 norm I WowThis would add the add word Wow at the beginning of 1-3 lines
:[range] norm [Commands]
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 28 / 35
Vim Advanced
What we have learnt now?
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 29 / 35
Vim Plugins
.vimrc
The file .vimrcYou could customize your vim setup
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 30 / 35
Vim Plugins
Plugins - installation
Plugin ManagersUse Vundle.(latest one) or Pathogen.
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 31 / 35
Vim Plugins
Plugins I use
NERDTreeNerdcommenterCtrl+Pdwmsurroundsnipmaterails.vimsupertabLaTeXBox
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 32 / 35
Vim Plugins
New Plugins which is worth a try
gist vimWriting your gist files in Vim :D
Etherpad vimYup! Etherpad in Vim! :) Also check out remote pair programming usingVim
In browserVimium in Chrome! is way awesome.Pentadactly in Firefox. (not sure if it is active)
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 33 / 35
Vim Resources and Links
Learn Vim
vimtutor (in terminal after installing Vim):help thingyouwantosearch (inside Vim)openvim.comvimcasts.comusevim.orgplenty more
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 34 / 35
Vim Resources and Links
Why waiting?
Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 35 / 35