Search code examples
vimvi

Placing characters at a specific column in vi


Is there a way to place a character at a specific line in vim, even if the line is short?

For example, I'm contributing to a project which has a comment block style which is 79 columns wide, with a comment character at either end e.g.

!--------------!
! Comment      !
! More Comment !
!--------------!

but it's really annoying to space over to it, even with guessing large numbers (35i< SPACE>< ESC>)

Is there a simple command which will do this for me, or a macro or something I could write?


Solution

  • set ve=all
    

    then you could move (h,j,k,l) to anywhere you want. no matter how short your line is.

    there are 4 options block, all, insert, onemore for details:

    check :h virtualedit

    in this way, after you typed short comment, then type <ESC>080l to go to the right place to the tailing !

    you can map it too, if it is often used

    then it works like this:

    enter image description here