Questions tagged [object-motions]

Question about text object motions

Filter by
Sorted by
Tagged with
7 votes
2 answers
496 views

How can I shift only inner contents of HTML element?

How can I quickly shift only inner contents of HTML tag X, when they are on separate lines to the opening and closing X tag? Example below: I want to shift only 2 lines with <p> tags when the ...
6 votes
2 answers
893 views

Why does dt$ not delete until the end of line?

I understand that the right way to delete until the end of line is d$, but why does dt$ not work also?
  • 1,961
6 votes
3 answers
908 views

Why does replace not accept a motion?

A lot of operator like delete, change, indent, switch-case accept a motion to apply on. For example, let say I want to replace the current word with all letter a, I do: viwra Compared to the ...
  • 15.4k
6 votes
4 answers
160 views

How can I delimit sentences by carriage return?

I write screenplays with fountain. Dialogue syntax looks like this: THE TERMINATOR Hasta la vista. Baby. I would like to be able to select the sentence: Hasta la vista., without also selecting THE ...
  • 181
5 votes
3 answers
934 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, ...
4 votes
3 answers
283 views

How to join lines within a block with `J`?

I want to join all the lines within a {} block. { 'a': 1, 'b': 2, 'c': 3, } ⬇︎ { 'a': 1, 'b': 2, 'c': 3, } Since J doesn't take a range, like d or c, the best command I found to do this is ...
3 votes
1 answer
622 views

Remap standard motions

I have a file formatted like this +---------------------------------+ | Text text text | | Text text text | | Text text text | +---------------------...
3 votes
1 answer
80 views

Why doesn't gJip turn a paragraph into a line?

Is there a good reason why gJip doesn't turn a paragraph into a line? If not, how could I make it work that way?
  • 3,089
3 votes
1 answer
107 views

Word motion and dots behaves differently in bash scripts

If I have a test.py and a word with dots, w motion goes through each "subword". If I have a test.sh and the same word with dots, w skips the dots. How do I debug this to know what is causing this ...
3 votes
1 answer
245 views

Abort an operating pending mapping

When creating an operator pending mapping in vim, it is possible make the mapping work on an arbitrary (consecutive) piece of text. I am looking for a way to abort the operation. For the case of ...
  • 932
3 votes
1 answer
100 views

How do I move by paragraphs, but end up *in* the paragraph?

So I often use repeated invocations of gqip to re-wrap paragraphs of text or comments. Unfortunately, the quickest way I've memorized for moving between paragraphs, }, lands me between them: Qui⁁ut ...
2 votes
4 answers
697 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 ...
  • 934
2 votes
1 answer
444 views

Automatically jump to text object during `ci(`

Suppose my cursor is at the beginning of the line of code: def f(a, b, c, d, e): If I want to change inside the parenthesis using the text object command ci(, I need to first navigate to some ...
  • 123
2 votes
1 answer
63 views

Is there a motion to select the comment block under the cursor?

One thing that I often need to do is reformat a code comment with gq or gw. For example, I often want to convert something like this: // Lorem ipsum // dolor // sir // amet int foo(int x) { ...
  • 203
2 votes
1 answer
69 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 ...
  • 934
2 votes
1 answer
108 views

delete from current position to end of paragraph when using hard wrap

i use hard wrap (in my vimrc: setl fo+=atw). I often want to delete from the middle of some row to the end of the paragraph. I do this as follows: d$, j (down one line), 5dd (if there are 5 subsequent ...
2 votes
1 answer
117 views

Interaction of object-select with double quotes

I'm trying to understand logic of text-object-selection in the presence of double qoutes. In the following lines * denotes cursor position, // denotes my comments. a"b(c*d)e"f //di) deletes ...
  • 123
1 vote
1 answer
224 views

text object for highlighted text

If I have a file that contains this_is_the_first_underscore_phrase this_is_the_first_underscore_phrase I search for "first" /first and my cursor is placed onto the start of the word "first". I know ...
  • 1,797
1 vote
2 answers
31 views

make da( or dab remove lagging whitespace like daw

TL;DR: da( doesn't delete the following space like daw does. Can I make this do what I want easily? I have some sample lines (cursor is shown as |): 1. Sample line (extraneous| statement) in notes. 2. ...
1 vote
2 answers
117 views

Changing content within the specified [count] number of braces for each line

I need to change the content within a [count] number of braces for each line in my buffer. 1 {Lorem} ipsum dolor {amet} blah blah {change this text} more blah blah 2 Hello. The {sun} rises in {the} ...
1 vote
1 answer
24 views

<esc>v$ without trailing space?

I want to use $ in visual mode but it always includes a trailing space (even if there isn't one on the line). How do I make it so $ only goes to the actual last letter?
  • 167
1 vote
1 answer
83 views

Inner-object possibilities

What are the possible uses of the inner-something command in vim? For example, the following three items work: ci) in ("hello") ci' in 'hello' ci] in ([var]) But the following two do not: ci# in # ...
  • 2,007
1 vote
2 answers
223 views

visual line mode is ended by inner block motion

When I do Vi{y to select inside a { block and yank it, it doesn't paste how I expect. I noticed that after V (which puts me into VISUAL-LINE mode), the i{ object takes me into VISUAL mode. Here's a ...
  • 1,797
1 vote
1 answer
96 views

onoremap: defining a bounded region

I want to craft a custom operator-pending motion if for functions in R language that look like this: doSomething <- function(arg1, arg2, ...) { doStuff(...) } The idea is to be able to press ...
1 vote
1 answer
62 views

Act on lines changed by previous command

Is there a way to target the set of lines changed in the previous command? Say I do a search and replace, bulk indent, or some other command that affects either a series or scattered collection of ...
  • 2,175
1 vote
0 answers
36 views

How to do a motion without leaving history (in .)?

Often, you do a complicated motion, which you want to repeat soon by pressing . but carry out a simpler motion overwrites that one. Can I keep that complicated motion in . itself ? Concrete example: ...
  • 43
1 vote
0 answers
60 views

Vim Text object and parentheses [duplicate]

I have a trouble with text objects and parentheses. For example with this sentence: <bla bla="test">(hello)</bla> With the cursor at the beginning of the line, when I use ci" ("change ...
  • 21
1 vote
0 answers
204 views

How to customize object-motions?

Text object motions are useful to move around in a file. Although these motion commands were specifically created for text (novel) writers, they can also be used in C source code. The commands gd and ...
  • 1,602
0 votes
2 answers
2k views

How to create a lua function that gets called for a vim (neovim) motion

Vim has the concept of actions, which can act on text objects via motions. For example diw will delete (the action) the inner word (the motion). I want to create a function that can be applied/...
0 votes
1 answer
40 views

"Visual around two Words"?

If I type 2daW, I can delete the current Word and the next (though I can't really see that case covered in the manual). Is there a way to visual-select around two words? I tried 2vaW, but of course (...
  • 335
0 votes
1 answer
47 views

How to select a whole line except beginning tab/space and last enter?

I'm dealing with the following text and want to select "abc def": 123 abc def 456_4 I've tried viw but it can only select a whole word isolated by spaces, and v$ starting with ...
0 votes
1 answer
81 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, ...
  • 2,663
0 votes
2 answers
57 views

Extract JavaScript variable (feature example): how to improve it?

I am a Vim newbie with one week experience and I'm already enjoying it. I've successfully written an (ugly) command+function+mapping with which I can extract some code to a new variable in JavaScript....
  • 113