Ilias Karim
Ilias Karim

Reputation: 5371

Vim: go to line and enter insert mode

How do you go to a line beginning or end and enter insert mode in vim?

For example you can delete a line number 33 with :33d. Is there an equivalent that lets you perform the same action as 36G followed by i or 36G, A so that you can go to line 36 and insert at the start of the line or the end of the line with a single command?

Upvotes: 0

Views: 726

Answers (2)

romainl
romainl

Reputation: 196546

You can use :help :startinsert for that:

:33|star     " go to line 33 and start insert mode before the cursor (like i)
:33|star!    " go to line 33 and start insert mode after the end of the line (like A)

Note that :startinsert doesn't accept a range so we must use :help :| as a workaround.

Also, :startinsert does i and A but it doesn't do I or a. I don't know of any easy workaround. If you feel adventurous, :help feedkeys() could help you craft your own custom commands:

:33|call feedkeys('I')

Upvotes: 2

Amogh Sarpotdar
Amogh Sarpotdar

Reputation: 617

By default you go to start of the line. For example, 5gg will take you to 0th character position on 5th line.

You can combine multiple commands with the help of pipe (|) character. You cannot combine the navigation commands since the moment you type your first navigation command it executes moving the cursor. When you type in next command such as A (Append at the end of the line), it executes too.

Upvotes: 0

Related Questions