Skip to main content

Questions tagged [custom-text-object]

Filter by
Sorted by
Tagged with
1 vote
1 answer
31 views

Use textobject selection with nnoremap

I hope this is not an XY problem, but I need the following thing: I have parameterized markdown fences (in vimwiki), i.e: ```c int a = 5; printf("%d", 5 <++>) ``` So my idea is when ...
Fedja's user avatar
  • 77
1 vote
1 answer
88 views

Setting change/visual marks with empty inner motion in custom text objects

This has been discussed on Vim’s issue tracker. By default for the default builtin motions where the 'indside' of a text object is empty - such as double quote (say we have the following text "&...
user2742982's user avatar
0 votes
1 answer
59 views

How can expand and contract visual selection from a tag block?

Say I have hierarchical markup like this: <div id="level_1"> <div id="level_2"> <div id="level_3"> watermelon </div> </div>...
Sasgorilla's user avatar
1 vote
2 answers
52 views

Is there a plugin that provides a new text element that works on single AND double quotes?

I have a common task which is refactoring typescript import statements. However sometimes the quotes used for the dependency path are single quotes and sometimes double quotes. this means when i go ...
Steven Lu's user avatar
  • 2,281
1 vote
1 answer
82 views

How to define text-object of "between markdown code fence with syntax"?

I want to create a binding for using vim-slime to run code between a code fence in markdown. This worked with a simple fence, using i` as a text-object: nmap <leader>s7 <Plug>...
fbence's user avatar
  • 707
1 vote
1 answer
52 views

Make operator that doesn't change gv

I'm trying to redefine my inner and outer line text objects so that they don't change gv. First I had onoremap <silent> il :<C-u>normal! $v^<CR> I changed it based on Using visual ...
minseong's user avatar
  • 2,393
3 votes
3 answers
626 views

How to select the next text object?

How can I move to the next text object? E.g. with cursor on the first , in {}, {}, {} ^ then calling va} selects the middle {}. This is the behaviour I want to be able to achieve consistently, even ...
minseong's user avatar
  • 2,393
0 votes
1 answer
173 views

How to remap default vim text-object keys to different keys like ' to n

I use ci', va" pretty often, I would like to map text-object keys like " ' to more accessible keys like m, n since writing cin, vam is much easier than ci' va". I tried the following ...
ytkimirti's user avatar
2 votes
2 answers
383 views

Copy content inside brackets and the word in front of bracket (i.e. a text object for function calls)

Quite often I copy or remove content inside brackets d% or y%. MyAwesomeClass( ///content ) But this way I get: ( ///content ) Is there a way to copy word in front of the bracket too? So that ...
Chris's user avatar
  • 141
1 vote
3 answers
371 views

How to copy between two '##'

In vim, there is a way to yank between two quotations by using yi'. And there is a way to yank between two square brackets by using yi]. I want to do this between two ##: some_text ## Point #1 --> ...
Al-Baraa El-Hag's user avatar
3 votes
1 answer
122 views

Text Object for HTML/XML attributes, e.g. data-foo="bar baz caz"

Is there a plugin or a way to work with HTML text objects, e.g. Say the cursor is in one of the attributes below: <div data-foo="bar baz caz" class="a b c"> I wish to treat ...
run_the_race's user avatar
2 votes
2 answers
114 views

Create a new matching-tag-pair textobject?

Vim provides a builtin textobject t that captures a matched pair of HTML tags — so e.g. if you start with this <i>that█ <b>those</b></i>, then typing dat in normal mode leaves ...
Leah Velleman's user avatar
1 vote
1 answer
104 views

How to handle no content for a custom text object?

I am building custom text object in lua. With the following code, I am able to change content within certain symbols. This is my code: local in_symbol = function(start_symbol, end_symbol, mode) ...
John Winston's user avatar
1 vote
1 answer
146 views

An easier (or friendlier) way to write text object

Text objects are one of the power of Vim that I particulary like. I wanted to create my personnal text object with the p (="previous") and n (="next") parameters. For instance if I ...
Fabrice Hategekimana's user avatar
1 vote
2 answers
98 views

Text object for a field between tabs

I'd like to define a text object for tab-delimited fields in a tsv file. So far, I have vnoremap af :<C-U>silent! normal! T<Tab>vf<Tab><CR> omap af :normal Vat<CR> ...
Kamil S.'s user avatar
  • 111
2 votes
1 answer
41 views

Is a smart text object possible?

Is it possible to create a smart text object for i), i], i}, i>, i' and i"? The text object would represent the first innermost object it can find. For example, with cursor on the plus sign ...
Nathanael Weiss's user avatar
3 votes
1 answer
138 views

Disabling `kana/vim-textobj-entire` by filetype autocommand

kana/vim-textobj-entire creates text-obejcts ae and ie which stand for the entire buffer. But in lervag/vimtex ae and ie stand for an environment in a .tex file. vimtex's ae and ie mappings are much ...
mahbubweb's user avatar
  • 602
1 vote
3 answers
419 views

Selector for line of text?

To grab a full word from anywhere in the word I can do: viw And to grab an entire line from start to finish I can do: V However, is there a section that grabs all text from the first char to the ...
David542's user avatar
  • 2,465
2 votes
2 answers
756 views

Is there an instant way of editing matching inner tags?

In Vim, using the text object i>, you can edit an inner tag, and using the built-in matchit plugin, you can even use % to jump between matching opening and closing tags. Let's say you want to ...
lpf's user avatar
  • 43
1 vote
2 answers
911 views

Inserting text at the beginning of all lines selected in visual line mode [duplicate]

I have selected a JS block such as following: function map(xs: string[], cb: Function) : string[] { const result: string[] = []; for(let i = 0; i++; i < xs.length) { result.push(cb(xs[i]));...
hyde's user avatar
  • 155
7 votes
3 answers
2k views

Is there a way to "move to the beginning of the next text object"?

Suppose I have a defined text object. For example, I have a ii text block which defines all the contiguous lines around the cursor at the same level of indentation or deeper. I know what it means to, ...
preferred_anon's user avatar
1 vote
1 answer
225 views

Custom prompt message when saving file

The default message displayed on the prompt when one saves a file is "<file_name>" <nlines>L, <ncharacters>C written and it remains in the prompt until another message is to be ...
noibe's user avatar
  • 199
1 vote
1 answer
56 views

Change definition of "under the cursor" for ctags with C++ qualifiers

When jumping to a tag it seems that ":" are ignored for the purpose of "under the cursor" (I'm assuming it's "word" "under the cursor"). For example if I want to jump to myTree::Node something I ...
kabanus's user avatar
  • 163
3 votes
2 answers
274 views

How to remap ci$

I am using the plugin vimtex. It offers the functionality (from the introduction of its documentation) Text objects ic ac Commands id ad Delimiters ie ae LaTeX environments i$ a$ ...
user avatar
6 votes
1 answer
331 views

How to pass v:register to custom operator when working on custom text object?

I have a simple custom operator, it echoes v:register, it's mapped to ,f. After reading this, i creat it like this : function! s:foo(type,...) echo v:register endfunction function! s:setupOpfunc(...
dedowsdi's user avatar
  • 6,318
2 votes
3 answers
533 views

Selecting code chunk in Rmarkdown

I am writing an RMarkdown file, which is a document that is a hybrid of text and R code. Here is an example of what that document could look like: Here is an example of text within my Rmarkdown file. ...
JKing's user avatar
  • 23
8 votes
2 answers
2k views

How can I tell vim to ignore spelling errors inside quotes?

If I'm editing a text file with :set spell, is there any way to have vim not check words within the boundaries of certain characters against the word list? I want to be able to write things like ...
myc3lium's user avatar
  • 101
0 votes
2 answers
45 views

define a text object as the boundary of two marks

Is there a way to turn the "region bounded by two specific marks" into a text object similar to aw or ap? I've been messing around with vi and found it convenient to use a and b. and define a region ...
Greg Nisbet's user avatar
  • 1,889
2 votes
0 answers
41 views

Do operator ranges/movements/textobjects always overwrite the last visual selection? workaround?

In vim, when I operate on a textobject from a plugin, say the 'inner indent' typed ii from kana/vim-textobj-indent, my last visual selection ('>, '<) is reset to where the operator worked on. ...
simlei's user avatar
  • 113
14 votes
1 answer
2k views

How to visually select based on indentation?

If someone is editing the following javascript file: let foo = true if (foo) { let bar = 42 // moooooore code... } You can use vi{ anywhere on the line with let bar to select let bar = 42 and ...
joaumg's user avatar
  • 283
0 votes
1 answer
99 views

How can I create a text object for a Python block comment?

Suppose I have some Python code with a “block comment” (i.e. multiple consecutive comment lines) in the middle of a paragraph: a = function1() # Remember: if you pass an even number to function2, ...
bdesham's user avatar
  • 3,013
1 vote
0 answers
263 views

Define new text object for snake case

I recently discovered iskeyword as in set iskeyword-=_ so that I can change just part of a snake case word, like changing character_idx to char_idx using ciw. This was working great, except sometimes ...
mas's user avatar
  • 555
2 votes
1 answer
72 views

Is there a text object or motion for non-comment lines are not separated from comment lines by blank lines? E.g., in git commit messages

Consider the text A B # C # D Is there a text object or motion that will select lines A and B if the cursor is on either, but not select lines C and D? ap or ip with the cursor on any of those four ...
cxw's user avatar
  • 974
6 votes
2 answers
1k views

Change text between two $ symbols

If there is some text between quotations, such as "x = 5" I can type ci" in normal mode to delete the text inside the quotations and switch to insert mode. I often want to perform this same action ...
Vermillion's user avatar
2 votes
1 answer
64 views

change inner backslashed quotes

I know the ci" motion and others :changes, but I need something like a ci\" in order to change inner a backslashed quotes. Assuming * as the cursor position: a = "message says: \"fo*o bar\"" I would ...
intmarinoreturn0's user avatar
3 votes
4 answers
958 views

How to select/delete/yank the contents of only the current fold?

When using foldmethod=marker, how do you select or reference exactly the contents of the current fold? I want to swap the order of two folds. If they were paragraphs, I would do dap { p. However, I ...
cxw's user avatar
  • 974
2 votes
0 answers
120 views

New text object for LaTeX subscript or superscript

Suppose in a latex file, I have a line $X_{i_{j}}$ and $Y^{i_{k}}$ My goal is to define a text object in VIM for the subscript, i.e. _{i_{j}}, and superscript, i.e. ^{i_{k}}. I was reading this ...
semibruin's user avatar
  • 121
1 vote
0 answers
73 views

Vim operation - creating a new text object selector for entire file [duplicate]

You can do dap, or vap, etc to select a paragraph. I want to be able to select/yank/delete the entire file. One way to do this would be to have: vnoremap af ggoG$ nnoremap yaf ggVGy nnoremap daf ...
Dylanthepiguy's user avatar
0 votes
1 answer
74 views

How can you turn off text highlighting (hlsearch) with custom text objects?

I am implementing a custom text object in visual mode, but this text object uses regular expressions to find the beginning and ending of the selection. However, when I do this, other parts of the text ...
magnus's user avatar
  • 427
3 votes
1 answer
1k views

Using Text Objects with vimtex

I am having trouble figuring out how to use the text objects with the vimtex plugin. The mappings with leaders and the commands in normal and insert mode are fine. But to get environments, sections, ...
user1536's user avatar
  • 131
4 votes
1 answer
159 views

textobj-user: must the patterns be different?

I'm trying to make a text-object that is a paragraph surrounded by lines containing %. To test something simpler, I tried: call textobj#user#plugin('pc', { \ 'code': { \ 'pattern': ['%<', '%'...
Toothrot's user avatar
  • 3,139
8 votes
1 answer
100 views

Define text object that depends on the current operator

I'm curious if it is possible to make a text object aware of its operator. In particular, I am writing a text object for LaTeX environments, where I want different behaviour depending on the operator. ...
Karl Yngve Lervåg's user avatar
17 votes
2 answers
4k views

Is there a text object for current line?

Is there a text object for current line? Is there a text object for ^$?
lindhe's user avatar
  • 487
11 votes
2 answers
246 views

Rectangular regions as text objects?

Is it possible to define a text object in vim that will act on a rectangular region? For instance, suppose I have vertically aligned columns of text, like this: column 1 co column 2 col lumn 1 ...
Leah Velleman's user avatar
36 votes
5 answers
4k views

Is there a text object for the entire buffer?

I often find myself typing commands like gg"+yG or ggdG and would like a more efficient way to do this without having to move the cursor twice. Is there any command that I can use e.g. y[movement] to ...
Random832's user avatar
  • 1,232
33 votes
5 answers
657 views

How can I treat LaTeX quotes as a text object?

Quotation marks in LaTeX are different than in normal text, in that they're formatted ``like this'' (or `like this' for single quotes). This makes it difficult to navigate through them in Vim. I ...
Doorknob's user avatar
  • 15.5k