Questions tagged [cursor-motions]

Commands that moves the cursor. A motion command is used after an operator command to move over the text that is to be operated upon.

Filter by
Sorted by
Tagged with
35 votes
5 answers
3k views

Is there a text object for the entire buffer?

I often find myself typing commands like gg"+yG or ggdG and would like a more efficient way to do this without having to move the cursor twice. Is there any command that I can use e.g. y[movement] to ...
5 votes
4 answers
721 views

What's the difference between a text object and a motion?

I've been using vim for a while and consider myself moderately proficient. I've also built custom text objects, primarily using the fantastic vim-textobj-user rather than natively, as well as using ...
4 votes
3 answers
4k views

Run macro over a visual selection with line movements

I can find an answer to a similar problem here, however although I can get that example to function I can't get what I want to do to work. Here is the example text to be edited, a partial section of ...
1 vote
3 answers
391 views

Selector for line of text?

To grab a full word from anywhere in the word I can do: viw And to grab an entire line from start to finish I can do: V However, is there a section that grabs all text from the first char to the ...
4 votes
2 answers
365 views

Does vim's ex command line support (readline-like) motions? [duplicate]

tldr Moving in ex command line is slow because common readline motions (like in bash) are not supported. Are there any improvements for this? I often find myself with an ex command in the command ...
3 votes
1 answer
106 views

custom mapping to make dge consistent with dw, de, and db?

Situation Recently I was investigating the behaviour of word motions in vim and to me it seems like ge is grossly inconsistent with the other 3. Here is an example with ^ showing the cursor: word1 ...
1 vote
2 answers
1k views

How do I get matchit to work with '/>' (self-closed tags)?

I really like to jump from one <el> to the end of </el> with matchit. I am using it for jsx, but it does not seem to work if I have an element that is declared with />, does anybody ...
1 vote
1 answer
440 views

Unexpected behavior with feedkeys

Consider the following code snippet, which aims to provide y without moving the cursor. function! Yank_fixed_cursor() let save_cursor = getcurpos() call feedkeys("y", 'nitx') call setpos('...
0 votes
1 answer
25 views

Delete to the end of a paragaph, including all of the current line

I'd like to redefine the { and } motions to operate "linewise" when used with the c and d operators. To be concrete, given the following: The quick brown fox j|umps over the lazy dog If I press d}, ...
4 votes
1 answer
170 views

delete brackets and select region

Is there a quick way to delete brackets ( some string ) and then select "some string"? ds( deletes them (using the surround plugin). vi( selects but only when they exist. looking for normal mode.
3 votes
1 answer
523 views

Change <up>/<down> to gk/gj in insert mode

I want to replace the default behavior of the arrows in insert mode, so that they behave like gk and gj, I have used: inoremap <up> <Esc>gka inoremap <down> <Esc>gja But this ...
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, ...
3 votes
1 answer
150 views

Repeat last "change inside text object" command without the inserted text

Is there some way to repeat something like cit and be left in insert mode instead of automatically repeating the previously entered text? For example, suppose I have the following lines: <th>...
3 votes
1 answer
266 views

Create a motion?

I find it very strange that I can't find this question anywhere... I made a mapping nnoremap <leader>C /\u<CR> to go to the next capital letter. I thought it would be useful to edit ...
2 votes
1 answer
514 views

How to search & replace the word under cursor without changing position?

This question is related to Do a forward slash search but don't have vim immediately jump to the string? but is not a dup. I recently updated my Linux box (clicked on the "install updates" button ...
3 votes
4 answers
743 views

Last char on the line is being "left out" in many situations

For example, wanting to delete the last 3 words from the current line, I press $d3b but I still have the last char from that line not deleted. Is that normal? Is there a better way to achieve what I'm ...
0 votes
1 answer
166 views

viw breaks when i is remapped

I have the following in my init.vim (neovim): nnoremap i k nnoremap j h nnoremap k j xnoremap i k xnoremap j h xnoremap k j nnoremap h i nnoremap H I I find this arrow key-like configuration much ...
1 vote
1 answer
189 views

How to create new operator by using existing operator with current motion?

function! OperatorFunc(type, ...) " how to call another operator with current motion? " do other stuff endfunction Is it possible to get motion text? such as get iw from yiw
1 vote
1 answer
278 views

(how) can I use di< / di> to delete inner block of xml

What would be the best way to delete / change the inner block of an xml element? I could use df< when my cursor is inside the block, i.e. when I have: <elem>foo bar<\elem> ^ ...
1 vote
1 answer
69 views

Vim changing the text objects of " in a single line with less number of keystrokes?

Consider this situation, which I often follow in python and consider that my cursor is on the letter a of args: args = ap.add_argument("-i", "--texture", type = str, required=True, help="path of the ...
2 votes
1 answer
106 views

How to go back after accidentally hitting H in visual mode?

While selecting in visual mode I often accidentally hit H or L instead of h or l due to having used Shift for some previous command (like e.g. V to start selection by line) and not yet released it ...
3 votes
1 answer
269 views

Register CursorMoved on certain key press and disable when move to new line

I'm trying to write a function that will highlight searches performed with the f and F keys. I currently have a solution here thanks to @filbranden, but would like to further improve it to only ...
3 votes
1 answer
1k views

Remapping motion keys [duplicate]

I recently found the awesome plugin named CamelCaseMotion which is awesome. I used their suggested mappings in my .vimrc for the plugin like this: map <silent> w <Plug>CamelCaseMotion_w ...
9 votes
1 answer
927 views

Change the cursor shape in operator pending mode

My cursor in Gvim: My cursor in Gvim after pressing d: Is there any way I can change the cursor in terminal Vim when in operator pending mode? It doesn't have to look exactly like the screenshots. ...
1 vote
4 answers
85 views

How to end selection at an occurrence of a word?

Let's say I have this text with | as my cursor: <<<<<<< HEAD hi ======= hello ====== >>>>>> XXXX GGg| Now, I'd like to select from >>>> to say second=== or ...
3 votes
1 answer
383 views

How do I get the text that is chosen by some motion?

I'm wanting to write a simple plugin that allows using a motion to choose some text and then processes that text. I'm trying to find out how to get the text that a motion results in. So far I haven't ...
8 votes
3 answers
4k views

A version of `w` which skips to the next underscore

I frequently work with code style which asks that many non-class symbols use snake_case -- Python, Ruby, and C especially. If I have a symbol like longfirstpart_longsecondpart, I'd like to be able to ...
2 votes
0 answers
26 views

Different behavior when selecting quote blocks vs. selecting parentheses blocks [duplicate]

When I have a line of code such as: result = function(myVar); then I can delete the text "myVar" with the command di( only if my cursor is already positioned inside the parentheses. However, when I'...
0 votes
1 answer
71 views

Can I select and paste with a single operation?

Here's my use case. I have the following text: This is a [hyperlink](http://someurl.com). Now I want to replace the http://someurl.com text with a new URL in the default register (something I've ...
1 vote
1 answer
101 views

How to wrap a command which can handle a text object?

The scenario is that the plugin I use (iron.nvim) has a mapping crt which handle text objects. Ultimately, this mapping is based on a command <Plug>(iron-send-motion). I would like to create a ...
1 vote
2 answers
311 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 vote
1 answer
288 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 ...
4 votes
3 answers
3k views

navigate within nerdtree

I wonder how folks navigate efficiently with in a nerdtree window, for example if I'm in a folder like this: ├── m1.py ├── m1.pyc ├── m2.py ├── m2.py.bak ├── m2.pyc ├── main.py ├── matplotdemo.py ├── ...
3 votes
2 answers
358 views

Highlight everything inside (, [, and { and expand outwards

Suppose I have a line of text of the form (123[456{789}abc]def) and the cursor is inside the curly braces. In sublime text, we can use ctrl-shift-m repeatedly to jump to highlighting 789, {789}, 456{...
6 votes
1 answer
2k views

How does Ctrl-I works?

I have completely clean vimrc, no plugins, and the following test file: foo bar baz baz baz baz baz baz baz baz Now, I press / to start search, then type baz, press Enter, press n twice. It will ...
0 votes
1 answer
85 views

Number in the beginning vs. number in the end

Yes, I know that d2e and 2de are two different commands and therefore works slightly different, though it's not visible to the eyes. Let's call them "number-in-the-middle" (nim) and "number-in-the-...
0 votes
0 answers
97 views

Select characters in Visual mode (works differently than Normal mode)

I'm trying to understand the difference in character counting between Normal and Visual modes. Roses are red, Violets are blue, Sugar is sweet, And so are you. The task is to copy everything from ...
5 votes
4 answers
853 views

Delete with search motion in normal command

I am attempting to delete from start of line until string foo. In normal mode, 0d/foo accomplishes this. Now, I would like to do this for every line in my buffer. Reading documentation and SO it ...
0 votes
1 answer
74 views

How can you turn off text highlighting (hlsearch) with custom text objects?

I am implementing a custom text object in visual mode, but this text object uses regular expressions to find the beginning and ending of the selection. However, when I do this, other parts of the text ...
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 ...
4 votes
1 answer
158 views

textobj-user: must the patterns be different?

I'm trying to make a text-object that is a paragraph surrounded by lines containing %. To test something simpler, I tried: call textobj#user#plugin('pc', { \ 'code': { \ 'pattern': ['%<', '%'...
2 votes
1 answer
63 views

change inner backslashed quotes

I know the ci" motion and others :changes, but I need something like a ci\" in order to change inner a backslashed quotes. Assuming * as the cursor position: a = "message says: \"fo*o bar\"" I would ...
11 votes
2 answers
243 views

Rectangular regions as text objects?

Is it possible to define a text object in vim that will act on a rectangular region? For instance, suppose I have vertically aligned columns of text, like this: column 1 co column 2 col lumn 1 ...
5 votes
1 answer
619 views

Motion to jump back one level of indentation, not including blank lines

I've been authoring a lot of F# in Vim lately. Like Python it is pretty strictly indentation-based. However, unlike Python mode for Vim, it does not appear that the standard F# Vim plugin supports any ...
1 vote
0 answers
57 views

Repeat previous square bracket command [duplicate]

I am using the ] commands (e.g. ]]) a lot and have a bunch of custom ones too. Is there a command that repeats the last such command, similar to how . repeats the last edit?
1 vote
0 answers
28 views

]m moves to class definitions not method definitions inside nested classes

I am editing a java file. ]m takes me from one class to the next, instead of to the next method definition. How do I get it to take me between methods? Example: public class Baz { public class ...
2 votes
1 answer
540 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 ...
1 vote
1 answer
145 views

Why is :execute required in this --remote-silent command?

Let's say I want to jump to a particular position in a file in an existing Vim server: This command jumps to the correct line, but not the correct column, leaving the cursor at the start of the line: ...
23 votes
4 answers
3k views

Simplest way to delete a "composite" word?

Apologies if "composite" is not the technical term. I mean the following: Hi, I-am-a-composite-word and we are not I would like to delete only the composite word. In command mode, if I move the ...
4 votes
3 answers
5k views

Control - Arrow to Skip Over Text

I am new to Vim, however I am learning to love it. As a former/current Windows user, there is one shortcut that I depend on and would like to configure in Vim. On windows I can use ctrl-arrow left ...