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.
255
questions
0
votes
0
answers
22
views
Move to end of current inner paren/block [duplicate]
Let's say we have this little snippet here open, and the cursor is at the |:
some_function(a[0], | some_other_function(a[1]));
How would you best delete, change, or visually select the ...
0
votes
0
answers
57
views
ib i( i) builtin text object give confusing results (for empty blocks)
When I use vi( (or vib or vi)) to select the inner-part of brackets, everything works fine whenever there is some content but as soon as the brackets are empty or contain only linebreaks, the previous ...
1
vote
1
answer
25
views
Clean the placeholder text after multiple jumps
I am studying the book "Hacking Vim" by Packt publishing.
In chapter 4 the author gives us an example of a template for HTML files. I followed the guide of the author.
Created a file ~/.vim/...
0
votes
2
answers
71
views
How to repeat motions in general and in particular the ones defined in filetype scripts?
It is possible in Vim to repeat:
Last edition with .
Last substitution with &
Last macro execution with @@
But how to repeat the last motion?
The , and ; repeats the last f, F, t or T move but ...
4
votes
1
answer
112
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 ...
1
vote
2
answers
85
views
How to toggle the cursor position between the beginning and the end of the line?
In normal mode, I'd like to press a key that behaves like ^ (move the cursor to the first non-blank character of the current line), unless the cursor is already there, in which case it should behave ...
3
votes
2
answers
202
views
Vim yank from cursor position to end of nth line
I am trying to yank from my cursor posintion to end of nth line defined by a motion. So for the below text
Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Donec non quam et erat pharetra
...
3
votes
1
answer
99
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 ...
0
votes
1
answer
32
views
What causes the forward word motion to have a delay when "mapleader" is set to space?
With the following mapleader I have a one second delay when performing a forward word motion (w in normal mode). Is there any way to prevent this?
let mapleader = "\<Space>"
0
votes
0
answers
41
views
Is there a way to access the text currently being typed in insert mode?
From :help registers I know that the . register contains the last inserted text. However, thanks to the following autocmd, I have verified that it's content is actually updated after exiting insert ...
0
votes
1
answer
52
views
Navigate between (form feed) sections
Background:
Vim :help states that a section begins after a form-feed (^L) in the first column [*].
In normal mode ]] or [[ can be used to navigate to the next or previous section (respectively).
...
0
votes
0
answers
33
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 ...
0
votes
1
answer
55
views
Permanent bottom margin
Is it possible to keep a permanent bottom margin in the editing area, so that the cursor never touches the very bottom of the screen?
So that when the cursor goes all the way down, I can still see a ...
0
votes
1
answer
64
views
How to make % motion work with quotes?
Is it possible to have % motion work with matching quote " or '?
For example if we have text:
"Lorem ipsum is placeholder text (commonly used in the graphic),
'print, and publishing ...
2
votes
2
answers
252
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
211
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
33
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
43
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 ...
2
votes
1
answer
61
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
106
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
2
answers
66
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
18
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<...
1
vote
1
answer
291
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 ...
1
vote
1
answer
321
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:
...
1
vote
1
answer
402
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 ...
7
votes
1
answer
1k
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 ...
4
votes
1
answer
607
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
99
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 ...
9
votes
5
answers
2k
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 ...
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 ...
0
votes
1
answer
68
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
64
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
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 ",...
0
votes
2
answers
322
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 ...
2
votes
1
answer
175
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
1
answer
64
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
40
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
42
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
1
answer
65
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
129
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.
4
votes
2
answers
472
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 ...
3
votes
2
answers
443
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
0
answers
36
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:
...
3
votes
1
answer
469
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 ...
3
votes
1
answer
682
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
1
answer
59
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
1
answer
179
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
172
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
2
answers
400
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
2
answers
505
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 ...