Questions tagged [object-motions]

Question about text object motions

Filter by
Sorted by
Tagged with
1 vote
0 answers
52 views

Paragraph motions in single-line buffer

This question looks at how paragraph motions behave when the buffer consists of only two lines. But what if the buffer has just one line? Both { and } move the cursor to the last character of the line,...
photon.engine's user avatar
4 votes
1 answer
113 views

Why doesn't Vim recognize a pair of <\> as a single unit?

I'm kind of confused about why doesn't Vim accept di> operation on this piece of text: <This is a random text but has a backslash at the end\> but rather does on this: <This is a text with ...
nekomekoraiyuu's user avatar
2 votes
1 answer
109 views

Make { ( and ) } normal mode motions skip blank lines

Normal mode ) } and ( { navigate paragraphs and lines but they don't skip blank lines. (They land on them.) This is obviously the preferable behavior when writing code, but when writing "normal&...
Anthony's user avatar
  • 55
3 votes
1 answer
100 views

The default behavior of "di("

As is well known, di( deletes the contents inside a () block. When the cursor is not within a group of (), the cursor jumps to the near () group and delete the contents in it. Is there any way to ...
gaoqiang's user avatar
  • 143
0 votes
0 answers
42 views

Check if cursor is inside a pair of quotes

What I'm looking for is basically a programmatic version of vi", va', etc. Say my cursor is at |: function_call(arg, "stri|") I want to be able to find the location/range of the quote ...
Kyle Richards's user avatar
1 vote
2 answers
175 views

Difference between dap and dip (and inner paragraph)

I have memorized dip as the command to delete a paragraph. However, I now see that dap is also a thing. The docs say: "dip" delete inner paragraph "dap" delete a paragraph ...
Wallace Kelly's user avatar
1 vote
2 answers
4k 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/...
Danielo515's user avatar
4 votes
1 answer
253 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 ...
neverdimed's user avatar
0 votes
1 answer
51 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 ...
Mactarvish's user avatar
1 vote
0 answers
40 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: ...
4amvim's user avatar
  • 43
2 votes
1 answer
60 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 (...
usretc's user avatar
  • 375
1 vote
2 answers
32 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. ...
jeremysprofile's user avatar
1 vote
1 answer
26 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?
Tallboy's user avatar
  • 177
2 votes
1 answer
126 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) { ...
hugomg's user avatar
  • 203
4 votes
3 answers
303 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 ...
Martín Fixman's user avatar
1 vote
1 answer
178 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 # ...
David542's user avatar
  • 2,415
6 votes
3 answers
2k 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, ...
preferred_anon's user avatar
2 votes
1 answer
126 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 ...
fantom's user avatar
  • 123
3 votes
1 answer
89 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?
Toothrot's user avatar
  • 3,119
1 vote
1 answer
283 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 ...
minseong's user avatar
  • 2,291
1 vote
2 answers
292 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 ...
minseong's user avatar
  • 2,291
0 votes
1 answer
95 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, ...
bdesham's user avatar
  • 2,973
2 votes
1 answer
524 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 ...
twink_ml's user avatar
  • 123
2 votes
1 answer
72 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 ...
cxw's user avatar
  • 974
6 votes
4 answers
161 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 ...
ctholho's user avatar
  • 181
1 vote
2 answers
138 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} ...
Dr Krishnakumar Gopalakrishnan's user avatar
0 votes
2 answers
63 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....
raul.vila's user avatar
  • 113
3 votes
4 answers
887 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 ...
cxw's user avatar
  • 974
3 votes
1 answer
114 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 ...
ELLIOTTCABLE's user avatar
8 votes
2 answers
539 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 ...
Robert Kusznier's user avatar
3 votes
1 answer
767 views

Remap standard motions

I have a file formatted like this +---------------------------------+ | Text text text | | Text text text | | Text text text | +---------------------...
Boris Brodski's user avatar
1 vote
1 answer
106 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 ...
Karolis Koncevičius's user avatar
6 votes
2 answers
1k 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?
Tyler Durden's user avatar
  • 2,091
1 vote
1 answer
64 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 ...
Caleb's user avatar
  • 2,245
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 ...
Crile's user avatar
  • 21
3 votes
1 answer
117 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 ...
Somebody still uses you MS-DOS's user avatar
3 votes
1 answer
282 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 ...
Octaviour's user avatar
  • 952
6 votes
3 answers
1k 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 ...
nobe4's user avatar
  • 16k
1 vote
0 answers
243 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 ...
Vitor's user avatar
  • 1,732