Questions tagged [cursor-movement]

Moving the cursor another place in the buffer.

Filter by
Sorted by
Tagged with
51
votes
3answers
13k views

How to jump between matching HTML/XML tags?

How to jump between matching tags (such as <div>, <span>, etc.) when editing HTML/XHTML/XML documents similarly as % is used to jump between matching parentheses?
1
vote
1answer
31 views

Conflict between system compose key and insert mode meta key mappings

I use the right alt key as a compose key on my system, to easily draw diacritics and accent characters. In Vim, I unlock alt key mappings with this (from stackoverflow): " Allow <alt> key ...
0
votes
1answer
33 views

How to bind these keys to prevent recursive binding in Vim?

I have been trying to do :noremap j k and :noremap k j which works but instead of going up it goes slanted up and down. I want j to move up and k to move down which is opposite in vim. I also tried :...
2
votes
1answer
10 views

How to jump to the first character of the first line of the next/previous block of text?

I am aware of {and } to navigate between blocks of texts , however these jump to blank lines in between blocks of text. When there are several blank lines in between 2 blocks of text these do not ...
1
vote
1answer
28 views

Typing d in insert mode briefly moves cursor backwards

In Vim, when I'm in Insert mode and hit d, the cursor moves back one spot for a second, then jumps back to behind the letter just typed. This is quite distracting when typing texts. It looks like Vim ...
28
votes
4answers
16k views

How to disable arrow keys in vim?

I want to teach myself using hjkl more than using the arrow keys in order to stay on the home row. And yes, I am very aware that one should not use hjkl as the main navigation keys. Yet my habits are ...
1
vote
1answer
24 views

Is there a way to use a relative address that doesn't go over the edges of the file?

I'm using the following commands to move a line of text up and down in the file. :move +1<CR> :move -2<CR> However, these commands don't work on the edges of the file. If I try to move ...
1
vote
1answer
23 views

How do I, in a macro, yank a word which might be just one letter long?

I am writing a macro a part of which is supposed to extract verse numbers from a string such as 11.1, standing for "verse one in canto eleven". I search /11\.\zs. The cursor now is in the right place. ...
0
votes
2answers
27 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....
2
votes
1answer
48 views

Put cursor at arbitrary line and column

Normal, insert, and visual modes restrict cursor movements to locations occupied by some characters. They don't allow moving to the right from the end of line and down beyond end of file. For example:...
1
vote
1answer
36 views

How to move past a closing parenthesis in insert mode

so I've been learning vim the past few weeks and am having trouble with defining functions and the such. e.g. every time I define I function in python I write: typing in insert mode: def foo<...
5
votes
3answers
2k views

Moving to an outer block

Does anybody know the command for moving to an outer block of brackets/parentheses? Lets say that my cursor is in the innermost bracket. I know that % moves to a matching bracket, but is there a ...
4
votes
2answers
702 views

Why isn't this implemented by default in vim? (line by line Scroll) [closed]

Very often, my preferred way of navigating a file in vim is by "scrolling" line by line. By scrolling, I mean shifting the lines up/down while keeping the cursor on the same line and position. <c-d&...
9
votes
2answers
1k views

Using marks with dead keys

I am using a keyboard layout in which the backtick (`) is a dead key. This means that when I type a backtick followed by a vowel (for example `a) what Vim sees is an accented character (à). So if I ...
2
votes
1answer
46 views

Go to Nth character in the file?

:goto goes to Nth byte of the file. I am looking for a way to go to Nth character. Given that Vim supports all kinds of multi-byte encodings, it would be odd if it did not exist, but I can't find one.
0
votes
1answer
25 views

Is the pattern .\{-}\> equivalent to the move command e?

What is the appropriate way to make a pattern that matches up until the point where the move command e would have moved to? Consider this text: texttext%0s: cookie after performing /%<CR>ve the ...
104
votes
2answers
7k views

How do I navigate to topics in Vim's documentation?

In Vim's built-in help system, how do I… search for topics that I want help on? follow hyperlinks? browse around for related material?
1
vote
2answers
42 views

Advance to next (multi)characters on a line

To advance to the next/previous character match on a line I can do: f <char> However, I find myself wanting to match against two characters on that line, for example, something like: f =' Is ...
0
votes
1answer
56 views

Can I use feedkeys() inside of a keyloop implemented by getchar()

I implemented a fuzzy filter, which accept a list argument, open a window with a scratch buffer whose content set to the list, then waiting for use input and do filtering. Here is why I ask this ...
3
votes
1answer
61 views

Simple keycombination to move to the last occurance of a character in a line

I am looking for a simple few key command which would move till the last occurrence of a character in the line. Is there anything already existing? The alternative is to jump to the next specified ...
23
votes
4answers
4k views

How do I deal with very long lines in text (500+ characters)?

For some text formats, line breaks matter. For example, I often use Vim to write MediaWiki documents, where you can't just put a linebreak anywhere (unlike Markdown). So I'm forced to write lines ...
19
votes
3answers
1k views

How can I make Vim position the cursor at the start of a tab character instead of the end?

Open an empty buffer and insert a tab character then exit to normal mode. When you place the cursor (normal mode) on the tab it will be at the right side of the whitespace. I'm looking for a way so ...
0
votes
1answer
41 views

How to move the cursor out of the terminal

I'm now using Vim 8 and its new feature: :term. Well, it's great but I don't know how to move the cursor out of the terminal without the mouse. In Vim 7, we can type <C-w><C-h>, <C-w&...
1
vote
1answer
39 views

Does Vim keep track of screen views?

In vim, one could describe the "state" as the position of the cursor, the position of the screen view (ratio of screen viewable above cursor vs below), and the values of all latent variables and file ...
0
votes
2answers
37 views

Paste at cursor instead of below

If I start with this file: https://example.com <> and press ddp, I expect to get this: <https://example.com> but instead I get this: <> https://example.com What am I doing ...
1
vote
2answers
101 views

Pressing Enter removes indentation

If I have a file a.js like this: let a1 = [ ]; and I press Enter at the end of the first line, a Tab is inserted. I do not want this, so I added a setting: filetype indent off but then if I have ...
2
votes
0answers
42 views

Remove 'jumps' when moving to last and first line in Vim [duplicate]

I have the display option set to lastline so that the last line is shown even if all it doesn't fit on the window. When moving down visual lines with gj to the last line that is only partially visible,...
18
votes
5answers
4k views

How do I move the cursor to the center of current line?

Is there a way I can move my cursor to the middle of the current line? (the middle of the line of text - not middle of screen width) I was wondering if there was a shortcut similar to M that moves ...
15
votes
2answers
4k views

How to restore the position of the cursor after executing a normal command?

I am trying to code a function that replaces the character in the sixth column of my current line with a dollar symbol ($), but I would like my cursor to remain at the position it was before calling ...
86
votes
6answers
15k views

How do I jump to the location of my last edit?

I often make changes to the middle of a big file, use gg to jump to the top to check something, and then realize I forgot to set a mark where I was editing. Is there a built-in way to jump to the ...
1
vote
2answers
59 views

Move cursor and screen together

I am implementing a smooth scrolling function for <C-u> and <C-d>, which just sleeps for a few milliseconds and then moves the screen up (<C-y>) or down (<C-e>) one line: ...
2
votes
1answer
60 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 ...
4
votes
1answer
25 views

Cursor Movement in y8k vs y8j [duplicate]

Why does y8j not move the cursor but y8k does move it up? What .vimrc entry would prevent yanking upwards moving the cursor?
2
votes
2answers
67 views

Jump to a specific line without moving the cursor horizontally

Consider you are editing the left table in Vim. Your cursor (■) is at Line 14, Column 12. Where you are now Move the cursor 11 +-------+-----+ 11 +-------+-----+ 12 | Name | Age | ...
2
votes
3answers
55 views

How can I prevent Vim from centering the line under the cursor on `:edit`

Each time I want to save my work while editing a text file, I enter :write to save the file, and :edit to reload the file, with the side effect of resetting the undo/redo buffer. However, an unwanted ...
1
vote
0answers
38 views

cursor position jumps to first non-blank character of line unpredictably [closed]

I'm using SpaceVim with Neovim, and often times I'd experience this cursor jumping issue (as if ^ has been pressed in normal mode) while using it. I doubt the bug is on the Neovim end, otherwise a lot ...
0
votes
1answer
51 views

Vim command 0 goes to second column instead of first one

When I press 0 in Normal mode, the cursor goes to the second column and not the first one. This is not the normal behavior stated in vim's :help 0. I have tried disabling the remaps to move between ...
3
votes
3answers
114 views

How to go halfway into a line? Percentage navigation within a line

I know that e.g. 50% is a normal mode command to go halfway down a file, but [count]% is line-wise. How can I get to the halfway point of the line that my cursor is on?
3
votes
3answers
387 views

Moving to the end of the last word on a line

There are commands to distinguish between the beginning of a line (0) and the beginning of the first word of the line (^), basically ignoring leading whitespace. But I can only find one way to move ...
0
votes
1answer
82 views

Jump to nearest pair of brackets with %

I'm looking for a way to change the behaviour of the % key. I know by default it will move the cursor to the corresponding parenthesis or brace, but I'm wondering if I can have it jump to the nearest ...
2
votes
0answers
39 views

Best way to move cursor to start of variable declaration?

There are a lot of times were I have something like int x = someFunction(a, b, c); If my cursor is somewhere after the equals sign, is there a good way to put the cursor on the “s” in someFunction? ...
3
votes
1answer
24 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
495 views

Jump *to* end of paragraph?

I often find I want to quickly select all the characters in an aligned column, something like this: this.p = obj.['propery']; this.prop = obj.['proper']; this.proper = obj.['...
3
votes
1answer
71 views

How to treat underscores as whitespace when skipping to the next word? [duplicate]

Let's consider an example where the cursor is at the beginning of the text one_two three. Underscores are treated as part of the word, so w moves right to the first letter of three. With set ...
1
vote
2answers
96 views

How to move a cursor to the last line with auto indent?

Assume autoindent is set, and you have the buffer below. Note the cursor is represented as I. for i in range(1, 6): print(i)I When you hit Enter key, you get this. for i in range(1, 6): ...
0
votes
2answers
63 views

Why does `:m+1` not move two lines down when `:m-2` moves one line up?

In the help for move: :[range]m[ove] {address} *:m* *:mo* *:move* *E134* Move the lines given by [range] to below the line given ...
1
vote
1answer
16 views

How to make comma and semi-colon direction-insensitive of the latest f,F,t,T command

I can customize the n and N keys to always search backward and forward respectively irrespective of what the last search direction was with the following commands: nnoremap <expr> n (v:...
0
votes
1answer
443 views

How to replace a word with spaces

Suppose I have the following text: This is a test of the emergency broadcast system What I want to do is delete the word "test" and replace it with four spaces: This is a of the emergency ...
5
votes
2answers
306 views

Prevent the cursor from moving to the start of the yanked text?

Vim help's change.txt states that Note that after a characterwise yank command, Vim leaves the cursor on the first yanked character that is closest to the start of the buffer. This means that "...
5
votes
2answers
116 views

WORD movement across lines

Consider the following text snippet: value1, value2 Now, if the cursor is at (1,1) (the 'v' of value1), W takes me to (2,5) (the 'v' of value2) which is as expected. But if I do dW at the same ...

1
2 3 4 5