在 Vim 中,如果我在代码文件中输入注释,然后点击Enter,它也会自动使换行符成为注释。
例如,在一个 Ruby 文件中:
# I manually typed the pound at the start of this line and hit enter.
# This line formatted itself this way automatically.
Run Code Online (Sandbox Code Playgroud)
一般来说,这就是我想要的,但并非总是如此。如何暂时关闭此自动评论行为?
Mik*_*itz 105
我想你正在寻找
:set formatoptions-=cro
Run Code Online (Sandbox Code Playgroud)
You can use the 'formatoptions' option to influence how Vim formats text.
'formatoptions' is a string that can contain any of the letters below. The
default setting is "tcq". You can separate the option letters with commas for
readability.
letter meaning when present in 'formatoptions'
t Auto-wrap text using textwidth
c Auto-wrap comments using textwidth, inserting the current comment
leader automatically.
r Automatically insert the current comment leader after hitting
<Enter> in Insert mode.
o Automatically insert the current comment leader after hitting 'o' or
'O' in Normal mode.
...
Run Code Online (Sandbox Code Playgroud)
Hep*_*ite 12
临时设置 'paste' 选项可能会满足您的要求,但它也会禁用许多其他 Vim 功能:
使用:set paste
来打开它,并:set nopaste
把它关掉。或者,您可以使用:set paste!
来切换它。
也可以看看:
:help 'paste'
:help 'pastetoggle'
Run Code Online (Sandbox Code Playgroud)
(这些命令是用单引号键入的。)
小智 6
另一种选择是ctrl-w
在您按下 后直接点击enter
。这会在插入模式下删除前一个单词(例如#
或//
)。事实上,ctrl-w
在大多数应用程序中,这是一个非常通用的快捷方式。
小智 5
我使用 . 输入非格式化的纯新行<CR>
。
当我想继续在注释块中输入下一行时,我只需O像往常一样使用该键。
尝试这个:
nnoremap <silent> <cr> :set paste<cr>o<esc>:set nopaste<cr>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
50107 次 |
最近记录: |