- Notifications
You must be signed in to change notification settings - Fork47
Vim plugin: Create your own text objects
kana/vim-textobj-user
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
vim-textobj-user is a Vim plugin to create your own text objects without pain.It is hard to create text objects, because there are many pitfalls to dealwith. This plugin hides such details and provides a declarative way to definetext objects. You can use regular expressions to define simple text objects,or use functions to define complex ones.
Definead/id to select a date such as2013-03-16, anddefineat/it to select a time such as22:04:21:
calltextobj#user#plugin('datetime', {\'date': {\'pattern':'\<\d\d\d\d-\d\d-\d\d\>',\'select': ['ad','id'],\ },\'time': {\'pattern':'\<\d\d:\d\d:\d\d\>',\'select': ['at','it'],\ },\})
DefineaA to select text from<< to the matching>>, anddefineiA to select text inside<< and>>:
calltextobj#user#plugin('braces', {\'angle': {\'pattern': ['<<','>>'],\'select-a':'aA',\'select-i':'iA',\ },\})
Defineal to select the current line, anddefineil to select the current line without indentation:
calltextobj#user#plugin('line', {\'-': {\'select-a-function':'CurrentLineA',\'select-a':'al',\'select-i-function':'CurrentLineI',\'select-i':'il',\ },\})function!CurrentLineA()normal!0let head_pos=getpos('.')normal!$let tail_pos=getpos('.')return ['v', head_pos, tail_pos]endfunctionfunction!CurrentLineI()normal! ^let head_pos=getpos('.')normal! g_let tail_pos=getpos('.')let non_blank_char_exists_p=getline('.')[head_pos[2]-1]!~#'\s'return\non_blank_char_exists_p\? ['v', head_pos, tail_pos]\:0endfunction
Definea( to select text from\left( to the matching\right), anddefinei( to select text inside\left( to the matching\right),butonly for tex files:
calltextobj#user#plugin('tex', {\'paren-math': {\'pattern': ['\\left(','\\right)'],\'select-a': [],\'select-i': [],\ },\})augrouptex_textobjsautocmd!autocmdFileTypetexcalltextobj#user#map('tex', {\'paren-math': {\'select-a':'<buffer> a(',\'select-i':'<buffer> i(',\ },\})augroupEND
You can define your own text objects like the above examples. See alsothe reference manualfor more details.
There are many text objects written with vim-textobj-user.If you want to find useful ones, or to know how they are implemented,seea list of text objects implemented withvim-textobj-user.
About
Vim plugin: Create your own text objects
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
