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 deal with. This plugin hides such details and provides a declarative way to define text objects. You can use regular expressions to define simple text objects, or use functions to define complex ones.
Define ad
/id
to select a date such as 2013-03-16
, and
define at
/it
to select a time such as 22:04:21
:
call textobj#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'],
\ },
\ })
Define aP
to select a PHP code with <?php
and ?>
, and
define iP
to select a PHP code without <?php
and ?>
:
call textobj#user#plugin('php', {
\ 'code': {
\ 'pattern': ['<?php\>', '?>'],
\ 'select-a': 'aP',
\ 'select-i': 'iP',
\ },
\ })
Define al
to select the current line, and
define il
to select the current line without indentation:
call textobj#user#plugin('line', {
\ '-': {
\ 'select-a-function': 'CurrentLineA',
\ 'select-a': 'al',
\ 'select-i-function': 'CurrentLineI',
\ 'select-i': 'il',
\ },
\ })
function! CurrentLineA()
normal! 0
let head_pos = getpos('.')
normal! $
let tail_pos = getpos('.')
return ['v', head_pos, tail_pos]
endfunction
function! 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]
\ : 0
endfunction
You can define your own text objects like the above examples. See also the reference manual for 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, see a list of text objects implemented with vim-textobj-user.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。