Tip #828: pad trailing blanks onto end of lines to ease visual blocks
tip karma |
Rating -3/3, Viewed by 729
|
created: |
|
December 3, 2004 7:14 |
|
complexity: |
|
basic |
author: |
|
Micha Shepher |
|
as of Vim: |
|
5.7 |
I love using the visual block feature to move columns around (<ctrl-v>, blockwise-visual).
However, this does not work conveniently on the last column
when lines are not of equal length. <ctrl-v> marks then a block which
is equal in width to the shortest line.
In order to pad all lines to a given width with trailing blanks
you can use the following functions:
" truncate line 'line' to no more than 'limit' width
function! Truncate( line, limit )
call cursor(a:line,a:limit)
norm d$
endfunc
" Pad all lines with trailing blanks to 'limit' length.
function! AtOnce( limit )
norm mm
g/^/norm 100A
g/^/call Truncate( getline('.'), a:limit )
let @/=""
norm 'm
endfunc
You may alternatively use the oneliner:
:g/^/exe "norm! 100A" | call cursor(getline('.'), 79) | norm d$
I even saw someone use a standard vi (non vim) oneliner to achieve the
same, but I forgot how. Any ideas?
<<XTerm and 256 Colors |
copy & paste between vim session >>
Additional Notes
|