Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to start append mode with a command in Vim?

Tags:

comments

vim

I am trying to edit a stript in Vim that appends a comment to the end of the line then puts the cursor at the end of the line and sets it to insert mode. However, I noticed that the comment placed at the end of the line has a space after it (e.g. if the comment styles in a particular language were // and /* */, then the text appended to the end of the line would be "// " or "/* */". In the .vim plugin, the command startinsert is used. However, this places the cursor before the space, rather than after. So rather than a comment being generated like this:

// This comment is prepended with a space!
/* This is a great commment! */

It ends up looking like this (note the trailing space):

//This comment is poorly formatted 
/*So is this one.*/

In Vim, is there any command equivalent to 'startappend', which will place the user into little-a append mode rather than insert mode? This way, the user doesn't need to use the right arrow key every time they generate an end-of-line comment with this script.

If this function doesn't exist, how would one go about creating this function?

like image 962
Phro Avatar asked Nov 21 '25 03:11

Phro


1 Answers

Technically append mode is a normal mode, the difference is that the cursor is moved first before entering the insert mode. Try moving the cursor to the right after you call startinsert:

call cursor( line('.'), col('.') + 1)
like image 195
egdmitry Avatar answered Nov 22 '25 22:11

egdmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!