Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I'd like to set a goal column, so whenever I navigate to a new line in Insert mode, the cursor is automatically positioned at that given column.

e.g I have the text:

foo bar
foo bar
foo bar

I type 123<space> in between foo bar on the first line and then have (pipe symbol shows where my cursor is):

foo 123 |bar
foo bar
foo bar

I press the down arrow... and I end up here:

foo 123 bar
foo bar|
foo bar

But I want to end up here:

foo 123 bar
foo |bar
foo bar

The use case being that I'm typing a list of numbers to insert in some existing text, and I want to just whizz through by typing a number, then pressing down, then next number, down, number, down, number, down, etc, without having to reposition my cursor each time.

share|improve this question
Tried it with a macro ? – Rook Jan 10 '10 at 14:39
up vote 4 down vote accepted

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:


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 ,,

share|improve this answer
Excellent, the second part of your answer solves the problem. I wasn't previously aware of imap, and I can see it's going to be extremely useful. – ngm Jan 18 '10 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .