Questions tagged [custom-text-object]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
32
votes
5answers
2k 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 ...
30
votes
4answers
485 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 ...
12
votes
2answers
2k views

Is there a text object for current line?

Is there a text object for current line? Is there a text object for ^$?
11
votes
2answers
202 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 ...
8
votes
1answer
528 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 ...
8
votes
1answer
74 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. ...
6
votes
2answers
741 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 ...
5
votes
2answers
494 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 ...
5
votes
1answer
157 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(...
4
votes
1answer
131 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': ['%<', '%'...
3
votes
3answers
342 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, ...
3
votes
2answers
132 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$ ...
3
votes
1answer
83 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 ...
2
votes
2answers
177 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 ...
2
votes
1answer
66 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 ...
2
votes
1answer
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, ...
2
votes
1answer
28 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 ...
2
votes
1answer
62 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 ...
2
votes
0answers
33 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. ...
2
votes
0answers
100 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 ...
1
vote
2answers
468 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 ...
1
vote
3answers
72 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 ...
1
vote
2answers
58 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]));...
1
vote
3answers
247 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. ...
1
vote
1answer
49 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> ...
1
vote
1answer
40 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 ...
1
vote
0answers
115 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 ...
1
vote
0answers
71 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 ...
0
votes
2answers
39 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 ...
0
votes
1answer
67 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 ...
0
votes
1answer
10 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) ...
0
votes
1answer
55 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 ...
0
votes
1answer
60 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, ...
0
votes
1answer
59 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 ...