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灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP