31
votes
Accepted
Why does dt$ not delete until the end of line?
Because t takes a character, so it looking for a literal $ character, not a motion like end of line
7
votes
Accepted
text object for highlighted text
You can do:
gnc
gn will do a visual selection of the search result, then c is, as you know, change.
Also, cgn works (change the next occurence of the search result).
6
votes
Accepted
Automatically jump to text object during `ci(`
The wellle/targets.vim plugin should do what you're looking for (and much more). This allows you to explicitly tell vim to go to the next parenthesis (with cin(, n for next parenthesis), or the last ...
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
Accepted
Remap standard motions
If you start with this normal mode mapping:
nnoremap <buffer> $ f\|ge
The visual-mode mapping is identical:
vnoremap <buffer> $ f\|ge
Then, for operator-pending mode (like after d, y, ...
5
votes
Why doesn't gJip turn a paragraph into a line?
The answer is simple: gJip doesn't work, because gJ is not an operator. See :h operator for which operators exist. The easy workaround is to use visual mode, and then join all the lines, e.g. use ...
5
votes
Why does dt$ not delete until the end of line?
t (and its variants T, f and F) take a single character afterwards to denote the target of motion within the line.
So the effects of the two commands are:
d$ - delete to end of current line
dt$ - ...
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
Word motion and dots behaves differently in bash scripts
This comes down to the iskeyword setting. When I run :set iskeyword? in a bash file, I get this:
iskeyword=@,48-57,_,192-255,.
When I run the same command with a python file, I get this:
iskeyword=@...
5
votes
How to join lines within a block with `J`?
This is called "a motion". Even though linewise motions result in a line range.
Normally, it's enough to do 5J and there's no need for "join" operator. However, if you really want it, you can make ...
4
votes
Accepted
Why does replace not accept a motion?
Actually. There is no reason, apart from things being as they are, that would be against an r operator. The simple fact that viwra works means that riwa could work. The reason is simply a historical ...
4
votes
Accepted
How can I shift only inner contents of HTML element?
That's a great opportunity to leverage text objects (see :help text-objects). The following code extends the normal behavior of the it text object (see :help it and :help tag-blocks) to make it ...
4
votes
How can I delimit sentences by carriage return?
If you tried reedes/vim-textobj-sentence, that (hopefully) means you have kana/vim-textobj-user installed. You can (mostly) trivially use this to define your own sentence. Treat this as a starting ...
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
"Visual around two Words"?
You can of course use v2aw, v3aw and so on as described in the :h text-objects where aw is a text object that accepts count.
You can also compose viw and e. Like viwe for 2 words, viw2e for 3 words ...
4
votes
Accepted
delete from current position to end of paragraph when using hard wrap
You can use the } motion, which moves forward a paragraph, together with d, as in d}.
This will delete from the cursor position until the next blank line (not including the blank line itself), which I ...
4
votes
Why doesn't Vim recognize a pair of <\> as a single unit?
I have noticed that regression, too, which seems to affect all text objects with single character boundaries:
i<
i"
i'
i{
etc.
You should report it if it hasn't been reported already.
EDIT
...
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
Accepted
Abort an operating pending mapping
This works for me:
:function! Foo()
call feedkeys("\<esc>")
return
:endfunction
This works since you can hit esc in operator pending mode (for example, c<esc>), and it will not ...
3
votes
Accepted
Is there a motion to select the comment block under the cursor?
If using plug-ins is acceptable to you, then the vim-commentary plug-in can help you.
It defines a gc text object to select a comment, which you can use in operator pending mode. Use gqgc anywhere in ...
2
votes
Accepted
onoremap: defining a bounded region
Have you looked at Quick search, limited to a C++ function all the techniques presented in this discussion shall apply to your question. I'm not sure my solution is checking the cursor is within a ...
2
votes
Act on lines changed by previous command
As @romainl said, you can use the [ and ] marks for this purpose, e.g.:
nnoremap gc `[v`]
Pressing gc visually select the previous change.
:'[,']s/var_name/varName/g
Replace in the last modified ...
2
votes
Why does replace not accept a motion?
Not an answer, but a piece of code I used to "simulate" the functionality of an operator with r:
function! ROperator()
call inputsave()
let l:replace_pattern = input('Replace > ')
call ...
2
votes
Why does replace not accept a motion?
Replace is a specific type of situation, that I don't believe is equivalent to the others you listed that take motions. r can take an optional count, but the action is the same. 3ra replaces 3 ...
2
votes
Accepted
How can I delimit sentences by carriage return?
Update: Well, I made a plugin. Get it from ctholho/vim-textobj-sentence-line.
The plugin supports is and as motions. I didn't test all possible conditions but it does the job reliably. It also remaps ...
2
votes
Accepted
Changing content within the specified [count] number of braces for each line
The answer from @RubenWesterberg is a correct sequence of Normal mode commands to do what you want. But I read your request to not move the cursor a little more literally. Also, if you need to make ...
2
votes
Accepted
Inner-object possibilities
All of the text-objects are documented under :help text-objects.
Excerpted from :help objects:
|v_iquote| i" double quoted string without the quotes
|v_i'| i' single quoted ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
object-motions × 38cursor-motions × 19
visual-mode × 5
custom-text-object × 4
vimscript × 3
key-bindings × 3
cut-copy-paste × 3
normal-mode × 3
vimrc × 2
neovim × 2
range × 2
map-operator × 2
lua × 2
regular-expression × 1
indentation × 1
substitute × 1
cursor-movement × 1
functions × 1
replace × 1
folding × 1
formatting × 1
macvim × 1
repeated-commands × 1
filetype-html × 1
count × 1