Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Vim plugin: Create your own text objects

NotificationsYou must be signed in to change notification settings

kana/vim-textobj-user

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 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.

Examples

Simple text objects defined by a pattern

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

Simple text objects surrounded by a pair of patterns

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

Complex text objects defined by functions

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

Text objects for a specific filetype

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

Further reading

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp