Go to beginning of line without opening new line in VI

VimVi

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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.

Solution 2 - Vim

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

:help 0 for more information

Solution 3 - Vim

Try this Vi/Vim cheatsheet solution to many problems.

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

Solution 4 - Vim

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).

Solution 5 - Vim

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)

Solution 6 - Vim

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

Solution 7 - Vim

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

Solution 8 - Vim

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

Solution 9 - Vim

0 Takes you to the beginning of the line

Shift 0 Takes you to the end of the line

Solution 10 - Vim

You can also use

:-0

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrixView Question on Stackoverflow
Solution 1 - VimXavier T.View Answer on Stackoverflow
Solution 2 - VimFredrik PihlView Answer on Stackoverflow
Solution 3 - VimcuriousMonkeyView Answer on Stackoverflow
Solution 4 - Vima8mView Answer on Stackoverflow
Solution 5 - VimAndriy DrozdyukView Answer on Stackoverflow
Solution 6 - VimrashokView Answer on Stackoverflow
Solution 7 - VimSkippy FastolView Answer on Stackoverflow
Solution 8 - Vimbrian_wangView Answer on Stackoverflow
Solution 9 - VimSagar JainView Answer on Stackoverflow
Solution 10 - VimMatthew AlsupView Answer on Stackoverflow