看板 Editor 關於我們 聯絡資訊
※ 引述《Xphenomenon (啦 )》之銘言: : 想請問一下,我希望可以有這樣子的功能: : 第一章 : ====== <== 希望自動產生 : 當我打完 “第一章”之後,在下一行我要全打 "=",現在我的做法是 6i=<esc>, : 但是這樣子我每次的標題我都需要去計算有幾個文字,有沒有辦法讓我可以在 : 目前這一行他會自動去計算上一行的文字數,然後在這一行可以使用的? : 先謝謝大家的回答。:) OB 查了一下如何寫簡單的 vim script, 給跟我一樣有需要的人: function! CountWords(char) let counter = strwidth(getline(".")) let result = repeat(a:char, counter) let failed = append(line("."), result) call cursor(line('.')+2, 0) endfunction map <leader>c- :call CountWords('-')<cr>O map <leader>c# :call CountWords('#')<cr>O map <leader>c~ :call CountWords('~')<cr>O 值得注意的是,函數 strwidth() 只出現在 7.3 版本,舊版的恐怕沒辦法使用喔。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.218.156