text-objects - vim's elegant function
DESCRIPTION
vim の機能である Text-Objects の紹介。 kanazawa.rb meetup 18 LT 資料。TRANSCRIPT
Text-Objectsvim's elegant function
2014/02/15 - Kanazawa.rb meetup 18 LT
vim operation
• [operator] [motion]
• target = from cursor potion to motion result
vim operator
• c : change
• d : delete
• y : yank
• p : paste
• etc ...
vim motion
• j : next line
• w : next word head
• $ : line end
• / : search
• etc ...
example
1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
3. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
example
1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
3. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
d$
example
1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
3. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
d$
delete
example
1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2. Ut enim ad
3. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
d$
delete
motion only?
• You can use Text-Objects
Text Objects
• blocked chars
• word, sentence, paragraph block
• special char surround block
• "xxx", (xxx), <xxx>, <p>xxx</p>
Text Objects
• blocked chars
• word, sentence, paragraph block
• special char surround block
• "xxx", (xxx), <xxx>, <p>xxx</p>
Yes, corder friendly!!
How to use
• [operator] [motion]
• [operator] [text-objects specifier]
• target = specified text-objects
↓
specifier
• [a|i][wsp\])}>"'`t]
• aw : a word
• i> : inner >
• at : a tag
• etc...
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. };
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. };
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; di'
example
1. var superFunc = function() {
2. console.log ('');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; di'
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. };
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; cit
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>abc</p>')
5. .appendTo('.super_anchor');
6. }; cit
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; cat
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; cat
include tag
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('abc')
5. .appendTo('.super_anchor');
6. }; cat
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; yi}
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; yi}
Conclusion
• Use "text objects" for elegant vim operation
• :help text-objects
Thank you
Tomokazu Kiyoharahttp://github.com/kiyohara
http://facebook.com/tomokazu.kiyohara