最近突然对纯文本编辑比较感兴趣,Google了一下,没有发现什么好的Win下可用的纯文本编辑器支持直接的表格编辑

于是想到了Vim

下面的就是用Vim编辑的一个示范例子

===============================================================================
Name Description Remark
AA Test OK
BB Good Great
——————————————————————————–

为了简便快速的编辑这个表格,需要编辑一下我们的_vimrc文件或其子配置文件

下面的代码摘自我的配置文件

map <S-Tab> :call NextField(’ \{2,}’,2,’ ‘,0)<CR>
map! <S-Tab> <C-O>:call NextField(’ \{2,}’,2,’ ‘,0)<CR>
” function: NextField
” Args: fieldsep,minlensep,padstr,offset

” NextField checks the line above for field separators and moves the cursor on
” the current line to the next field. The default field separator is two or more
” spaces. NextField also needs the minimum length of the field separator,
” which is two in this case. If NextField is called on the first line or on a
” line that does not have any field separators above it the function echoes an
” error message and does nothing.func! NextField(fieldsep,minlensep,padstr,offset)
let curposn = col(”.”)
let linenum = line(”.”)
let prevline = getline(linenum-1)
let curline = getline(linenum)
let nextposn = matchend(prevline,a:fieldsep,curposn-a:minlensep)+1
let padding = “”

if nextposn > strlen(prevline) || linenum == 1 || nextposn == 0
echo “last field or no fields on line above”
return
endif

echo “”

if nextposn > strlen(curline)
if &modifiable == 0
return
endif
let i = strlen(curline)
while i < nextposn - 1
let i = i + 1
let padding = padding . a:padstr
endwhile
call setline(linenum,substitute(curline,”$”,padding,”"))
endif
call cursor(linenum,nextposn+a:offset)
return
endfunc

现在这个简单的表格的编辑过程如下所列:

1. 80i=<ESC>

2. Name Description Remark

3. AA<S-Tab>Test<S-Tab>OK

4. BB<S-Tab>Good<S-Tab>Great

5. 80i-<ESC>

上面的配置文件参考这里:http://www.vim.org/tips/tip.php?tip_id=547