Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert space until column

Tags:

emacs

I have to enter in the following format...

A          B          C
D          E          F
[]

I use indent-relative to jump from one column to another. But is there a way to jump to column number? And if so, is there a way to insert spaces until that column?

like image 451
iobelix Avatar asked Feb 10 '11 03:02

iobelix


2 Answers

Maybe indent-to-column would work for you.

indent-to-column is an alias for `indent-to'.

(indent-to-column COLUMN &optional MINIMUM)

Indent from point with tabs and spaces until COLUMN is reached.
Optional second argument MINIMUM says always do at least MINIMUM spaces
even if that goes past COLUMN; by default, MINIMUM is zero.

The return value is COLUMN.

It enters tabs too, but you can clean those up when you're done with the untabify command.

like image 57
Mike Avatar answered Nov 16 '22 01:11

Mike


You can use move-to-tab-stop with a custom tab-stop-list variable to denote your columns. You could use M-x edit-tab-stops RET to configure this variable in a visual manner.

You can also use M-x ruler-mode RET and M-x ruler-mode-toggle-show-tab-stops RET to view your tab stops.

For jumping multiple columns, move-to-tab-stop doesn't repeat with a prefix arg, but if you define a keyboard macro which calls it, you can then use the prefx arg to repeat it as many times as you require:

Record macro:
F3 M-x move-to-tab-stop RET F4

Either bind to key temporarily:
C-x C-k b (key)

Or name it and ask Emacs to provide you with the elisp to put in your init file:
C-x C-k n (name) RET
M-x insert-kbd-macro RET (name) RET
(global-set-key (kbd "key") 'name) (for the appropriate key and name)

You can enter a numeric prefix arg with any of:
C-u number(s)
M- number(s)
C- number(s)

e.g. if you had bound the macro to C-i then M-4 M-2 C-i would move forward forty two tab stops, and so would C-u 4 2 C-i

Set the indent-tabs-mode variable to nil to prevent tabs being inserted.

like image 34
phils Avatar answered Nov 15 '22 23:11

phils