I know how to generally move around in command mode, specifically, jumping to lines, etc. But what is the command to jump to the end of the line that I am currently on?
17 Answers
Just the $ (dollar sign) key. You can use A to move to the end of the line and switch to editing mode (Append). To jump to the last non-blank character, you can press g then _ keys.
The opposite of A is I (Insert mode at beginning of line), as an aside. Pressing just the ^ will place your cursor at the first non-white-space character of the line.
7 Comments
g_g$ to reach the end of the current wrap.As lots of people have said:
- $ gets you to the end of the line
but also:
- ^ or _ gets you to the first non-whitespace character in the line, and
- 0 (zero) gets you to the beginning of the line incl. whitespace
3 Comments
| command can take a count, e.g. 3| to jump to the third column.- $ moves to the last character on the line.
g _ goes to the last non-whitespace character.
g $ goes to the end of the screen line (when a buffer line is wrapped across multiple screen lines)
9 Comments
b goes to the beginning of the previous word which is not the same thing at all. It's roughly equivalent to $ge._ and g_ for visual/yanking, as $ will also copy/delete the new line (LN) character.g_ is the only way I found to get to the actual end of the line.$ goes to the end of the line even when wrapped for me. I know of no setting to adjust its behaviour. Perhaps it's been remapped by your .vimrc to g$?The main question - end of line
$ goes to the end of line, remains in command mode
A goes to the end of line, switches to insert mode
Conversely - start of line (technically the first non-whitespace character)
^ goes to the start of line, remains in command mode
I (uppercase i) goes to the start of line, switches to insert mode
Further - start of line (technically the first column irrespective of whitespace)
0 (zero) goes to the start of line, remains in command mode
0i (zero followed by lowercase i) goes the start of line, switches to insert mode
For those starting to learn vi, here is a good introduction to vi by listing side by side vi commands to typical Windows GUI Editor cursor movement and shortcut keys.
Comments
I can't see the hotkey for a MacBook for using Vim in the standard terminal.
For macOS users (tested on a MacBook Pro 2018):
fn + ← - move to the beginning of the line
fn + → - move to the end of the line
fn + ↑ - move a page up
fn + ↓ - move a page down
fn + g - move the cursor to the beginning of the document
fn + shift + g - move the cursor to the end of the document
For the last two commands, it sometimes needs to be tapped twice.
3 Comments
gg move cursor to the top of document and G move cursor to the bottom of the document?If your current line wraps around the visible screen onto the next line, you can use g$ to get to the end of the screen line.
3 Comments
gw and gq are commands that reformat text. (see :h gw and :h gq) What probably happened was you did gw{motion} and changed some text so that the screen lines corresponded to the actual lines.Press A to enter edit mode starting at the end of the line.
2 Comments
Shift + AAlso note the distinction between line (or perhaps physical line) and screen line. A line is terminated by the End Of Line character ("\n"). A screen line is whatever happens to be shown as one row of characters in your terminal or in your screen. The two come apart if you have physical lines longer than the screen width, which is very common when writing emails and such.
The distinction shows up in the end-of-line commands as well.
- $ and 0 move to the end or beginning of the physical line or paragraph, respectively:
- g$ and g0 move to the end or beginning of the screen line or paragraph, respectively.
If you always prefer the latter behavior, you can remap the keys like this:
:noremap 0 g0 :noremap $ g$ 2 Comments
g_ is last non-whitespace of the physical line. How about screen line?In many cases, when we are inside a string we are enclosed by a double quote, or while writing a statement we don't want to press escape and go to end of that line with arrow key and press the semicolon(;) just to end the line. Write the following line inside your vimrc file:
imap <C-l> <Esc>$a What does the line say? It maps Ctrl+l to a series of commands. It is equivalent to you pressing Esc (command mode), $ (end of line), a (append) at once.
6 Comments
vim certainly allows you to do much more in much less time with things like this. @razorxpress, a minor adjustment would be imap <C-l> <Esc>A, which makes Ctrl+l the equivalent of pressing Esc (exit insert mode), then A (append to end of line).inoremap <C-l> <C-o>AOr there's the obvious answer: use the End key to go to the end of the line.
7 Comments
I was used to Home and End getting me to the start and end of lines in insert mode (from use in Windows and I think Linux), which Mac doesn't support.
This is particularly annoying because when I'm using Vim on a remote system, I also can't easily do it. After some painful trial and error, I came up with these .vimrc lines which do the same thing, but bound to Ctrl + A for the start of the line and Ctrl + D for the end of the line. (For some reason, Ctrl + E I guess is reserved or at least I couldn't figure a way to bind it.) Enjoy.
:imap <Char-1> <Char-15>:normal 0<Char-13> :imap <Char-4> <Char-15>:normal $<Char-13> There's a good chart here for the ASCII control character codes here for others as well:
You can also do Ctrl + V, + Ctrl + <Letter> you want to bind or execute as well, but that doesn't paste as well to places like this.
Comments
To jump behind the last character in insert mode (especially when the End button isn't available as a user described above) there is a way without having to add any extra functionality to the .vimrc.
By pressing Ctrl + O first and then $ the cursor is placed behind the last character of the line.