I'm trying to use VIM for Word Processing situations where, for example, I might need to put the date at the 70th column of a line that has no other text on it. So, for example, if there's currently no text on line 1 and I want to insert something at column 70, the only way I know how to get to column 70 is by hitting the space bar while in insert mode, a very slow process.

Is there a way to do what I'm trying to achieve in VIM? i.e. to jump ahead to a particular column in a blank line. Even if I could do something like 70l (move 70 spaces to the right) would be amazing, but it doesn't work on a line without any text.


You could also consider virtualedit which allows you to pace the cursor any where regardless of if there is a character there.

Use (short form set ve=all)

:set virtualedit=all

to enable it. Then use 70| to go to the 70 column. Take a took at :help 'virtual edit'

To turn it off use :set virtualedit= (Short form set ve=)

  • thanks, it's great but how to unset, doesn't say in docs, set novirtualedit doesn't do it, nor does set novirtualedit=all – BrainLikeADullPencil Aug 30 '14 at 2:26
  • This is a great answer, I did not know about the virtualedit option! @BrainLikeADullPencil: the default is set virtualedit=, with no arguments. (edit - oh, he mentions that in the answer too, I suppose it was edited to contain this information) – Valmiky Arquissandas Aug 31 '14 at 0:22

You can do 70i followed by esc (that's 70ispacebarEsc).

For the specific case you mention - adding the date on the 70th column:

  • 69ispacebarEsc$

    This will create 69 spaces and the cursor will be on the 69th column;

  • :r !date Enter

    This will copy the output of the date command into the edit buffer (on the next line);

  • backspaceJ

After this step, you have the date, starting on the 70th column.

There probably is an easier way, but at least this one works for sure.

  • really nice thanks. I'll see what others come up with before I accept – BrainLikeADullPencil Aug 29 '14 at 22:55
  • What is backspace Jactually telling VIM to do? I see that it works in this situation but would like to know the instruction it's giving – BrainLikeADullPencil Aug 29 '14 at 23:02
  • If you accept it, great! But even if this isn't the accepted answer, if you find it worthy, you can always upvote it ;) – Valmiky Arquissandas Aug 29 '14 at 23:03
  • 1
    backspace is just my way of moving to the previous line. You can also use the k character to do the same thing (but backspace moves it to the end of the previous line, which is intuitively what I wanted to do, even if it isn't actually necessary). J joins the current line with the next one, effectively making them a single, larger line. Since the :r command inserts the output in the next line, I had to join them. – Valmiky Arquissandas Aug 29 '14 at 23:05
  • your solution is best for vi, but the virtualedit response is better for vim (imo) – BrainLikeADullPencil Aug 30 '14 at 2:33

Not the prettiest way to do it, but you can modify the shiftwidth, which is the size of a single tab. In command mode type in :set shiftwidth=1 and then type in what you want at column 70, then use the command: V (uppercase ´v´) to highlight your current line and then type 70>. That should tab your text over 70 columns.

Then after that, it might be a good idea to set your shiftwidth back to 4, to make tabbing more consistent. Unless this is a task you do pretty often and you have no use for tabbing.

  • hmm, I have a WordPressing function that I can toggle (see drbunsen.org/writing-in-vim) I guess I could put the shift width in there and then it will revert back when I leave WP mode – BrainLikeADullPencil Aug 29 '14 at 22:51
  • This is a good idea, but only if you have the :set expandtab activated, so that you actually write 70 spaces, instead of a single tab character. – Valmiky Arquissandas Aug 29 '14 at 23:02

Another way can be to set tabstop to 70 and set expandtab to expand tabs to spaces:

:se ts=70
:se et

And then you can hit the tab key to get to the 70th column.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.