This plugin is no longer being maintained. Check out targets.vim instead, which does everything this does plus more.
This plugin adds various symbols as delimiting text-objects.
Block delimiters are symbols that mark the beginning and end of a region of
text. With Vim's text-objects, these delimited text sections can be edited
with operators and motions. The block delimiters that Vim already support
include (parentheses)
, [brackets]
, {braces}
, "double quotes"
,
'single quotes'
, <angled brackets>
, and <a>tags<\a>
. This plugin adds
several additional block delimiters.
This plugin depends on Kana's plugin vim-textobj-user, so it should be installed if not already done so.
Install using your favorite package manager, or use Vim's built-in package support:
mkdir ~/.vim/pack/plugin/start/vim-textobj-user
git clone https://github.com/kana/vim-textobj-user.git ~/.vim/pack/plugin/start/vim-textobj-user
mkdir ~/.vim/pack/plugin/start/vim-textobj-delimiters
git clone https://github.com/EvanQuan/vim-textobj-delimiters.git ~/.vim/pack/plugin/start/vim-textobj-delimiters
- Add
Plug 'kana/vim-textobj-user'
to yourvimrc
file. - Add
Plug 'EvanQuan/vim-textobj-delimiters'
to yourvimrc
file. - Reload your
vimrc
or restart. - Run
:PlugInstall
- Add
Plugin 'kana/vim-textobj-user'
to yourvimrc
file. - Add
Plugin 'EvanQuan/vim-textobj-delimiters'
to yourvimrc
file. - Reload your
vimrc
or restart. - Run
:BundleInstall
- Add
NeoBundle 'EvanQuan/vim-textobj-delimiters'
to yourvimrc
file. - Add
NeoBundle 'kana/vim-textobj-user'
to yourvimrc
file. - Reload your
vimrc
or restart. - Run
:NeoUpdate
git clone https://github.com/kana/vim-textobj-user.git ~/.vim/bundle/vim-textobj-user
git clone https://github.com/EvanQuan/vim-textobj-delimiters.git ~/.vim/bundle/vim-textobj-delimiters
The following symbols are now recognized as block delimiters, marking the start and end of a region of text:
Symbol | Name |
---|---|
* | asterisk |
\ | backslash |
: | colon |
$ | dollar sign |
= | equal sign |
- | minus sign/dash |
% | percent sign |
. | period |
| | pipe |
+ | plus sign |
? | question mark |
/ | slash |
_ | underscore |
But what about commas?
vim-textobj-parameter provides support for function parameters or comma-separated lists.
Similar to how quotes, parentheses, and brackets amongst other block
delimiters can mark the start and end of a region of text and can have edited
with the 'c' (change), 'd' (delete), 'v' (visual) and 'y' (yank) operators,
vim-textobj-delimiters provides several new text-objects which are triggered
by a
and i
motions. While there may be any number of uses for these
delimiters, here are some examples for where they may be used.
Selections of text surrounded by asterisks (*) is fairly common in markdown
files, marking *italicized*
or **bold**
text.
In Windows-style path names, directories are separated\with\backslashes
.
For Vim modelines, values are delimited with colons, such as:
vim:tw=78:ts=8:ft=help:norl:
Certain tags, such as markdown emojis are also also delimited with colons: >
:sunrise_over_mountains:
In LaTeX files, inline math mode is delimited with $single dollar signs$
,
while $$double dollar signs$$
delimits display math mode.
In certain text formats, titles are delimited with equal sign:
=== such as this ===
Languages like Lisp and css often use kebab case variable names, which
separate-words-with-dashes
. In webiste URLs, text of certain directories or
titles are often in kebab case as well.
In some web templates, language boundaries are
<% surrounded with template delimiters such as this %>
In many programming languages, periods denote member variables of a class or
object, be it an attribute or method. If these member variables are written in
snake_case
, or kebab-case
, then using word or WORD text-objects will
not be enough to edit them. For example:
foo.delete-this.bar
foo.delete_this.bar
Hot-links in Vim help documentation and markdown tables delimit text with pipe characters.
For example, suppose you have the following markdown table:
| Cats | Dogs |
|:------------:|:--------:|
| Mr. Whiskers | Snuffles |
| Oscar | Bella |
If you want to change 'Mr. Whiskers' to 'Tigger', you can do the following (cursor position marked by *):
| Mr. Wh*iskers |
and type ci|
to get |*|
, where you can make your
replacement | Tigger |
.
Another example is if you are writing Vim help documentation and have a hot-link, which is a word surrounded with pipes as such:
|bad tag|
If you want to delete the hot-link, you can do the following (cursor position marked by *):
|bad*tag|
and type da|
, which will delete the hot-link.
In mathematical expressions or string concatenation, certain text may incidentally be delimited with plus signs such as:
a = 4 + 457 + 12
message = "Hello" + "there" + "General" + "Kenobi"
Admittedly, there does not seem to be much use to this as the quote and word text objects can achieve the same thing.
In XML, processing instructions are
<? delimited with question marks ?>
In website URLs and Unix-style path names, directories are
separated/with/slashes
.
Languages like C, Python, and Ruby often use snake case variable names, which
separate_words_with_underscores
. In website URLs, text of certain
directories or titles are often in snake case as well.