policies and principles
play

Policies and Principles Part I Recurring Themes Annoucements - PowerPoint PPT Presentation

Lecture 3: Relative Jumps, Policies and Principles Part I Recurring Themes Annoucements Homework 1 due now! '*' means it will not be in any of the exams. Last Time We talked about the ambiguity! We talked about two ways of


  1. Insert Mode • Commands follow a 'unix standard' or convention. (usually...) • <C-h>: remove the last character. • <C-w>: remove the last word. (will be discussed in the future) • <C-u>: remove the entire line. • <C-r>: a bit more complicated... • etc. • These commands are relative to the current cursor! (quickdemo)

  2. Insert Mode

  3. Modal Editing • Myth #3: In Vim, you are almost always in Normal Mode.

  4. Modal Editing • Myth #3: In Vim, you are almost always in Normal Mode. • When you are drafting in Vim, you are almost always in Insert Mode!

  5. Modal Editing • Myth #3: In Vim, you are almost always in Normal Mode. • When you are drafting in Vim, you are almost always in Insert Mode!

  6. Modal Editing • When using Vim, there are different phases: • Drafting -- almost always in insert mode • Skimming • Editing

  7. Modal Editing • When using Vim, there are different phases: • Drafting -- almost always in insert mode • Skimming • Editing

  8. Skimming • When you just want to skim/read the content of the file, you probably don't want to make modifications...

  9. Skimming • When you just want to skim/read the content of the file, you probably don't want to make modifications... • <C-> itself provides limited number of commands...

  10. Skimming • When you just want to skim/read the content of the file, you probably don't want to make modifications... • <C-> itself provides limited number of commands... • Most importantly, poor ergonomics!

  11. Normal Mode • Hence, we have normal mode! • Entire mode for 2 main purposes: – Provide good skimming/scrolling commands – Provide good editing commands Without completely awful ergonomics!

  12. Normal Mode • Hence, we have normal mode! • Entire mode for 2 main purposes: – Provide good skimming/scrolling commands – Provide good editing commands Without completely awful ergonomics!

  13. Normal Mode • Hence, we have normal mode! • Entire mode for 2 main purposes: – Provide good skimming/scrolling commands – Provide good editing commands Without completely awful ergonomics! so far, all commands we've talked about are in normal mode! /<pattern><CR> f c d I A ea

  14. Normal Mode

  15. Window and Cursor Policy • Vim's cursor and screen behaves very differently from other editors.

  16. Window and Cursor Policy • Vim's cursor and screen behaves very differently from other editors. • Principle: • cursor follows edit • screen follows view • quickdemo (lorem.txt)

  17. Window and Cursor Policy • What this means: • skimming -- view -- screen • editing -- edit -- cursor

  18. Window and Cursor Policy • What this means: • skimming -- view -- screen • editing -- edit -- cursor • Implication: you use different commands in different phases!

  19. Skimming • We use the screen commands in normal mode while skimming. • They do not modify the file! • <C-d>: Half screen down • <C-u>: Half screen up • <C-e>: One line down • <C-y>: One line up • zz: Set screen to cursor in midscreen • etc... • Many commands have <C-> modifiers... Because Vim has waaaayy too many key mappings! :(

  20. Skimming • We use the screen commands in normal mode while skimming. • They do not modify the file! • <C-d>: Half screen down • <C-u>: Half screen up • <C-e>: One line down • <C-y>: One line up • zz: Set screen to cursor in midscreen • etc... • Many commands have <C-> modifiers... Because Vim has wayy too many key mappings! :(

  21. Modal Editing • When using Vim, there are different phases: • Drafting -- almost always in insert mode • Skimming -- always in normal mode • Editing

  22. Modal Editing • When using Vim, there are different phases: • Drafting -- almost always in insert mode • Skimming -- always in normal mode • Editing

  23. Editing • Complication: – Want to be able to type every character – Want to have not completely terrible ergonomics for editing commands as well....

  24. Editing • Complication: – Want to be able to type every character – Want to have not completely terrible ergonomics for editing commands as well....

  25. Editing • Normal modes provides commands for locating and editing (as you've seen already)... • But after using some edit command, have to specify what to edit TO.

  26. Editing • Normal modes provides commands for locating and editing (as you've seen already)... • But after using some editing command, have to specify what to edit TO. • Solution: Call locating and editing commands in normal mode. Then jumps into insert mode to specify what to edit to....

  27. Editing • Example: ciw lol ???

  28. Editing • Example: ciw change current word (while in normal mode), then jumps into insert mode. lol ???

  29. Editing • Example: ciw change current word (while in normal mode), then jumps into insert mode. lol changes the word to 'lol' (now I am in insert mode) ???

  30. Editing • Example: ciw change current word (while in normal mode), then jumps into insert mode. lol changes the word to 'lol' (now I am in insert mode) ???

  31. Editing • Complication: you want to continue editing by using normal mode commands....

  32. Editing • Complication: you want to continue editing by using normal mode commands.... • But, you are currently in insert mode...

  33. Editing • Complication: you want to continue editing by using normal mode commands.... • But, you are currently in insert mode... • So: we need some nonprintable character to jump from insert mode to normal mode!

  34. 'Escape' command <Esc>

  35. Editing • Has debatable ergonomics... • You may choose to remap this key in the future... • Specialized purpose : escaping from insert mode to normal mode!

  36. Editing • Example: ciw change current word (while in normal mode), then jumps into insert mode. lol changes the word to 'lol' (now I am in insert mode) <Esc> Return to normal mode!

  37. Modal Editing • When using Vim, there are different phases: • Drafting -- almost always in insert mode • Skimming -- always in normal mode • Editing -- always alternating between normal mode and insert mode

  38. Modal Editing • When using Vim, there are different phases: • Drafting -- almost always in insert mode • Skimming -- always in normal mode • Editing -- always alternating between normal mode and insert mode • Takeaway: do not be afraid of insert mode! Many actions should be done in insert mode!

Recommend


More recommend