19 votes
Accepted

Is there a text object for current line?

Here are crude "line" text objects: xnoremap il g_o0 onoremap il :normal vil<CR> xnoremap al $o0 onoremap al :normal val<CR> And a crude "buffer" text object: xnoremap ...
romainl's user avatar
  • 39.9k
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
  • 25.7k
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,604
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.2k
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
  • 14k
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

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
  • 31.6k
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
  • 13k
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
  • 14k
5 votes
Accepted

Define text object that depends on the current operator

The following example comes close to what you are asking for: onoremap <expr> w '<esc>' . v:operator . v:count1 . (v:operator ==# 'd' ? 'aw' : 'iw') It creates a textobject w that is ...
Enno's user avatar
  • 211
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
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
  • 28.6k
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
  • 31.6k
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,091
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,740
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,740
3 votes

textobj-user: must the patterns be different?

This is actually a know issue (see issues #2 and #15 in the plugin bug tracker). The author of the plugin suggested a workaround of the following form: call textobj#user#plugin('handyobjects', { \ ...
statox's user avatar
  • 49.6k
3 votes

How can I treat LaTeX quotes as a text object?

This is an old question but for the benefit of future visitors: I find its easier to change the latex quotes with: \usepackage{csquotes} % change " " into nice double quotes \MakeOuterQuote{"} And ...
user10607's user avatar
  • 175
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
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
  • 13k
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
  • 28.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
  • 28.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
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,740
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

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
  • 592
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,147
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,527

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