vim-textobj-user

Vim plugin: Create your own text objects

Github星跟蹤圖

vim-textobj-user - Create your own text objects

Build Status

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.

Examples

Simple text objects defined by a pattern

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'],
\   },
\ })

Simple text objects surrounded by a pair of patterns

Define aA to select text from << to the matching >>, and
define iA to select text inside << and >>:

call textobj#user#plugin('braces', {
\   'angle': {
\     'pattern': ['<<', '>>'],
\     'select-a': 'aA',
\     'select-i': 'iA',
\   },
\ })

Complex text objects defined by functions

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

Text objects for a specific filetype

Define a( to select text from \left( to the matching \right), and
define i( to select text inside \left( to the matching \right),
but only for tex files:

call textobj#user#plugin('tex', {
\   'paren-math': {
\     'pattern': ['\\left(', '\\right)'],
\     'select-a': [],
\     'select-i': [],
\   },
\ })

augroup tex_textobjs
  autocmd!
  autocmd FileType tex call textobj#user#map('tex', {
  \   'paren-math': {
  \     'select-a': '<buffer> a(',
  \     'select-i': '<buffer> i(',
  \   },
  \ })
augroup END

Further reading

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
.

主要指標

概覽
名稱與所有者kana/vim-textobj-user
主編程語言Vim Script
編程語言Ruby (語言數: 2)
平台
許可證
所有者活动
創建於2010-03-23 13:46:01
推送於2020-02-21 09:29:25
最后一次提交2017-08-02 14:16:07
發布數25
最新版本名稱0.7.6 (發布於 2018-11-19 19:10:38)
第一版名稱0.3.5 (發布於 )
用户参与
星數1.5k
關注者數29
派生數47
提交數297
已啟用問題?
問題數52
打開的問題數21
拉請求數6
打開的拉請求數1
關閉的拉請求數23
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?