Skip to main content

Questions tagged [object-motions]

Question about text object motions

Filter by
Sorted by
Tagged with
8 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
8 votes
2 answers
553 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
7 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
  • 16.3k
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,161
6 votes
4 answers
165 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
5 votes
1 answer
399 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
4 votes
3 answers
326 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
4 votes
1 answer
120 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
3 votes
4 answers
1k 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
845 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
3 votes
1 answer
90 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,149
3 votes
1 answer
118 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
302 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
  • 982
3 votes
1 answer
101 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
  • 153
3 votes
1 answer
132 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
2 votes
1 answer
568 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
76 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
  • 384
2 votes
1 answer
151 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
2 votes
1 answer
73 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
2 votes
1 answer
148 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
2 votes
1 answer
127 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
1 vote
1 answer
315 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 ...
user avatar
1 vote
2 answers
357 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's user avatar
  • 113
1 vote
2 answers
35 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
2 answers
52 views

Motions for selecting code statements?

Let's say I have a line of lua like this: vim.keymap.set("n", "<D-BS>", function() vim.cmd(":!trash '%'") vim.cmd("bprev|bd#") end) How could I select ...
Oneechan69's user avatar
1 vote
2 answers
141 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
1 vote
1 answer
28 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
1 vote
1 answer
246 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,485
1 vote
2 answers
344 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 ...
user avatar
1 vote
1 answer
109 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
1 vote
1 answer
66 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,265
1 vote
1 answer
35 views

Use textobject selection with nnoremap

I hope this is not an XY problem, but I need the following thing: I have parameterized markdown fences (in vimwiki), i.e: ```c int a = 5; printf("%d", 5 <++>) ``` So my idea is when ...
Fedja's user avatar
  • 87
1 vote
1 answer
93 views

Setting change/visual marks with empty inner motion in custom text objects

This has been discussed on Vim’s issue tracker. By default for the default builtin motions where the 'indside' of a text object is empty - such as double quote (say we have the following text "&...
user2742982's user avatar
1 vote
0 answers
56 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
1 vote
0 answers
42 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
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
1 vote
0 answers
250 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,802
0 votes
2 answers
5k 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
0 votes
1 answer
58 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
0 votes
1 answer
100 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
  • 3,043
0 votes
1 answer
25 views

Defining custom motions to be used with operators?

For instance, I want to press an operator like yank change or delete, followed a macro that triggers :HopWord from hop.nvim which puts hints on words, I select a hint to navigate that word, then ...
Oneechan69's user avatar
0 votes
1 answer
61 views

Motions for moving to the middle of text objects like words, lines and paragraphs?

I can use 0 and $ to move to the start and end of the line, and w and b to move between words, but what about moving to the middle of words and lines?
Oneechan69's user avatar
0 votes
2 answers
69 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