266

For ages now I've used SHIFTO and SHIFT$ to move to the beginning and end of a line in vi.

However SHIFTO is more for opening a new line above the cursor.

Is there any command which just takes you to the start of a line?

Zsolt Botykai
  • 50,406
  • 14
  • 85
  • 110
rix
  • 10,104
  • 14
  • 65
  • 92

10 Answers10

488

You can use ^ or 0 (Zero) in normal mode to move to the beginning of a line.

^ moves the cursor to the first non-blank character of a line
0 always moves the cursor to the "first column"

You can also use Shifti to move and switch to Insert mode.

Stephan
  • 16,509
  • 7
  • 35
  • 61
Xavier T.
  • 40,509
  • 10
  • 68
  • 97
  • 8
    Also Shift+A and Shift+I goes to end and beginning of line respectively and also switches to Insert Model – Bibek Shrestha Oct 30 '14 at 12:42
  • 11
    For me, pressing `^` is usually not as easy as pressing `0` and `w` consecutively. – DXDXY Feb 11 '16 at 00:51
  • ^ is easier to remember if you work a lot with regular expressions, but 0 actually while ^ doesn't (anymore) in vi in my Ubuntu bash terminal window – Ingo Steinke Jul 27 '23 at 09:53
41

A simple 0 takes you to the beginning of a line.

:help 0 for more information

Fredrik Pihl
  • 44,604
  • 7
  • 83
  • 130
32

Try this Vi/Vim cheatsheet solution to many problems.

For normal mode :
0 - [zero] to beginning of line, first column.
$ - to end of line

curiousMonkey
  • 677
  • 6
  • 15
13

You can use 0 or ^ to move to beginning of the line.
And can use Shift+I to move to the beginning and switch to editing mode (Insert).

a8m
  • 9,334
  • 4
  • 37
  • 40
  • 2
    You answer is mostly correct but there's a small caveat. `Shift+I` or `^` will move cursor to beginning of the **text** in the line. If line has `n` tabs in the beginning, it'll move cursor to `n*tabstop + 1`th column. While `0` moves cursor to the *very first column* of the line. – narendra-choudhary Jun 23 '16 at 16:52
13

There is another way:

|

That is the "pipe" - the symbol found under the backspace in ANSI layout.

Vim quickref (:help quickref) describes it as:

N      |      to column N (default: 1)

What about wrapped lines?

If you have wrap lines enabled, 0 and | will no longer take you to the beginning of the screen line. In that case use:

g0

Again, vim quickref doc:

 g0   to first character in screen line (differs from "0"
      when lines wrap)
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
  • Now I see why it works. Thanks. I was wondering. I think it is better than `0` because `|` and `$` are on the same key. – WesternGun May 03 '18 at 08:32
12

Move the cursor to the begining or end with insert mode

  • I - Moves the cursor to the first non blank character in the current line and enables insert mode.
  • A - Moves the cursor to the last character in the current line and enables insert mode.

Here I is equivalent to ^ + i. Similarly A is equivalent to $ + a.

Just moving the cursor to the begining or end

  • ^ - Moves the cursor to the first non blank character in the current line
  • 0 - Moves the cursor to the first character in the current line
  • $ - Moves the cursor to the last character in the current line
rashok
  • 12,790
  • 16
  • 88
  • 100
7

Type "^". And get a good "Vi" tutorial :)

Skippy Fastol
  • 1,745
  • 2
  • 17
  • 32
5

I just found 0(zero) and shift+0 works on vim.

brian_wang
  • 401
  • 4
  • 16
2

0 Takes you to the beginning of the line

Shift 0 Takes you to the end of the line

Sagar Jain
  • 7,475
  • 12
  • 47
  • 83
2

You can also use

:-0

This sets the cursor at the present line (blank here) at the 0 column.

Matthew Alsup
  • 31
  • 1
  • 3