drafting commands metaediting
play

Drafting Commands, Metaediting Part II: The Core Commands - PowerPoint PPT Presentation

Lecture 8: Visual Mode, /<CR>, Drafting Commands, Metaediting Part II: The Core Commands Announcements HW3... is postponed to next week... Too few things to test on Make sure to practice on commands discussed so far. Every


  1. Lecture 8: Visual Mode, /<CR>, Drafting Commands, Metaediting Part II: The Core Commands

  2. Announcements • HW3... is postponed to next week... – Too few things to test on – Make sure to practice on commands discussed so far. Every single command in this course is important! (Each has an equal chance of showing up on the exams)

  3. Last Time • Text Objects! • Motions....

  4. Last Time • Text Objects! • Motions.... • Today: Visual Mode!

  5. Reminder... • As always, in regular text editing, there is a certain order that we tend to prioritize: 1.Text objects: views objects as fundamental elements of text 1. word/WORD objects 2. line objects 3. enclosed objects

  6. Reminder... • As always, in regular text editing, there is a certain order that we tend to prioritize: 2. Motions: deals with "chunks of text" that cannot be expressed by simply stating what objects they are.

  7. Reminder... • As always, in regular text editing, there is a certain order that we tend to prioritize: 2. Motions: deals with "chunks of text" that cannot be expressed by simply stating what objects they are. – Usually complicated combinations of objects. – Are straightforward, and uninteresting.

  8. Reminder... • As always, in regular text editing, there is a certain order that we tend to prioritize: 2. Motions: deals with "chunks of text" that cannot be expressed by simply stating what objects they are. – What could possibly go wrong?

  9. • Visual Mode • 1 Character Editing Commands and Drafting Commands • /<pattern><CR> and Metaediting.

  10. • Visual Mode • 1 Character Editing Commands and Drafting Commands • /<pattern><CR> and Metaediting.

  11. Issues with Motions

  12. Issues with Motions Task: Change to "in C, we can use ``variableinstance.function'' to access its member variables."

  13. Issues with Motions Task: Change to "in C, we can use ``variableinstance.function'' to access its member variables." Well?

  14. Issues with Motions Task: Change to "in C, we can use ``variableinstance.function'' to access its member variables." Well? Obvious Solution: c/.<CR>yaddayadda<Esc>

  15. Issues with Motions Task: Change to "in C, we can use ``variableinstance.function'' to access its member variables." Well? Obvious Solution: c/.<CR>yaddayadda<Esc> Nonobvious Result: ...

  16. Issues with Motions • The gotcha: c<object> • Command deals with only ONE object or ONE motion!

  17. Issues with Motions • The gotcha: c<object> • Command deals with only ONE object or ONE motion! • How do we deal with complicated descriptions? (relative, cheating, etc...)

  18. In the good ol' days of vi...

  19. In the good ol' days of vi...

  20. In the good ol' days of vi... Can't do that...

  21. In the good ol' days of vi... Can't do that... (workaround: marks, regex tricks, more accurate regex matching)

  22. In the good ol' days of vi...

  23. Today: Vim Editing Commands follow the format: <command><object/motion>

  24. Today: Vim Editing Commands follow the format: <command><object/motion> Issue: how do we know that our description has ended ?

  25. Possible Workarounds • Some kind of termination signal to tell Vim that we have finished our description... – Very Problematic: no longer vi-compatible, extra keystrokes for EVERY single edit command, too many commands (keyboard fully mapped)

  26. Possible Workarounds • Some kind of termination signal to tell Vim that we have finished our description... – Very Problematic: no longer vi-compatible, extra keystrokes for EVERY single edit command, too many commands (keyboard fully mapped) • What Vim actually does: Visual Mode!

  27. Visual Mode: The Idea • Nearly all Vim commands have a clear seperation of editing process: 1. Locate 2. Edit 3. (Repeat) • These commands are hence disjoint!

  28. Visual Mode: The Idea • Instead of structuring our commands like this: <command><object/motion> • We do this: <object/motion><command>

  29. Visual Mode: The Idea • Instead of structuring our commands like this: <command><object/motion> • We do this: <object/motion><command> • How do we know that our motion has terminated?

  30. Visual Mode: The Idea • Instead of structuring our commands like this: <command><object/motion> • We do this: <object/motion><command> • How do we know that our motion has terminated? When we reach an edit command!

  31. Visual Mode • Three kinds, with radically different use cases: – Visual Mode (today) – Visual Line Mode – Visual Block Mode

  32. Visual Mode • Three kinds, with radically different use cases: – Visual Mode (today) • to allow complicated descriptions for locates – Visual Line Mode • to allow "chuck" execution of ex commands or normal mode commands – Visual Block Mode • practically useless... very few contrived use cases.

  33. Visual Mode • Descriptions are highlighted . • Enter/Exit with the v command. • Demo. • Use case: nearly always paired with use of f and t commands! Deals with any kind of code that is even slightly complicated.

  34. Visual Mode • Commands: • Nearly all normal mode commands work as expected, only in reverse order: v<object/motion><command> • v - enter/escape visual mode • V , <C-v> - switch to visual line/block mode

  35. Visual Mode • Commands: • gv - reselect previous selection – VERY useful for redoing typos • o - go to the other end of the selection – Used in combination with gv for convenient continuting navigation.

  36. Visual Mode • Commands: • gv - reselect previous selection – VERY useful for redoing typos • Hm.... How does gv work? – where and how is previous selection stored? – what happens if we perform edits?

  37. Visual Mode • Commands: • gv - reselect previous selection – VERY useful for redoing typos • Hm.... How does gv work? – where and how is previous selection stored? – what happens if we perform edits? • Will be addressed in HW 3!

  38. • Visual Mode • 1 Character Editing Commands and Drafting Commands • /<pattern><CR> and Metaediting.

  39. Miscellaneous: 1-Character Commands • ... are used nearly exclusively to fix one character typos. • Used surprisingly frequently: one character typos happen often. • Optimized keystrokes. • Fixed Pattern : /<line><CR>f<char><1-char-edit>

  40. Miscellaneous: 1-Character Commands • Commands: • r<char> - replace character with <char> • x - delete character • s - change character (go to insert mode) • vU/vu - trick to capitalize/lowercase one character. • J - command to trim end of line and join two lines together. (not quite 1 character)

  41. Drafting Commands • Drafting: appending/inserting huge chuncks of text.

  42. Drafting Commands • Drafting: appending/inserting huge chuncks of text. • Not much involved, remember a few very common use case patterns:

  43. Drafting Commands • Base Commands: • i - insert in front of cursor • a - append at end of cursor • I - insert in front of line • A - append at end of cursor

  44. Drafting Commands • VERY Common Patterns: • /<line><CR>I/A : insert in front of/append at end of line containing <line>. • /<word><CR>i : insert in front of <word> • /<word><CR>ea : append at end of <word> • /<line><CR>f<char>i/a : insert in front of/append at end of <char> from <line>

  45. Speaking of Which... • The /<pattern><CR> command... • ... is THE MOST IMPORTANT command in Vim!

  46. Speaking of Which... • The /<pattern><CR> command... • ... is THE MOST IMPORTANT command in Vim! • Which we will devote the rest of today's lecture to!

  47. • Visual Mode • 1 Character Editing Commands and Drafting Commands • /<pattern><CR> and Metaediting.

  48. /<pattern><CR> ... again! • ... is very very versatile!

  49. /<pattern><CR> ... again! • ... is very very versatile! • But first, what's a <pattern> ?

  50. vimregex • a <pattern> is a form of vim regular expression.

  51. vimregex • a <pattern> is a form of vim regular expression. • Depressing fact of life: vim has 4 different flavors of regular expressions!

  52. vimregex • a <pattern> is a form of vim regular expression. • Depressing fact of life: vim has 4 different flavors of regular expressions! – NONE of which is EQUIVALENT to regular expressions of programming languages. – Only SIMILAR, which means that you'll still have to "relearn" it.

  53. vimregex • 4 flavors: • verynomagic • nomagic • magic • verymagic • ... Each with their own rules! • ... and extremely questionable reasons for having 4 different standards...

  54. vimregex • 4 flavors: • verynomagic • nomagic • magic • verymagic • ... Each with their own rules! • ... and extremely questionable reasons for having 4 different standards...

Recommend


More recommend