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
65
votes
3answers
19k views

Why does vim use hjkl for cursor keys?

Why use the keys hjkl on the same line instead of keys in a triangle like wasd for moving on video games? Why not something equivalent with right hand, like ijkl or pl;'?
38
votes
5answers
22k views

How to disable arrow keys in vim?

I want to teach myself to prefer hjkl more over the arrow keys in order to stay on the home row. (I am very aware that one should not use hjkl as the main navigation keys as there are more powerful ...
33
votes
5answers
2k 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 ...
30
votes
1answer
17k views

How can I jump to the next "paragraph"?

Right now I'm working with some blocks of text that are over 1000 lines long. Is there a simple way to move to the beginning of the next paragraph? My workaround for now is searching for two ...
30
votes
4answers
1k views

Why can ci" be outside of quoted area and ci( only works inside parentheses?

When using ci" the cursor does not have to reside in the double quoted area. |String somestring = "some text"; Assuming the pipe is the cursor position, ci" will make it jump to the quoted area. ...
30
votes
4answers
510 views

How can I treat LaTeX quotes as a text object?

Quotation marks in LaTeX are different than in normal text, in that they're formatted ``like this'' (or `like this' for single quotes). This makes it difficult to navigate through them in Vim. I ...
25
votes
5answers
4k views

Delete until the right end of the current inner block

Let's say that I have a code like this (| represents the cursor position): func1(x|, func2(), y); I would like to get: func1(x|); Is there a way to delete the code from the position of the cursor ...
21
votes
4answers
2k 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 ...
21
votes
2answers
5k views

Why do `cw` and `ce` do the same thing?

This has always bugged me about the w and W motion commands—they seem to work differently when used with the change command than they do when used alone, or with the delete command. For example, with ...
21
votes
1answer
3k views

Why is the underscore command _ useful?

I'm a bit puzzeled as to why the underscore command _, which jumps to the beginning of the (COUNT - 1)th line below the cursor, gets its own key. When would I use this rather than + or ^?
20
votes
3answers
13k views

Multiple cursors at desired location

I'm using vim-multiple-cursors plugin. I would like to put cursors exactly where I want. For example ([x] are the cursor positions): Lorem ipsum dolor sit amet[1], consectetur adipiscing elit, sed ...
20
votes
2answers
353 views

Why does "Operator" + "Motion" behave inconsistently?

This is something that has bugged me for a long time, but I've never gotten around to asking about. Say the text in your buffer looks like this: Hello World If I put my cursor somewhere in line 2, ...
19
votes
1answer
4k views

End of python block motion

I need a motion that moves to end/beginning of a python block, and I need another motion that moves to begining/end of previous/next method/class (all combinations). I've tried vim-indent-object, ...
17
votes
3answers
2k views

How to jump to middle of buffer

By pressing gg and G you can jump to both ends of a buffer. 42G jumps to the line 42. Is there any quick g shortcut to jump to the middle of buffer. Something like roughly round(number of lines/2)G ?...
17
votes
2answers
2k views

Expand f and t motion to next lines

Is there a way that t{char} and f{char} will continue to work in the next lines if {char} is not present in a given line? I would like to avoid using /{char}<CR> to save 1 keystroke and to not ...
16
votes
3answers
2k views

Mapping with motion

I'm trying to understand how can I use operator with subsequent motion inside a mapping. For example: nmap /c c{here we pending for a motion}/<C-r>"<CR> The map should do the following: ...
15
votes
1answer
1k views

How to treat underscores like space?

Is it possible for vim to treat underscores like spaces or hypens, so when I use the sequence dw, it doesn't delete whole sentence some_long_text_with_underscores, when the cursor is at the beginning?
12
votes
4answers
6k views

Is it possible to have vim show the list of available marks when using marks?

That is, when you hit the marks operator key ` or ' you get a list of the available marks - i.e. the list vim gives from the ex command :marks. Then, when you press a letter to jump to the mark, you ...
12
votes
2answers
2k views

Is there a text object for current line?

Is there a text object for current line? Is there a text object for ^$?
12
votes
1answer
822 views

Why does >3k move the cursor up when >3j does not move it down? [duplicate]

Hitting >3j indents the current line and the three below it, and >3k does the same but with the three lines above. However, when indenting down, my cursor is left on the same line as it started, ...
11
votes
3answers
554 views

Is there a motion similar to a" that never includes leading whitespace?

I'm using the a" motion rather often in vim; e.g. using ca" while refactoring a piece of code to replace a hardcoded argument with a variable name. The problem with this approach is that a" includes ...
11
votes
4answers
3k views

How do I move to the last character in a sentence?

In normal mode ( and ) move to the previous or next first character in the sentence, respectively. How do I move to the very last character. If all of my sentences end with a period I can use )T. (...
11
votes
3answers
827 views

How can I use marks to jump to locations in files I have recently opened, but not changed?

Often times I edit a file - think my work is done - then close the file and move on to the next thing. But then I realise I need to go back to that code and tweak it a bit more. If I open the file ...
11
votes
2answers
210 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 ...
10
votes
3answers
2k views

How to delete till the end of the previous line?

An example (The ^ is the cursor position): Before: a bc def ghi j k l mn o p q rs ^ After: a bc def ghimn o p q rs ^ or at least: a bc def ghimn o p q rs ^ I know I ...
10
votes
4answers
295 views

Restricting operations to a section of code

There is many times in my day to day work life that I need to operate on a specific function, things like highlighting or searching for a variable, but I have never managed to limit the scope of the ...
9
votes
2answers
6k views

How to quickly add content in a new line at end of file?

I often have to add stuff at the end of a file, hence I go to the last line: :$ yet this is at the beginning of the line. Often I discover myself doing: Ctrl + Arrow Right to jump by word until I ...
9
votes
3answers
957 views

Jump to next identifier in Vim help files

I regularly find myself in the situation that I am reading a help topic and see an identifier (the blue underlined words) that I want to follow with <C-]>. However, most of the time the ...
9
votes
1answer
374 views

How can I easily get the length of a piece of text?

I sometimes want to check the length of a piece of text, for example in this example: str = 'Hello, world!' if len(str) == 13: print('Hello back to you!') I would like to know the length of the ...
9
votes
1answer
3k views

Define word boundaries

I use, e.g., dw to delete a word based on word boundaries defined by changing character classes, so that this command applied on abc,def,ghi will result in ,def,ghi. (So far so good, and it worked for ...
9
votes
2answers
201 views

Make sense of "[[", "]]", "[]", "]["

I found it hard to understand these text object motions: *]]* ]] [count] sections forward or to the next '{' in the first column. When used after an ...
9
votes
1answer
380 views

Is it possible to use '/' search as an inclusive motion (similar to what 'f' is to 't')?

I've been a long time fan of the t and f motions to modify text up to or including some character. For more complicated criteria, I've started using / followed by a search string to modify text up to ...
9
votes
1answer
777 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. ...
8
votes
4answers
1k views

Grok Vim motions and simple edits

I'm returning to Vim after using Emacs for a few years. I'm trying to grok Vim by reading and watching tutorials, as well as actually using it daily. When editing text, I find the Emacs commands of ...
8
votes
3answers
2k views

How to simply remove braces

One of my friend told me that I can use the trick below to remove a pair of curly brackets. Put the cursor inside the curly bracket pair you want to remove. y i { to yank the text in braces , then v ...
8
votes
2answers
341 views

How do I surround a quoted string without including leading whitespace?

I have a string like 'foobar', and I want to surround it with parentheses: ('foobar'). With vim-surround, I can do ysi'), which produces '(foobar)'... Not what I want I can also ysa'), but that will ...
8
votes
3answers
1k views

Move after end of word or Delete after cusor

What is the fastest sequence to delete to the end of line after the cursor position? Example: I want to delete this line in a faster way Sequence: 5eD will delete the last character of the word ...
8
votes
1answer
124 views

change meaning of "paragraph" for TeX input?

I'm writing LaTeX code which has a lot of sections like this \begin{definition} blah blah blah ... ... \end{definition} In normal text, I'm very fond of gq] to rewrap everything nicely. Inside a ...
8
votes
1answer
429 views

Can I add a custom paragraph delimiter?

Paragraphs are delimited by empty lines, both in vim and tex, but sometimes I wish vim to treat an entity as a paragraph and not tex. Can I, e.g., make vim treat lines containing only a "%" as a ...
7
votes
2answers
1k views

How to jump back to the cursor position before I entered insert mode?

I'm trying to set up normal mode mappings to make it easy to add white space around the cursor: <C-h> will add one space to the right of the cursor; <C-j> will add a newline below; <C-...
7
votes
3answers
3k views

How to use 'w' to navigate in CamelCase words?

How would I use set iskeyword to be able to use w to count Capital letters as words? For example for the following sentence, ThisIsAShortSentence Pressing w will jump from T -> I -> A -> S -> S
6
votes
5answers
844 views

truncate sentence: delete up to, but not including period

How can I set up a keybinding to delete up to the end of a sentence that ends with a period, but keep the period? The commands df., d), and D all truncate the sentence but don't keep the period. ...
6
votes
2answers
2k views

How to delete entire function definition (C style)

How can I delete the block int Test() { // } when my cursor is before int (or even better when it is anywhere on that line)? The shortest I could come up with is d<line>G where <line> ...
6
votes
5answers
418 views

How to ignore a column when visually selecting a paragraph

I have a file that looks like this: # Section 1 # # new: a.txt # new: b.txt # # # Section 2 # # [n]ew: c.txt # new: d.txt # new: e.txt # My cursor is on the first new of the second section and I ...
6
votes
2answers
4k views

Vim jump between words and stop at end of line

In normal mode, b and w are jumping between words, and I would like to stop at the end of line. For example: The cursor is right over here When I press w, what I expect is Instead, the cursor ...
6
votes
2answers
4k views

Jumping to start/end of function definition in C++

Is there an easy way to jump to the beginning or end of the function your cursor is currently inside? It doesn't seem like sentence/paragraph/section have useful syntax aware meanings when editing C++....
6
votes
1answer
144 views

How to keep in the undo history just one change for this command?

I want to keep in the undo history just one change for a long command such as: d0kJx. (I took the command from this answer.) This command (d0kJx) does this (The ^ is the cursor position): Before: a ...
6
votes
1answer
543 views

Key binding to select the current paragraph

I'm using the following key binding to visually select the current paragraph. nnoremap <leader>v }kV{j Is works as follows: } Move below the current paragraph. k Move one line up. V Start ...
6
votes
1answer
403 views

Which text object defines text enclosed in space?

Since I need to operate on a sequence of symbols between spaces I'd like to know which text object defines it. Here is an example: 45908 Sep 24 21:31 [r].t3891993.tr some another text. ...
6
votes
3answers
754 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 ...

1
2 3 4 5