text-objects - vim's elegant function
DESCRIPTION
vim の機能である Text-Objects の紹介。 kanazawa.rb meetup 18 LT 資料。TRANSCRIPT
![Page 1: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/1.jpg)
Text-Objectsvim's elegant function
2014/02/15 - Kanazawa.rb meetup 18 LT
![Page 2: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/2.jpg)
vim operation
• [operator] [motion]
• target = from cursor potion to motion result
![Page 3: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/3.jpg)
vim operator
• c : change
• d : delete
• y : yank
• p : paste
• etc ...
![Page 4: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/4.jpg)
vim motion
• j : next line
• w : next word head
• $ : line end
• / : search
• etc ...
![Page 5: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/5.jpg)
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.
![Page 6: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/6.jpg)
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$
![Page 7: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/7.jpg)
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
![Page 8: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/8.jpg)
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
![Page 9: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/9.jpg)
motion only?
• You can use Text-Objects
![Page 10: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/10.jpg)
Text Objects
• blocked chars
• word, sentence, paragraph block
• special char surround block
• "xxx", (xxx), <xxx>, <p>xxx</p>
![Page 11: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/11.jpg)
Text Objects
• blocked chars
• word, sentence, paragraph block
• special char surround block
• "xxx", (xxx), <xxx>, <p>xxx</p>
Yes, corder friendly!!
![Page 12: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/12.jpg)
How to use
• [operator] [motion]
• [operator] [text-objects specifier]
• target = specified text-objects
↓
![Page 13: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/13.jpg)
specifier
• [a|i][wsp\])}>"'`t]
• aw : a word
• i> : inner >
• at : a tag
• etc...
![Page 14: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/14.jpg)
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. };
![Page 15: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/15.jpg)
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. };
![Page 16: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/16.jpg)
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'
![Page 17: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/17.jpg)
example
1. var superFunc = function() {
2. console.log ('');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. }; di'
![Page 18: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/18.jpg)
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>fancy html</p>')
5. .appendTo('.super_anchor');
6. };
![Page 19: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/19.jpg)
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
![Page 20: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/20.jpg)
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('<p>abc</p>')
5. .appendTo('.super_anchor');
6. }; cit
![Page 21: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/21.jpg)
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
![Page 22: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/22.jpg)
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
![Page 23: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/23.jpg)
example
1. var superFunc = function() {
2. console.log ('pretty good function');
3. $("<div>")
4. .html('abc')
5. .appendTo('.super_anchor');
6. }; cat
![Page 24: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/24.jpg)
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}
![Page 25: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/25.jpg)
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}
![Page 26: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/26.jpg)
Conclusion
• Use "text objects" for elegant vim operation
• :help text-objects
![Page 27: Text-Objects - vim's elegant function](https://reader031.vdocument.in/reader031/viewer/2022020110/5565f71bd8b42a20158b5142/html5/thumbnails/27.jpg)
Thank you
Tomokazu Kiyoharahttp://github.com/kiyohara
http://facebook.com/tomokazu.kiyohara