• Stars
    star
    1,439
  • Rank 32,712 (Top 0.7 %)
  • Language
    Vim Script
  • Created over 14 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vim plugin: Create your own text objects

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.

More Repositories

1

vim-textobj-entire

Vim plugin: Text objects for entire buffer
Vim Script
426
star
2

vim-smartinput

Vim plugin: Provide smart input assistant
Vim Script
318
star
3

vim-arpeggio

Vim plugin: Mappings for simultaneously pressed keys
Vim Script
271
star
4

vim-vspec

Vim plugin: Testing framework for Vim script
Vim Script
222
star
5

vim-submode

Vim plugin: Create your own submodes
Vim Script
217
star
6

vim-operator-user

Vim plugin: Define your own operator easily
Vim Script
188
star
7

vim-fakeclip

Vim plugin: Provide pseudo "clipboard" registers
Vim Script
180
star
8

vim-textobj-line

Vim plugin: Text objects for the current line
Vim Script
178
star
9

vim-textobj-indent

Vim plugin: Text objects for indented blocks of lines
Vim Script
166
star
10

vim-textobj-function

Vim plugin: Text objects for functions
Vim Script
141
star
11

vim-flavor

Taste the difference.
Ruby
112
star
12

config

My configuration files feat. hardcore Vim scripts
HTML
96
star
13

vim-operator-replace

Vim plugin: Operator to replace text with register content
Vim Script
81
star
14

vim-altr

Vim plugin: Switch to the missing file without interaction
Vim Script
76
star
15

vim-smartword

Vim plugin: Smart motions on words
Vim Script
70
star
16

vim-niceblock

Vim plugin: Make blockwise Visual mode more useful
Vim Script
67
star
17

vim-tabpagecd

Vim plugin: Turn :cd into :tabpagecd, to use one tab page per project
Vim Script
52
star
18

vim-textobj-lastpat

Vim plugin: Text objects for the last searched pattern
Vim Script
51
star
19

sicp

Scheme
49
star
20

vim-smartchr

Vim plugin: Insert several candidates with a single key
Vim Script
38
star
21

vim-metarw

Vim plugin: A framework to read/write fake:path
Vim Script
35
star
22

vim-textobj-fold

Vim plugin: Text objects for foldings
Vim Script
34
star
23

vim-gf-user

Vim plugin: A framework to open a file by context
Vim Script
33
star
24

vim-filetype-haskell

Vim configuration files for Haskell code
Vim Script
32
star
25

vim-textobj-syntax

Vim plugin: Text objects for syntax highlighted items
Vim Script
29
star
26

vim-version-manager

curl https://raw.githubusercontent.com/kana/vim-version-manager/master/bin/vvm | python - setup
Python
24
star
27

vim-altercmd

Vim plugin: Alter built-in Ex commands by your own ones
Vim Script
21
star
28

vim-scratch

Vim plugin: Emacs like scratch buffer
Vim Script
20
star
29

othello-js

A quick and dirty implementation of Othello (Reversi).
JavaScript
20
star
30

vim-repeat

Vim plugin: Enable to repeat last change by non built-in commands
Vim Script
18
star
31

vimup

Tool to automate to upload vim scripts to www.vim.org
Ruby
18
star
32

vim-flymake

My own version of flymake.vim originally written by Daisuke Ikegami
Vim Script
18
star
33

vim-textobj-datetime

Vim plugin: Text objects for date and time
Vim Script
17
star
34

vim-doc

An online viewer for Vim :help documents
Ruby
15
star
35

vim-textobj-diff

Vim plugin: Text objects for ouputs of diff(1)
Vim Script
14
star
36

vim-narrow

Vim plugin: Emulate Emacs' narrowing feature
Vim Script
14
star
37

vim-gf-diff

Vim plugin: Go to the changed block under the cursor from diff output
Vim Script
14
star
38

TokyoVim

Vimに関する何かをやる会。
12
star
39

vim-ku

Vim plugin: An interface for anything
Vim Script
12
star
40

hatokurandom

A utility to choose a supply for HEART of CROWN.
JavaScript
12
star
41

reading-vimrc

vimrc読書会資料集
Vim Script
10
star
42

vim-surround

Vim plugin: Operators to edit surrounding text
Vim Script
10
star
43

vim-textobj-jabraces

Vim plugin: Text objects for Japanese braces
Vim Script
10
star
44

py-monad

An implementation of monad in Python
Python
9
star
45

vim

Vim with my hacks
C
8
star
46

vim-smarttill

Vim plugin: Smart motions, till before/after a punctuation
Vim Script
8
star
47

vim-textobj-help

Vim plugin: Text objects for Vim help documents
Vim Script
8
star
48

vim-better-tag-jump

Vim Script
7
star
49

vim-wwwsearch

Vim plugin: Search WWW easily from Vim
Vim Script
7
star
50

keyremap4macbook

Copy of KeyRemap4MacBook with some my hacks.
C++
7
star
51

vigorsh

vi-like text editor based on Gauche
6
star
52

vim-exjumplist

Vim plugin: Extra commands for jumplist
Vim Script
6
star
53

vim-metarw-git

Vim plugin: metarw scheme for git repository
Vim Script
6
star
54

evolution-js

A reproduction of the Evolution game from the book Land of Lisp by Conrad Barski.
JavaScript
6
star
55

vim-xire

Vim metaplugin: eX command Is Root of all Evil
Scheme
5
star
56

vim-skeleton

Vim plugin: Skeleton for newly created buffers
Vim Script
5
star
57

vim-grex

Vim plugin: Operate on lines matched to the last search pattern (:g/re/x)
Vim Script
5
star
58

vim-operator-siege

Vim plugin: Operators to besiege text
Vim Script
5
star
59

vim-g

Vim plugin: Misc. utilities for Git
Vim Script
5
star
60

vim-bundle

Vim plugin: Load a series of files easily
Vim Script
5
star
61

vim-vcsi

Vim plugin: Version Control System Interface
Vim Script
4
star
62

kuy-vim-fuzzyjump

Manually forked repository for kuy's fuzzyjump.vim
Vim Script
4
star
63

vim-monad

An implementation of monad in Vim script
Vim Script
4
star
64

fnfnen

A web-based Twitter client (deprecated; see https://github.com/kana/fnfnen3 instead)
JavaScript
4
star
65

chat.vim-users.jp-log-converter

Text-to-HTML converter for logs of chat.vim-users.jp
Ruby
4
star
66

vim-advice

Vim plugin: Alter the behavior of a command in modular way
Vim Script
3
star
67

vim-metarw-esa

Vim plugin: metarw scheme for esa posts
Vim Script
3
star
68

vim-mru

Vim Script
3
star
69

vim-pixivision

P <P
Vim Script
3
star
70

metastagram

In respect for june29
JavaScript
3
star
71

mduem

Little utility for little software development
Vim Script
3
star
72

vim-xml-move

Vim plugin: Support moving around various objects in XML documents
Vim Script
3
star
73

nanoc-lab

A personal repository to experiment with Nanoc.
Ruby
2
star
74

splatoon

%&$*!)%&@)!
JavaScript
2
star
75

vim-xml-autons

Vim plugin: Automatic :XMLns by the current contents of buffers
Vim Script
2
star
76

vim-exfiletype

Vim plugin: :filetype wrapper for reliable configuration
2
star
77

py-llll

LINQ-like list processing library in Python
Python
2
star
78

vim-ctxabbr

Vim plugin: Context-sensitive abbreviations
2
star
79

vim-ku-metarw

Vim plugin: ku source for metarw
2
star
80

vim-ku-args

Vim plugin: ku source for argument list
2
star
81

ypns

JavaScript
2
star
82

vim-ku-quickfix

Vim plugin: ku source for quickfix list
2
star
83

gauche-test-gasmine

Jasmine-like behavior driven development tool for Gauche
Scheme
2
star
84

vim-ku-bundle

Vim plugin: ku source for bundles
2
star
85

heroku-varnish-test

A Sinatra application to test Varnish on Heroku, but it doesn't work. Why?
Ruby
2
star
86

vim-obedient

Vim Script
1
star
87

ddh0313

Ruby
1
star
88

colors

A quick-and-dirty sketch of a board/card game
JavaScript
1
star
89

vim-slacky

Update Slack status with fancy stuffs
Vim Script
1
star
90

sudokush

Shell to solve Sudoku, written in Haskell
Haskell
1
star
91

vim-tag-php

vim-tag-user plugin for PHP
Vim Script
1
star
92

shephy-js

JavaScript
1
star
93

prafbe

JavaScript
1
star
94

vim-sasara

1
star
95

glitchr

Shell
1
star
96

ruby-arake

Run rake automatically whenever any dependent is updated.
Ruby
1
star
97

vim-perproject

Vim plugin: per-project configuration
1
star
98

slack-review-counter

Do you remember how many pull requests have you reviewed in your life?
JavaScript
1
star
99

vim-rx

1
star
100

vim-idwintab

Vim Script
1
star