Editor 板


LINE

基本上可以使用 set shiftwidth=4 來設定 tab 寬。 而使用 set expandtab 來將 tab 轉成 space (實際存起來的檔案將會是以 space , not tab ) 如果要將既有的 <Tab> 轉成 space 可以再 expandtab 之後輸入: :retab! 來做轉換。 而 tabstop 是實際上讀到檔案的 \t (Tab 字元) 時,要解譯為幾個空白 通常設定為 4 set tabstop=4 另外 softtabstop 則是,你在編輯動作 (Backspace) 或是 (Tab) 時,對空白的解譯 譬如說: set noexpandtab set sw=4 set tabstop=4 set softtabstop=4 新加入的 Tab 都會是 \t , Tab 為 4 個 space ,讀取檔案的 \t 會被顯示為 4 個 space ,在操作 BS 的時候,4 個顯示的空白會被當作一個 tab 刪除。 實際上 softabstop 比較常用在 expandtab 的模式下: set expandtab set sw=4 set tabstop=4 " 怕檔案裡頭仍有 \t set softtabstop=4 如此被延展為空白的 space 也可以像是 tab 一樣被刪除固定的 space 數 (softtabstop=4) 附帶一題,由於 tab 每個人的用法都不一樣,而且變化很多 所以現在很多專案都只使用 space 而不使用 tab 了! 也就是: set et sw=4 ts=4 sts=4 設定是被建議的。 當然如果你寫 python 就不一樣。 :p 這邊順便引入 vim help 的 'tabstop' 章節: There are four main ways to use tabs in Vim: 1. Always keep 'tabstop' at 8, set 'softtabstop' and 'shiftwidth' to 4 (or 3 or whatever you prefer) and use 'noexpandtab'. Then Vim will use a mix of tabs and spaces, but typing <Tab> and <BS> will behave like a tab appears every 4 (or 3) characters. 2. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use 'expandtab'. This way you will always insert spaces. The formatting will never be messed up when 'tabstop' is changed. 3. Set 'tabstop' and 'shiftwidth' to whatever you prefer and use a |modeline| to set these values when editing the file again. Only works when using Vim to edit the file. 4. Always set 'tabstop' and 'shiftwidth' to the same value, and 'noexpandtab'. This should then work (for initial indents only) for any tabstop setting that people use. It might be nice to have tabs after the first non-blank inserted as spaces if you do this though. Otherwise aligned comments will be wrong when 'tabstop' is changed. ※ 引述《shanmi (4/27視小中友之夜)》之銘言: : 我在寫fortran77 : 所以常常需要空個字元 : 我都按tab : 我用geditor 發現他可以設定tab=空幾格 : 所以是不是各家編輯器對tab的設定不同? : 或者等到程式compile時也會把一個tab讀成不同的空格數? : 這樣似乎要小心使用tab了 : 小弟剛開始寫程式 : 感謝各位 -- --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 113.61.198.68 ※ 編輯: kornelius 來自: 113.61.198.68 (02/05 23:10) ※ 編輯: kornelius 來自: 113.61.198.68 (02/05 23:12)
1F:推 Uruzu:補個小技巧,設了expandtab後,想插入tab時,在insert mode 02/05 23:18
2F:→ Uruzu:下,先按ctrl+v 再輸入tab就是真的tab了 02/05 23:19
※ 編輯: kornelius 來自: 113.61.198.68 (02/05 23:35)
3F:推 shanmi:太感謝了! 請問set shiftwidth是vi的指令嗎? 02/08 16:42
4F:推 PCIT:是的 02/09 01:53
5F:推 zwai:強! 受益良多~ 02/09 22:39
6F:推 iwhiori:推!! 03/25 10:30
7F:推 darkgerm:推!! 08/09 18:40







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP