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
...
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>
...
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>
...
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 ...
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 ...
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 ...
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&...
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
...
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 ...
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 ...
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 ...
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 ...
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) ...
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-...
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}
...
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 ...
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
...
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! ...
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
...
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')...
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 ...
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 ...
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 ...
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.
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&...
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 ...
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 ...
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 ...
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">&...
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 &...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
custom-text-object × 46cursor-motions × 14
visual-mode × 7
key-bindings × 6
object-motions × 6
cut-copy-paste × 5
filetype-tex × 4
map-operator × 4
plugin-textobj-user × 4
cursor-movement × 3
vimrc × 2
visual-block × 2
plugin-vimtex × 2
filetype-html × 2
operator-pending-mode × 2
vimscript × 1
neovim × 1
search × 1
indentation × 1
autocmd × 1
normal-mode × 1
folding × 1
filetype × 1
spell-checking × 1
filetype-markdown × 1