Skip to main content
15 votes
Accepted

How to visually select based on indentation?

I've used vim-indent-object for a while with some success. It provides text objects like ii, ai, iI, and aI, each with slightly different semantics. For your sample code def some_method if @foo ...
D. Ben Knoble's user avatar
  • 27.2k
10 votes
Accepted

Change text between two $ symbols

If you want only $ to be a text object, then do the following xnoremap i$ :<C-u> normal! T$vt$<CR> onoremap i$ :normal vi$<CR> xnoremap a$ :<C-u> normal!F$vf$<CR> ...
3N4N's user avatar
  • 5,864
6 votes

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

To delete the current fold, you simply have zd for instance Otherwise, you could also define an operator-pending mode mapping with for instance: :onoremap iz :<c-u>normal! [zV]z<cr> ...
Luc Hermitte's user avatar
  • 17.7k
6 votes
Accepted

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

There is no text object for folds in vim, but there is a plugin which provides them, az/iz: https://github.com/kana/vim-textobj-fold Here are vanilla alternatives: vi{/va{. This may or may not ...
Mass's user avatar
  • 14.2k
6 votes

Is there a text object for current line?

I would suggest an additional solution, to use ^ instead of 0 (so the line starts at the beginning of the first character: xnoremap il g_o^ onoremap il :normal vil<CR> xnoremap al $o^ onoremap ...
Blasco's user avatar
  • 275
5 votes

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

You can add your own syntax element (probably overriding existing one): syntax match quoteblock /"[^"]\+"/ contains=@NoSpell syntax match: Tells vim this is a syntax command quoteblock: The name of ...
Maxim Kim's user avatar
  • 13.8k
5 votes

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

For the general case, you can try creating new operators, gs and ge: function! GoStart(type) abort normal! `[ endfunction function! GoEnd(type) abort normal! `] endfunction nnoremap <silent&...
Rich's user avatar
  • 32.4k
5 votes
Accepted

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

Consider if you were doing some operation in visual mode for deleting in a word, you would use the following to put the deletion in register a. viw"ad -> v [iw] ["a] d ...
Mass's user avatar
  • 14.2k
4 votes
Accepted

How to remap ci$

Since i$ is a mapping itself (defined by the vimtex plug-in), you need a recursive mapping to be able to use i$ as part of the expansion of your mapping. So this should work: nmap cim ci$ But you ...
filbranden's user avatar
  • 29.6k
4 votes

Using Text Objects with vimtex

I think you do not really understand what a text object is. I therefore recommend that you read :h text-objects. When you have read and understood this, you should be able to understand the vimtex ...
Karl Yngve Lervåg's user avatar
4 votes

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

This doesn't answer your more general question about text objects, but you can achieve the behaviour in your specific indentation-based example with folds: setlocal foldmethod=indent setlocal ...
Rich's user avatar
  • 32.4k
4 votes
Accepted

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

The vim-textobj-xmlattr plugin does exactly that. This vim plugin provides two text objects: ax and ix. They represent XML/HTML attributes. ix works with the inner attribute, with no surrounding ...
Igor's user avatar
  • 56
4 votes
Accepted

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

Vim only solution The simplest thing for the example you posted is probably to use visual linewise mode - va)Vwill first select the content and the surrounding parenthesis (but not the word in front) ...
mattb's user avatar
  • 1,161
3 votes
Accepted

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

You can try this: vip<Ctrl-v>I//<ESC> vip select paragraph <Ctrl-v> make selection blockwise I// insert // into begining of a selection block PS: I would suggest to use vim-...
Maxim Kim's user avatar
  • 13.8k
3 votes

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

Plugin vim-ninja-feet by tommcdo Currently, this plugin provides following square bracket mappings (do not overlook the square in the definition): {operator}[{text object} ...
Hotschke's user avatar
  • 4,830
3 votes

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

Define syntax match gitcommitBody for the custom text object syntax Install vim-textobj-user and vim-textobj-syntax. The default syntax file for gitcommit does not define gitcommitBody. Place ...
Hotschke's user avatar
  • 4,830
3 votes

Is there a text object for the entire buffer?

Recommended Solution Created by @filbranden in response to my question here " Create text-object `A` which operates on the whole buffer (i.e. All) " Keeps the cursor position in the same position ...
run_the_race's user avatar
3 votes

Selector for line of text?

Here's an il operator that behaves like iw but selects a line, from first to last non-blank character in the line: function! SelectLine(count) abort normal! gv if visualmode() !=# 'v' normal! ...
filbranden's user avatar
  • 29.6k
3 votes
Accepted

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

UPDATE: Latest vimtex includes PR #1711 which allows you to configure vimtex to override existing mappings by setting this global variable from your vimrc: let g:vimtex_mappings_override_existing = 1 ...
filbranden's user avatar
  • 29.6k
3 votes
Accepted

How to copy between two '##'

I think your approach is correct, but some tweaks might be needed: function! BlockCopy(pattern) call search('^' .. a:pattern, 'cbW') normal! 0V let l:bottom = search('^' .. a:pattern, 'nW')...
r_31415's user avatar
  • 576
3 votes
Accepted

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

When using "a something" text objects (at, a(, etc.) in visual mode, you can generally keep using them to expand the visual selection. In this case, you should be able to do vatat to select ...
romainl's user avatar
  • 41.8k
2 votes

How can I treat LaTeX quotes as a text object?

I spent a bit of time today throwing together some code for this exact purpose, and since the existing answers either use plugins or are slightly fragile, I figured I may as well post it here. To use ...
orthocresol's user avatar
2 votes

How can I treat LaTeX quotes as a text object?

Plugin vim-sandwich Another useful plugin for this is vim-sandwich which has defined ft-specific surroundings l` or l' for `text', l" for ``text'' and textobjects to easily operate on them. With ...
Hotschke's user avatar
  • 4,830
2 votes

change inner backslashed quotes

This could be implemented using: https://github.com/kana/vim-textobj-user Lots of existing plugins are close to this behavior, but none seems to answer the question yet.
Charles Gueunet's user avatar
2 votes
Accepted

define a text object as the boundary of two marks

Here is an example for a custom text object working with the marks a and b. " char-wise onoremap am :<c-u>execute 'normal `av`b'<cr> xnoremap am :<c-u>execute 'normal `av`b'<cr&...
Ralf's user avatar
  • 9,337
2 votes
Accepted

Selecting code chunk in Rmarkdown

This seems like a prime case for a text object, but unfortunately, Vim doesn't recognize ```{R} or ``` as text object delimiters. There's at least three options that do work: 1. Click and drag with ...
8bittree's user avatar
  • 1,546
2 votes
Accepted

Selector for line of text?

The fastest I can come up with is really ^vg_ to be precise about start and end of line. But, by way of challenge, perhaps you really need dd, yy, cc, or similar? Even guu and g~~ work. If you can ...
D. Ben Knoble's user avatar
  • 27.2k
2 votes
Accepted

Is there an instant way of editing matching inner tags?

text-object (say mt) that selects the name of matching tags? It's hard to think about handling this one with a text object, because a text object is all about selecting some text and then the ...
filbranden's user avatar
  • 29.6k
2 votes

Is there an instant way of editing matching inner tags?

I found that something like that is possible with the plugin tpope/vim-surround. <di█ id="foo"> <div class="bar"> </div> Or: <div id="foo"> █ <div class="bar">&...
lpf's user avatar
  • 43
2 votes

How to remap ci$

You can also put the following in your .vimrc: xmap dsm <plug>(vimtex-env-delete-math) xmap csm <plug>(vimtex-env-change-math) xmap am <plug>(vimtex-a$) xmap im &...
mahbubweb's user avatar
  • 602

Only top scored, non community-wiki answers of a minimum length are eligible