Introduction to vim

508 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
508
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Introduction to vim

  1. 1. Vim - The Hacker’s EditorVysakh Sreenivasanvysakh.quora.comvysakh0 - twitter/facebookApril 29, 2013
  2. 2. VimTable of Contents1 VimHistoryVi BasicsAdvancedPluginsResources and LinksVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 2 / 35
  3. 3. VimBillion Dollar EditorVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 3 / 35
  4. 4. VimWhat 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
  5. 5. VimWhat 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
  6. 6. VimWhat 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
  7. 7. VimWhat 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
  8. 8. VimWhat 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
  9. 9. VimWhat 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
  10. 10. VimHow do Vim users feel :)Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 5 / 35
  11. 11. Vim HistoryLine and Screen EditorsHistory of Text editors in a nutshellVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
  12. 12. Vim HistoryLine and Screen EditorsHistory of Text editors in a nutshellBasic Line editor - Ed editor - made by Ken ThompsonVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
  13. 13. Vim HistoryLine and Screen EditorsHistory of Text editors in a nutshellBasic Line editor - Ed editor - made by Ken ThompsonAdvanced line editor Ex editorVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
  14. 14. Vim HistoryLine and Screen EditorsHistory of Text editors in a nutshellBasic Line editor - Ed editor - made by Ken ThompsonAdvanced line editor Ex editorScreen Editor - you could see stuff while editing :) ViVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
  15. 15. Vim HistoryLine and Screen EditorsHistory of Text editors in a nutshellBasic Line editor - Ed editor - made by Ken ThompsonAdvanced line editor Ex editorScreen Editor - you could see stuff while editing :) ViAn improved Vi - VimVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 6 / 35
  16. 16. Vim Vi BasicsFire up Vimvim 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 fileVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 7 / 35
  17. 17. Vim Vi BasicsModesInsert - 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 aboveCommand - delete/copy/paste/movement/..Ctrl + C or Ctrl+ [ or escVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 8 / 35
  18. 18. Vim Vi BasicsModes 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/linesCtrl+v Selects block/columnVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 9 / 35
  19. 19. Vim Vi BasicsPanesctrl+w+s or :sp - split horizontallyctrl+w+v or :vsp - split verticallyctrl+w+w - move next paneVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 10 / 35
  20. 20. Vim Vi BasicsTabs:tabe filename To open a file in a new tabgt To move to next tabgT To move to prev tabVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 11 / 35
  21. 21. Vim Vi BasicsMovementsj - points downwards!k - the straight k line points upwardsVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 12 / 35
  22. 22. Vim Vi BasicsMore 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
  23. 23. Vim Vi BasicsMore 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 lineVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 14 / 35
  24. 24. Vim Vi BasicsCopy/Delete/Pastey - 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 cursorVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 15 / 35
  25. 25. Vim Vi BasicsCombination of keysVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 16 / 35
  26. 26. Vim Vi BasicsCombination of keys10p - 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
  27. 27. Vim Vi BasicsMore on key combodiw - 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
  28. 28. Vim Vi BasicsSearch, ReplaceSearch /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
  29. 29. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  30. 30. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  31. 31. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  32. 32. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  33. 33. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  34. 34. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  35. 35. Vim Vi BasicsPlay around with ex editor/ex modeex 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
  36. 36. Vim Vi Basicst$ (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
  37. 37. Vim Vi Basicst$ (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
  38. 38. Vim Vi Basicst$ (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
  39. 39. Vim Vi Basicst$ (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
  40. 40. Vim Vi Basicst$ (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
  41. 41. Vim Vi Basicst$ (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
  42. 42. Vim Vi Basicst$ (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
  43. 43. Vim Vi BasicstipCtrl+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 directorygiGo 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
  44. 44. Vim AdvancedOmni completeCtrl + n or Ctrl + p (in insert mode, handy when calling functions)Ctrl + x + k - dictionary completionCtrl + x + f - file name autocompletionVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 23 / 35
  45. 45. Vim AdvancedMacrosRecords 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
  46. 46. Vim AdvancedMarksMark 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
  47. 47. Vim AdvancedJumpsCtrl + 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 jumpsVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 26 / 35
  48. 48. Vim AdvancedRegisters”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 registerVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 27 / 35
  49. 49. Vim Advancednorm 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
  50. 50. Vim AdvancedWhat we have learnt now?Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 29 / 35
  51. 51. Vim Plugins.vimrcThe file .vimrcYou could customize your vim setupVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 30 / 35
  52. 52. Vim PluginsPlugins - installationPlugin ManagersUse Vundle.(latest one) or Pathogen.Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 31 / 35
  53. 53. Vim PluginsPlugins I useNERDTreeNerdcommenterCtrl+Pdwmsurroundsnipmaterails.vimsupertabLaTeXBoxVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 32 / 35
  54. 54. Vim PluginsNew Plugins which is worth a trygist vimWriting your gist files in Vim :DEtherpad vimYup! Etherpad in Vim! :) Also check out remote pair programming usingVimIn 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
  55. 55. Vim Resources and LinksLearn Vimvimtutor (in terminal after installing Vim):help thingyouwantosearch (inside Vim)openvim.comvimcasts.comusevim.orgplenty moreVysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 34 / 35
  56. 56. Vim Resources and LinksWhy waiting?Vysakh Sreenivasan (vysakh.quora.com) Vim - The Hacker’s Editor April 29, 2013 35 / 35

×