Questions tagged [cursor-movement]
Moving the cursor another place in the buffer.
248
questions
108
votes
2answers
9k 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?
93
votes
6answers
19k 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 ...
56
votes
3answers
16k 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?
45
votes
8answers
17k views
Why is using arrow keys in normal mode considered bad practice?
I have read it in many articles (e.g.) that it's a bad practice to use arrow keys in normal mode. Could somebody explain why is it considered a wrong practice, if at all?
40
votes
6answers
6k views
Can I delete an entire line, except the line break?
A fairly common operation for me in vim, since I am compulsive-obsessive and like to keep my files free of whitespace, is to delete the contents of an entire line, but not the line itself (i.e. not ...
34
votes
4answers
19k 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 ...
32
votes
8answers
2k views
How do I move vertically until reaching a non-whitespace character?
In a very long file with (accurately-) indented code, it may be helpful to move directly to a line of text above or below the cursor which delimits the indenting.
(One way of doing this could be via ...
31
votes
1answer
6k views
How can I move the cursor to the top or bottom of the screen?
I know that gg and G can move the cursor to the top and bottom of the file. But is there a way to jump to the top or bottom of the visible window?
29
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.
...
28
votes
1answer
14k 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 ...
23
votes
4answers
5k 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 ...
22
votes
5answers
3k 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 ...
22
votes
1answer
2k views
How to make movements respect camelCase or snake_case?
It is common to use either camelCase or snake_case to separate multiple words which form an identifier. It would be nice if the "word" movements (b, w, e) would detect those inner-identifier ...
20
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 ...
20
votes
2answers
621 views
How can I use a line number to copy a line to where my cursor is?
A lot of times I'm in a situation similar to this:
1. <Line 1>
2. <Line 2>
3. <Line 3>
4. <Cursor is here>
5. <I want to copy line 1 here>
An easy solution is mm:1<...
19
votes
4answers
2k views
How to replace inner text with yanked text
An editing pattern I frequently run into is the following: I want to yank a piece of text inside quotes or brackets, and replace that piece of text inside another pair of quotes/brackets.
For example,...
19
votes
3answers
1k views
How can I get ‘n’ to go forward even if I started searching with ‘?’ or ‘#’?
Vim has (at least) two sets of commands that search in opposite directions. Typing / and then a pattern will search forward through the document for the pattern; typing ? and then a pattern will ...
19
votes
3answers
2k 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 ...
18
votes
5answers
2k views
After copying a visual selection to keyboard, return to original location
My cursor is in the middle of a paragraph when I decide suddenly I need to copy that paragraph:
So I type vip to select the paragraph visually:
Now I hit cmd+C to copy to clipboard (this may vary on ...
18
votes
2answers
1k views
Using % in languages without curly braces
In C and C-like languages, I can use % to jump to the corresponding curly brace that the cursor is on. This is a well-known "trick".
But in Ruby for example:
def fun
[1, 2].each do |n|
end
...
17
votes
4answers
7k views
Scroll a quarter (25%) of the screen up or down
I often find scrolling a full page too disorienting, half a page too much, but a quarter page is just right. I currently do it just by holding down the arrow keys.
How do I scroll 25% of the page ...
17
votes
2answers
5k 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 ...
17
votes
3answers
10k views
Jumping to a byte offset, and displaying position as byte offset
How can I move the cursor to the nth byte in the buffer?
How can I display the current cursor position in the ruler in terms of the byte offset, rather than lines and columns? (Follow-up question: ...
17
votes
2answers
7k views
How do I make Vim always display several lines after EOF?
In Vim, I don't like how when you reach end of file it puts the last line at the bottom of the screen.
Is there anyway to make the last line be something like 10 lines above the bottom of the screen ...
16
votes
1answer
5k views
Hand Placement for Vim Navigation
I'm a new Vim user, and I want to ask this somewhat elementary question in order to make sure I start learning Vim the right way and don't develop bad habits.
When you use Vim, how do you position ...
15
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:
...
14
votes
3answers
1k views
Edit different words simultaneously, one the same line like in Sublime Text with multiplie selections
is it possible to edit more than one word simultaneously, which are on the same line?
For example, let's say I have this:
Spam and Eggs is all you need for a healthy breakfast
and I would like to ...
13
votes
2answers
8k views
What is the difference between j, CTRL-J, <NL> and CTRL-N in normal mode?
I saw somewhere on the web someone using Ctrl-J and as I didn't know this mapping I looked up in the relevant doc and found the following:
j or
<Down> or
CTRL-J or
<NL>...
12
votes
6answers
8k views
How to delete line above/below cursor, but not current line?
Is there a command for deleting line (or n lines) above current one? Above = current not included.
I.e., is there an alternative to dk which doesn't delete current line? Similar to how o/O and p/P ...
12
votes
4answers
3k views
Vim HardMode Fine Grain Movements
I recently found out about Vim hard mode and I've decided to try and use it. However, I'm running into some problems with fine grain movements.
For example, let's say I really just want to move up or ...
12
votes
1answer
818 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, ...
12
votes
1answer
3k views
Why does the cursor move to the start of the line after <Esc>?
I've noticed while editing along a line in a .txt file in insert mode the cursor will move to the start of the line following a write using key sequence:
<esc>:w
I'd like to change this ...
11
votes
2answers
5k views
Go to last non-whitespace character of previous/next line?
I like the - and <C-M> normal-mode keys for going to the first non-whitespace character of the previous/next line.
Are there coresponding keys for going to the last non-whitespace character on ...
11
votes
2answers
574 views
Scrolling issues when the `wrap` option is set
I find myself dealing with this issue every time the wrap option is active (in my particular case whenever I'm working with markdown files).
What happens is that, while scrolling up and down the ...
10
votes
3answers
1k 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
2answers
11k views
Go to column number?
I often use something like :80 to quickly go to a line (80 for example).
I'm in a unique situation where I want to go to column 80, to see if lines are too long in files.
Any quick way to do this in ...
10
votes
3answers
2k 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. (...
9
votes
2answers
2k views
Go to X bytes from here
How can I move X bytes forward, starting from the current cursor location (including line breaks)?
[count]go could be used to move forward X bytes from the start of the buffer. I tried Shift + V, G, [...
9
votes
1answer
2k views
Cursor moves one character backwards on exiting insert mode
I recently have noticed that entering and then exiting insert mode will move your cursor one space to the left. This is a default behavior of vim, since it still occurs with vim -u NONE -U NONE -N. ...
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 ...
9
votes
3answers
988 views
How can I delete a function call, leaving its inner content intact?
Let's say I have a line like this:
a = x(y(z));
And I want to change it to:
a = y(z);
What's the most efficient way to do this?
8
votes
6answers
4k views
Using vim when press both opening and closing parenthesis/brackets/etc
When I learned to program, I would press both the opening and closing brackets/etc then the left arrow key then enter the text. So to put in [hello] I would type [], and then the left arrow so that it ...
8
votes
2answers
5k views
Tag navigation using CTRL+] does not work with Non English keyboard on Windows
When using gVim on Windows 7 I cannot use ^] (CTRL+]) to jump to tags as described in the Vim documentation:
<C-LeftMouse> *<C-LeftMouse>* *CTRL-]*
CTRL-] Jump to ...
8
votes
2answers
260 views
What does [count]% do?
I would expect [count]% to jump back and forth between matching braces count times or something like that, but instead, typing that command seems to move the cursor to a random place in the buffer. ...
8
votes
3answers
839 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 ...
8
votes
1answer
3k views
How do I get back to the previous line after moving?
I am new to Vim. My code file has 300 lines. Suppose currently the cursor is on line 254, and I used gg command the cursor turn to line 1. I want to go back to line 254 but I forget that line number. ...
8
votes
1answer
370 views
Motion for moving to non-top-level Python function definition
I'm looking for something like [[ (or [], ]], ][) that works with non-top-level function definitions instead of the next line with a top-level class or function definition on the first character.
...
8
votes
1answer
621 views
Move to next unmatched line with vimdiff
Is there a way to move to the next unmatched line with in vimdiff? Not "move to the next changed line", but move to the next unmatched line for the current file.
In my case I'm trying to compare two ...
7
votes
2answers
7k views
How to go to end/get out of the parenthesis of a line in vim?
I read the solution answered in https://stackoverflow.com/questions/11037825/vim-get-out-of-parenthesis-brackets-etc. That is nothing but command A that takes away you in the end of line.
But, my ...
7
votes
2answers
902 views
Go to the next word starting with specific letter on current line
I want to have the command which is stated in the title. I looked for it in intrinsic Vim command but did not find it. I ran some tutorial online about functions in vim, The idea would be to have ...