Vim, the final text editor you need to learn

Vim, the final text editor you need to learn

F2dcf6633971844e19ca96ea294ba976?s=128

高見龍

May 07, 2013
Tweet

Transcript

  1. Vim the final text editor you need to learn eddie@NISRA,

    fju
  2. None
  3. Current Status 80% iOS app, 20% Ruby/Rails

  4. Scenario

  5. I'm looking for a text editor..

  6. 1. launch quickly 2. easy to navigate between files 3.

    and pretty syntax highlight
  7. What's Vim?

  8. it may look a little old-fashioned

  9. but it can also be modern : )

  10. So, Why Vim?

  11. Keyboard-driven

  12. Keyboard is King!

  13. and, Why not Vim?

  14. tonight, we have 2 Goals..

  15. no Mouse

  16. no Arrow keys

  17. How to Vim?

  18. Practice: Install Vim in your machine. http://www.vim.org/download.php

  19. .vimrc

  20. if you want to use my .vimrc 1. clone from

    my Github repo 2. cd to cloned repo and execute install script 3. make symbolic link for vim 4. done!
  21. https://github.com/kaochenlong/eddie-vim

  22. Modes normal, visual, and edit mode

  23. Modes Switch: 1. in normal mode, i or a or

    o to enter insert mode(i = insert, a = append, o = newline) 2. in insert mode, ESC or Ctrl+[ to enter normal mode 3. in normal mode, hit v or V to enter visual mode 4. in visual mode, hit ESC or Ctrl+[ to normal mode
  24. ESC or Ctrl + [

  25. None
  26. Practice: launch Vim and switch between normal, visual, and edit

    mode.
  27. Basic

  28. ✓:w write to file. ✓:q exit Vim. ✓:tabe create a

    new tab. ✓gt to switch to next tab, gT to previous tab. (I map gt and gT to F7 and F8 in my vimrc) ✓:new to create a horizontal split window, :vnew or :vs to create a vertical split window.
  29. ✓vi -o a.rb b.rb to open those two files at

    the same time with horizontal split window. ✓vi -O a.rb b.rb same as above, but in vertical split window. ✓vi -p a.rb b.rb to open files with tabs. ✓vi http://www.eddie.com.tw will read the source content into vim directly.
  30. Practice: 1. quit Vim, and launch Vim, quite Vim, and

    launch Vim .. x N 2. open a file with Vim, exit, then open it again, then exit .. x N
  31. Vim Text Objects

  32. d 3 w = delete 3 words

  33. Word: 1. aw - a word 2. iw - inner

    word
  34. Practice: 1. select a word, deselect, and select another word,

    and deselect.. x N 2. select a word, delete it, select another word, and delete.. X N
  35. Sentence: 1. as - a sentence 2. is - inner

    sentence
  36. Practice: 1. select a sentence, deselect, and select another sentence,

    and deselect.. x N 2. select a sentence, delete it, select another sentence, and delete.. X N
  37. Paragraph: 1. ap - a paragraph 2. ip - inner

    paragraph
  38. Practice: 1. select a paragraph, deselect, and select another paragraph,

    and deselect.. x N 2. select a paragraph, delete it, select another paragraph, and delete.. X N
  39. Movement :h movement

  40. move cursor with h, j, k and l disable arrow

    keys if possible
  41. ✓w or W to move cursor forward by a word,

    and b or B is backward. ✓0 to back to the begin of the line, and $ is jump to the end. ✓fx will stop the cursor at the next "x" character in current line, and F is search backward.
  42. ✓} will move cursor to next section, { move to

    last section. ✓vit will visually select content between the tag, while vat will even including the tag. ✓vi" will visually select content between current double quotes. ✓viw will select the current word.
  43. ✓gg will move the cursor to the top of the

    current file, and G will jump to bottom. ✓zz, zb, zt ✓/ search, n can jump to next matched result, and N will jump to last one. ✓* search the word on cursor.
  44. Practice: try to move cursor with hjkl keys, not arrow

    keys.
  45. Buffers :ls, :bd, :b3, :b filename, :tab ba

  46. Practice: try to open several files, and switch between them

    with buffer commands.
  47. Folding :h folds

  48. Basic: - zf to fold selected lines - zd to

    un-fold selected lines
  49. Practice: fold several lines, and unfold them .. x N

  50. Editing

  51. ✓D to clear all content of current line after the

    cursor. ✓C like D, but enter insert mode. dG will clear all content after the cursor, dgg will clear all content before the cursor. ✓x remove a character. ✓. to repeat last action. ✓dd to delete whole line, 3dd to delete 3 lines.
  52. ✓yy yank the whole line of the cursor. ✓3yy yank

    3 lines. ✓p paste content from register, 3p paster content from register for 3 times. ✓= re-format, gg=G re-format whole file.
  53. ✓dw, diw to delete the word in the cursor. ✓cw,

    ciw same as above, but enter insert mode. r to replace current character. ✓J to concatenate current line with next line, 3J will concatenate next 3 lines. ✓> to add indentation, < to remove indentation.
  54. Plugins

  55. Pathogen nice plugin manager https://github.com/tpope/vim-pathogen

  56. NERDTree A tree explorer https://github.com/scrooloose/nerdtree

  57. SnipMate code snippets plugin, inspired by TextMate https://github.com/msanders/snipmate.vim

  58. ctrlp Fuzzy file, buffer, mru, tag, etc finder https://github.com/kien/ctrlp.vim

  59. surround.vim quoting/parenthesizing made simple https://github.com/tpope/vim-surround

  60. vim-multiple-cursors Sublime Text style multiple selections for Vim https://github.com/terryma/vim-multiple-cursors

  61. powerline the ultimate vim statusline utility https://github.com/Lokaltog/vim-powerline

  62. rails.vim Ruby on Rails power tools https://github.com/tpope/vim-rails

  63. fugitive a git wrapper for vim https://github.com/tpope/vim-fugitive

  64. vimwiki personal wiki for vim https://github.com/vim-scripts/vimwiki

  65. ragtag https://github.com/tpope/vim-ragtag

  66. Practicing!

  67. References

  68. http://blog.eddie.com.tw/screencasts/

  69. and more practice.. : )

  70. Tips

  71. in terminal: 1. ctrl + z to stash vim, and

    type fg to bring it back. 2. ctrl + w to delete a word, ctrl + u to delete a whole line, both work in terminal and vim edit mode. 3. ctrl + r to find history commands fuzzily.