Home » Questions » Computers [ Ask a new question ]

Vim: always navigate to set column when changing line

Vim: always navigate to set column when changing line

Is there an equivalent in Vim to the idea of a "goal column" in Emacs?

Asked by: Guest | Views: 380
Total answers/comments: 1
Guest [Entry]

"You could use a macro - position to the column and then:

:map ,1 i123 <Esc>bj

... and keep typing ,1; or you could use Vim's macro recording feature (:help recording):

qai123 ^[bjq

(that stores the macro in a register 'a', the final q ends recording).

Then you can use a repeat count (from the appropriate column) and invoke the recorded macro with @a:

100@a

If you want to enter different text each time, and just have a smarter next-line feature, you can create a macro for that:

:imap ,, <Esc>j5^V|i

That ^V is a literal Control-V, entered by typing ControlV twice; the next char is a pipe, which will move the cursor to column 5.

You'd use this macro in input mode, entering the digits, then a space, then ,, which would move you to the next line at column 5, still in input mode.
Then when you're done: :iunmap ,,"