How to align a column using the vi editor? -
i have column in numbers below
-0.01343 0.002 -1.1234
i want align column in vi editor below
-0.01343 0.002 -1.1234
so, want insert space before each line not starting minus:
the appropriate command is :%s/^\([^-]\)/ \1/
this breaks down as:
:
- start command
%s
- regex on lines
/^\([^-]\)
- matching start of line, followed character other -
, call group 1
/ \1
- replace space followed whatever in group 1
/
- end regex, perform no more once on each line
other options:
if select intended lines in visual block, typing :
start command '<,'>
. move onto regex starting s
(no %
) , apply selected lines.
if end /c
ask confirmation on each replacement. if end /g
work multiple times per line if applicable. /gc
valid.
if you'd wanted decimal points aligned, rather first digits, that's more complex , cannot done simple command in vi or vim.
Comments
Post a Comment