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

} Jumps { between paragraphs - why they work so strange?

Paragraph 1. Paragraph 2. Paragraph 3. Paragraph 4. Here is how } and { currently work for me: Put the cursor on the P of the 2nd paragraph. Press }. The cursor will jump to the position between ...
2 votes
2 answers
58 views

How can I use `:keepjump` with `gd`/`gf`/searches?

I know that plugin that can do it almost certainly exists. Or maybe I could use something like LSP for this. But I want to make my simple command, that will go to file with definition of component / ...
0 votes
1 answer
25 views

Opfunc inserts text before cursor position sometimes

function! s:Surround(motion = "") abort let [_, l:start_row, l:start_col, _] = getpos("'[") let [_, l:end_row, l:end_col, _] = getpos("']") let l:before = &...
1 vote
1 answer
35 views

How to have w,e,b-based motions handle underscores without using iskeyword?

Using Neovim 0.6.1. I use a lot of snake_case_variable_names and have a frequent need to navigate within their individual components instead of treating these names as a single word. Right now, the ...
  • 121
2 votes
1 answer
56 views

clever way to move words at the end of the line into braces

I repeatedly need to transform word into \edlemvar{word}{}{} or \edlemvar{}{}{word} More generally, it would be great to have a way to do this even if there are more words on the line than "...
1 vote
1 answer
43 views

Word motion as though non-keyword characters were whitespace

I'm very new to vi, so sorry if this is a dumb question. I've recently learned about the list of keyword characters, and I've noticed that vi treats strings of characters not in that list as words ...
0 votes
0 answers
20 views

Plug-in to make sentence skipping based on NLP

Is there any plug-in which uses modern NLP sentence segmentation when deciding on the sentence boundaries, when skipping with )? If not, how could that be implemented? Because the sentence jumping I ...
0 votes
1 answer
28 views

What is an elegant way to delete until the first line?

I know that I can delete until the first character with dgg or until line 1 with d1 Shift-G. But I would prefer something conceptually elegant if possible. I guess I can easily just remap a single key ...
0 votes
0 answers
16 views

How to use advanced Regex features without too many syntax cluster

I have a bunch of typescript classes in a single file, each of them has an _update function. I want to go to _update function of a class Player. How would I do that? class Player { _update() {} } ...
  • 145
0 votes
0 answers
20 views

How to prevent Esc+Home from jumping to line 3?

I have Linux boxes running a mix of Gentoo and Arch Linux with VIM version 8.2, and one CentOS box with VIM 7.4. When I use VIM in a GUI terminal most of them jump to the third line from the top of ...
0 votes
0 answers
17 views

How can I have my mapping handle a count in a function? [duplicate]

I wrote the following filetype plugin. It comments out lines in shell scripts by typing <leader>c. The problem is when I execute the mapped command multiple times by writing for example 4<...
0 votes
1 answer
82 views

Vimscript: how to detect selection of a text object in visual mode?

I'm writing what may become a plugin that needs to know what is currently visually selected. To do it, I'm using the autocmd CursorMoved event to detect the creation of visual mode selections on the ...
  • 971
1 vote
1 answer
52 views

How can I use a variable line number with a command?

I want to move a line to another specified in a variable. So where I might do this to move the current line up seven lines: :m-7 I want to do it with a variable line destination. Something like this: ...
  • 211
1 vote
1 answer
133 views

How to delete everything after the cursor

Say the cursor is []: A very intelligent turtle Found programming [U]NIX a hurdle I want to achieve the same thing as l D in one go: A very intelligent turtle Found programming [U] Is there any ...
5 votes
1 answer
958 views

Vim normal mode: why is j/k jumping paragraphs instead of lines?

So i've copied and pasted text from my browser, and when i hit j/k, it does not bring the cursor up/down single lines like it's supposed to: COLLEYVILLE, Texas (AP) — The rabbi of a Texas synagogue ...
1 vote
1 answer
144 views

How do I delete a self closing html tag?

I'm trying to delete self closing html tags, like the img tag below. <div><img src='http://mypic.com/1.jpg' /></div> I've tried dit, dat, the tpope/vim-surround plugin, and other ...
3 votes
1 answer
76 views

How to insert to the beginning of a word with one key stroke?

Is it possible to start insertion in the beginning of a word when standing in the middle of it with a single keystroke? Currently I am using bi or Bi, but it does not allow me to use . to repeat the ...
  • 1,203
9 votes
4 answers
1k views

How to append to the end of word with one key stroke?

Is it possible to start insertion in the end of word with a single keystroke? Currently I am using ea, but it does not allow me to use . to repeat the same action. I really love A and I which operate ...
  • 1,203
0 votes
1 answer
44 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
63 views

How do you move to the end of the previous line?

Say the cursor is []: A very intelligent turtle Found programming [U]NIX a hurdle I want to end up here: A very intelligent turtl[e] Found programming UNIX a hurdle If I were here: A very ...
2 votes
0 answers
57 views

Make Lightspeed work with Repmo

I'm trying to make the EasyMotion-like (cursor jumping) Lightspeed plugin work with Repmo which repeats a previous motion. So far, (and after many hours), I've come up with the following: let g:...
  • 2,291
2 votes
1 answer
51 views

ci" changes between the wrong quote pairs

For instance, if the cursor position is right after one of the two commas: var strains = ["omicron", "delta","alpha"]; the ci" command deletes the content of ",...
  • 153
0 votes
2 answers
67 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 ...
  • 121
1 vote
1 answer
42 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.
  • 1,931
3 votes
1 answer
45 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
1 answer
34 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
1 answer
30 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?
  • 209
0 votes
1 answer
49 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
1 answer
83 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
2 answers
256 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 ...
  • 163
3 votes
2 answers
303 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 ...
  • 33
1 vote
0 answers
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: ...
  • 43
2 votes
1 answer
149 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 ...
  • 121
2 votes
1 answer
247 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 ...
  • 133
1 vote
1 answer
56 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)....
  • 851
1 vote
1 answer
118 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
2 answers
122 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 ...
  • 3
1 vote
2 answers
271 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, ...
  • 1,203
3 votes
2 answers
223 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 ...
  • 255
0 votes
1 answer
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 ...
  • 111
1 vote
1 answer
35 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=...
  • 113
1 vote
2 answers
30 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
1 answer
34 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 ...
  • 111
1 vote
1 answer
34 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 -- ...
  • 335
-1 votes
1 answer
39 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
2 answers
89 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> ...
  • 111
0 votes
1 answer
46 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
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
2 votes
1 answer
54 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) { ...
  • 193
1 vote
0 answers
24 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 ...
  • 111

1
2 3 4 5