简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM