rob-135 wrote:
>
>
> Is there a way, like a plugin or a perl/python tool, to draw ascii
> tables like below without having to painfully do it by hand? I'd like
> to be able to a) easily navigate between cells b) <left|right|top|
> bottom> justify text in cell c) edit cells and have the table
> readjust column width, table size??
>
You can try this command :
put this in your .vimrc. It will provide you a command FmtTable that will
format the range you visually select.
Note that you can change the "|" if you prefer to use '\t' or any other
character, and you can also have different characters as input separator and
output separator.
command! -range FmtTable python FmtTable(<f-line1>,<f-line2>)
python << EOS
def FmtTable(line1,line2):
import vim, string
inputSeparator='|'
outputSeparator="|"
cb=vim.current.buffer.range(int(line1)-1,int(line2))
colLen=[]
# first we collect col lengths and calculate the longest
for line in cb[1:]:
spLine=line.split(inputSeparator)
for i in range(len(spLine)):
try:
if len(spLine[i]) > colLen[i]:
colLen[i] = len(spLine[i])
except IndexError:
colLen.append(len(spLine[i]))
tmpBuf=[]
# Then we fill the cols with spaces
for line in cb[1:]:
spLine=line.split(inputSeparator)
newLine=outputSeparator.join([spElt.ljust(colLen[i]) for i, spElt in
enumerate(spLine)]) + outputSeparator
tmpBuf.append(newLine)
cb[1:]=tmpBuf[:]
EOS
--
View this message in context:
http://www.nabble.com/creating-%28ascii%29-tables-tp21116904p21125884.html
Sent from the Vim - General mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---