Lecture 7: Text Objects, Motions and Visual Mode Part II Core Commands
The World as Everyone Else Sees it
The World as Everyone Else Sees it
The World as Everyone Else Sees it
The World as Everyone Else Sees it Other editors see text as a string of characters
The World as Everyone Else Sees it Other editors see text as a string of characters
The World as Everyone Else Sees it Other "editors" see text as a string of characters
The World as Vim Sees It
The World as Vim Sees It
The World as Vim Sees It
The World as Vim Sees It Vim (and you) see text as a sequence of objects.
• Editing Commands • Text Objects • Motions • Visual Mode
• Editing Commands • Text Objects • Motions • Visual Mode
If you still recall.... • Editing...
If you still recall.... • Editing... – is the process of making changes to text. • Hence, we have editing commands.
If you still recall.... • Editing... – is the process of making changes to text. • Hence, we have editing commands. • Focus of today: the c and d commands (and the like)!
If you still recall.... • Editing... – is the process of making changes to text. • Hence, we have editing commands. • Focus of today: the c and d commands (and the like)! • Focus of next lecture: the i and a commands for inserting/drafting, along with a rehash of the /<pattern><CR> , and f<char> commands.
Editing Commands c<object> • Change <object> under current cursor to... (goes to insert mode). d<object> • Delete <object> under cursor. • Main focus of today!
Other editing commands • Are still important. • Follow pretty much the same syntax/principles. • Every editing command can be repeated with the dot command!
Other editing commands y<object> • Yanks <object> under current cursor to register. =<object> • Reformats code for <objects> under current cursor.
Other editing commands gu/gU<object> • Decapitalize/Capitalize <object> under current cursor. >/<<object> • Indent/Dedent for <objects> under current cursor.
Other editing commands (from plugins) gc<object> • Comment <object> under current cursor. • From vim-commentary by Tim Pope. cs/ds<object> • Change/Delete surrounding for <objects> under current cursor. • From vim-surround by Tim Pope.
And then there are others • Other commands that do not follow this format: • Single Character Commands. • Special Purpose Commands. • And others that don't even categorize to these... • Not the focus of today!
Today: Editing Commands c<object> • Change <object> under current cursor to... (goes to insert mode). d<object> • Delete <object> under cursor.
• Editing Commands • Text Objects • Motions • Visual Mode
Text Objects • Vim sees the world as inherently composed of objects.
Text Objects • Vim sees the world as inherently composed of objects. • They are: – The most important part of Vim's commands that you NEED TO KNOW on top of your head.
Text Objects • Vim sees the world as inherently composed of objects. • They are: – The most important part of Vim's commands that you NEED TO KNOW on top of your head. – Most used part of Vim's commands.
Text Objects • Vim sees the world as inherently composed of objects. • They are: – The most important part of Vim's commands that you NEED TO KNOW on top of your head. – Most used part of Vim's commands. – You should be using them almost all of the time, unless you are not describing an object.
Fundamental Objects: #1 word and WORD
Fundamental Objects: #1 word and WORD • Probably one of the most confusing parts of Vim.
Fundamental Objects: #1 word and WORD • Probably one of the most confusing parts of Vim. • A word is... an almost C-Style variable name.
Fundamental Objects: #1 word and WORD • Probably one of the most confusing parts of Vim. • A word is... an almost C-style variable name. – A consecutive string of characters containing only of letters, digits and underscores.
Fundamental Objects: #1 word and WORD • Probably one of the most confusing parts of Vim. • A word is... an almost C-style variable name. – A consecutive string of characters containing only of letters, digits and underscores. – Can be modified through the 'iskeyword' option, if you are working with a language that has slightly different specification of variable names! – They are meant to indicate variable name and values!
Fundamental Objects: #1 word and WORD
Fundamental Objects: #1 word and WORD l_list is a word! (variable name)
Fundamental Objects: #1 word and WORD NULL is a word! (variable value)
Fundamental Objects: #1 word and WORD • Why word? • Do the following: change variable name, function name, change values, fix variable/function name typos...
Fundamental Objects: #1 word and WORD • Why word? • Do the following: change variable name, function name, change values, fix variable/function name typos... • Without having to retype everything in that WORD! (convenience)
Fundamental Objects: #1 word and WORD • Probably one of the most confusing parts of Vim. • A word is... an almost C-Style variable name. • A WORD is... what unix standard thinks is a word (lol).
Fundamental Objects: #1 word and WORD • Probably one of the most confusing parts of Vim. • A word is... an almost C-Style variable name. • A WORD is... what unix standard thinks is a word (lol). – A sequence of characters delimited by any kind of whitespace characters .
Fundamental Objects: #1 word and WORD l_list->next is a WORD!
Fundamental Objects: #1 word and WORD • Why WORD? • Do the following: making phrasal changes such as email addresses (with @'s and .'s), fixing completely wrong variables or structures... • Entirely different purpose.
Fundamental Objects #1 word and WORD • So how to express a word or WORD object?
Fundamental Objects #1 word and WORD • So how to express a word or WORD object? • Before that: • Text objects (generally) come in two different flavors!
Two flavors of text objects • Two flavors: 1.i - also known as "inside" 2.a - also known as "around"
Fundamental Objects #1 word and WORD • What does it mean to be "inside" a word/WORD, or "around" a word/WORD?
Fundamental Objects #1 word and WORD • What does it mean to be "inside" a word/WORD, or "around" a word/WORD? "inside" a word means the word itself . iw
Fundamental Objects #1 word and WORD • What does it mean to be "inside" a word/WORD, or "around" a word/WORD? "around" a word means the word itself + a succeding space . aw
Fundamental Objects #1 word and WORD • iw - inside word. • aw - around word. • iW - inside WORD. • aW - around WORD.
Fundamental Objects #1 word and WORD • iw - inside word. • aw - around word. • iW - inside WORD. • aW - around WORD. • Why do we care?
Fundamental Objects #1 word and WORD • iw - inside word. • aw - around word. • iW - inside WORD. • aW - around WORD. • Why do we care?
Fundamental Objects #1 word and WORD • Compare: diw
Fundamental Objects #1 word and WORD • Compare: daw
Fundamental Objects #1 word and WORD • Compare: ciwlot<Esc>
Fundamental Objects #1 word and WORD • Compare: cawlot<Esc>
Fundamental Objects: #1 word and WORD • Vim allow you to express precisely what you want to do! • When you are deleting a word, do you want to preserve the space after the word? Or do you want to delete it? • When you are changing a word, do you want to change the space after the word as well? Or are you okay with leaving it as-is?
Fundamental Objects: #1 word and WORD • Is this an issue?
Fundamental Objects: #1 word and WORD • Is this an issue? – If you are editing prose, generally NO! • Too much thinking? • When you are deleting a word, you probably want to delete the whitespace after it, otherwise there might be duplicate spaces. • When you are changing a word, you probably don't need to change the space after it.
Fundamental Objects #1 word and WORD • Hence, make this your muscle memory! da ci
Fundamental Objects #1 word and WORD • Hence, make this your muscle memory! da ci • Note: depending on language, may not apply to programming! • Figure out your language style conventions, and make it a habit!
Fundamental Objects #2 enclosed objects • "strings" • (cons (1 nil)) • {document} • etc... • Are wrapped with matching characters: "", (), [], {}, even html tags!
Fundamental Objects #2 enclosed objects • General syntax for <enclosed object>: • i<closing delimiter> • a<closing delimiter>
Fundamental Objects #2 enclosed objects • Example:
Recommend
More recommend