当我在这里使用我的vimrc时:
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set smarttab
我安装了supertab插件。每当我处于插入模式时,我按Tab键,它会显示自动完成,但有时我想在字符串文字中插入一个真正的制表符。所以我的意思是每当我在双引号字符串文字中按Tab键时,它应该输入一个真正的制表符。
答案 0 :(得分:95)
在插入模式或命令模式下(编辑器底部的:
提示符),键入 CTRL + V 然后 TAB < / KBD>。
使用 CTRL + V 向Vim发出信号表明它应该按字面意思取下一个字符。即使在插入模式下也是如此。
更新:
如Herbert Sitz所述,如果gVim处于Windows模式(默认),则必须使用 CRTL + Q 代替 CTRL + V 。
答案 1 :(得分:0)
这是一种解决方法:
选择文本(可视模式)并执行搜索/替换,
:'s/`/\t/g
更新的答案,灵感来自@Cyryl1972的评论。
在所有行的开头插入制表符(另请注意:对于以下任何代码,无需选择行,因为它包含在表达式的行匹配部分中):
:1,$s/^/\t\1/
所有行中前10个字符后的惰性标签:
:1,$s/^\(.\{10}\)/\1\t/
解释 - 第一部分:
:1,$ Match from line 1 to end of file
^(.{10} Collect (preserve) all text from beginning of line to position 10
(you need to escape the parentheses, \( and \), as well the FIRST
(left) curly brace, only: \{ -- as it, { , appears to have special
meaning in regex when used for this purpose
说明 - 第二部分:
/1 Add back the preserved text
\t Insert a tab
...并且该线的其余部分也会自动恢复。
当前行,仅限:
:s/^/\t\1/
示例:在第2-4行插入标签(0-indexed):
1234567890abcdefghij
1234567890abcdefghij
1234567890abcdefghij
1234567890abcdefghij
1234567890abcdefghij
:2,4s/^\(.\{10}\)/\1\t/
1234567890abcdefghij
1234567890 abcdefghij
1234567890 abcdefghij
1234567890 abcdefghij
1234567890abcdefghij
引用(StackOverflow):
参考文献(其他):