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
0
votes
2answers
39 views

How to move `n` number char <left> in vim command line?

My init.vim code autocmd FileType cpp nnoremap <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt I want my cursor position to be exact 31 times <left> in command ...
1
vote
1answer
25 views

How can sentences be handled by a motion?

Is there a motion to move forwards a sentence? For example, w moves forwards a word.
3
votes
1answer
34 views

Stop word motions from overshooting line

The word/WORD motions w, W, e, and E will overshoot to the next line when the cursor reaches the end of the current one. The word/WORD motions b, B, ge, and gE will overshoot to the previous line when ...
1
vote
1answer
28 views

Execute action to the beginning/end of a motion

Is there a way do execute an action (change c, delete d, and so on) to the beginning or to the end of a motion? For example: Suppose we have: Praesentium officia mollitia iste molestiae ipsa qui ...
0
votes
1answer
27 views

Why does the cursor advance to the next character?

I have nnoremap Y y$ in my .vimrc. If I type "*y$, my cursor stays in the same spot on a word. However if I type, "*Y, the cursor is advanced one character. Why is that?
0
votes
1answer
41 views

Inconsistent behavior of dj and other motion-delete operations

I'm running Neovim 0.5.0 locally. I'm going through Harvard's CS50 course and they have an IDE (accessible here: https://ide.cs50.io/) with a shell that's running this version of Vim: version 8....
0
votes
1answer
46 views

How do I move to the next/previous number [duplicate]

How do I move the cursor to the next/previous number? Ctrl-x and Ctrl-a can't be used since I have :set nrformats+=alpha.
3
votes
2answers
113 views

how to jump to start of tag

I might have some text like the following: <foo>something very important</foo> 1 2 ^ 3 4 If the cursor is inside the tag, for example on the m character, what is ...
0
votes
0answers
40 views

Cursor disappearing

I'm using pywal and the wal colourscheme and since enabling it my cursor seems to have disappeared, meaning it has the same colour as my background (that's what I guess) and I only see it blinking ...
3
votes
2answers
250 views

removing multiple lines - d3d vs 3dd

I was speaking with my friend about removing multiple lines while using vim. They said they use d3d to remove 3 lines, whereas I use 3dd I understand my command is: 3 (repeat 3x) dd (delete the entire ...
1
vote
0answers
35 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: ...
1
vote
1answer
83 views

Add current position to the jump list the first time <C-u> or <C-d> is pressed

I'm often using <C-u> and <C-d> to quickly navigate around in my code (I don't like using { and } since they're hard to type on my layout). One thing that annoys me is that <C-u> and ...
2
votes
1answer
149 views

Fastest way to find last occurence of a character in line?

Say we have the following: echo 'This is a test'.$test1.$test2.$test3.$test4.$test5.'and this is another test'; ^ With the cursor being on the first dollar sign, and I want to ...
1
vote
1answer
50 views

What is the correct cursor position when a } (forward paragraph motion) reaches the last line of the buffer?

Suppose I have two lines in a buffer: First line Second line I position my cursor on the first column of the first line. In normal mode, I press } (i.e. closing curly brace, forward paragraph motion)....
1
vote
1answer
100 views

How does the underscore forward movement work? _f

I was recently watching a more advanced vim tutorial on youtube. One of the commands used was _f. This was actually just part of a longer macro being demonstrated and the underscore wasn't commented ...
0
votes
2answers
78 views

Mapping with motion ip

I'm trying to create my own mapping with motion in Vim after reading this stackexchange question. I'm using the plugin vimtux to send code to specific tmux instances and I now want to be able to do ...
1
vote
2answers
258 views

How to add several empty lines without entering insert mode? [duplicate]

Sometimes I want to add several empty lines for better visualization. Now I end up clicking o<Escape> multiple times. I would love to reduce number of clicks by using something like 7o instead, ...
3
votes
1answer
72 views

Backward search in current line with search() and z option

I am trying to write a couple of simple functions to find the next and previous links in Vimwiki and move to them. Links in Vimwiki are indicated with the syntax [[link to something]]. Since I only ...
0
votes
1answer
17 views

Make j and k act character-wise when used with operators

When I use j or k with operators, they make the operator act line-wise - acting over two whole lines, as if I had used Vj/Vk. I want them to act character-wise so that they act until the current ...
1
vote
1answer
28 views

Create mapping that works both with a motion and a count

I'd like to have a mapping that separates words, like this: noremap RJ :s/\>\s*\</\r/g<CR>='' I can do 3RJ with that. I can also create opfunc, so I can do RJ}: noremap RJ :set opfunc=...
1
vote
2answers
28 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. ...
0
votes
1answer
31 views

Line numbers relative to the screen

Is it possible to make Vim show line numbers relative to the screen? Not to the beginning of the file, and not to the current position of the cursor, but relative to the first line that is currently ...
1
vote
1answer
26 views

How to prevent cursor shift when using <C-O>{delete cmd} at the end of a line?

<C-w> deletes a (small-)word in insert mode, but I often want to delete the Word (to last whitespace) I've most recently typed. I tried inoremap <C-_> <C-o>dB which kind-of works -- ...
-1
votes
1answer
35 views

In a new line, moving to the columns of the beginning of the words in the line above?

Is it possible to have a 'smart tab' working as follows: 'move forward to the columns corresponding to the beginnings of the words in the line above' For example, in the situation below: I would like ...
1
vote
2answers
73 views

Text object for a field between tabs

I'd like to define a text object for tab-delimited fields in a tsv file. So far, I have vnoremap af :<C-U>silent! normal! T<Tab>vf<Tab><CR> omap af :normal Vat<CR> ...
0
votes
1answer
42 views

G+zz simultaneously : Move to bottom and then move text to center?

How do i remap G to do what G and zz do simultaneously ? In other words, I would like to move to the bottom of the page and then have the text moved to the middle of the screen. I tried something like ...
1
vote
1answer
19 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?
2
votes
1answer
42 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) { ...
1
vote
0answers
22 views

Different Deletion from seemingly equivalent motions

I have been learning vim for some time now and I am loving it but there is something that confuses me a little bit. For discussion proposes lets say that we have the following text foo.bar with the ...
0
votes
2answers
320 views

Why do I have to press the caret button twice to go to the beginning of the line?

When I press the caret button in normal mode, vim first prints a caret at the cursor position. Only with the second press of the caret button does the cursor actually move to the beginning of the line....
3
votes
4answers
309 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 ...
1
vote
2answers
303 views

How to go back to the start of a visual selection?

I find myself often selecting text and then wanting to go to the start of that selection rather than the end. For example in the following: If I press esc, it will take me to the end of the selection,...
1
vote
3answers
145 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 ...
3
votes
2answers
107 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
1answer
83 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
1answer
147 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
1answer
21 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}, ...
3
votes
1answer
107 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.
1
vote
0answers
33 views

A quick way to restore motion after changing iskeyword

I want iskeyword to only affect completion. I need that in the case of Latex. I want \chi_{23} to be a single object with regard to complition. But changing iskeyword also makes \dosomething{crap} a ...
2
votes
1answer
210 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 ...
4
votes
3answers
565 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, ...
2
votes
1answer
71 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>...
2
votes
1answer
64 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
1answer
149 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
4answers
740 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
1answer
121 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
1answer
55 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
1answer
72 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
1answer
140 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
1answer
723 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 ...

1
2 3 4 5