[英]Is There event of autocmd in vim triggered by inputing character exceeding the specified column number?
Is There event of autocmd
in vim
triggered by inputing beyond specify column ? 输入超出指定列会触发vim
的autocmd
事件吗? I can't find the event I need. 我找不到我需要的活动。 If the event doesn't exist, can I customize event of autocmd
? 如果事件不存在,我可以自定义autocmd
事件吗? I want to execute a command When my input character exceeds the specified column number. 我要在输入字符超过指定的列号时执行命令。
This command :match Underlined /.\\%>81v/
can specify style of characters beyond 81
, and now I want to run command instead of changing style. 此命令:match Underlined /.\\%>81v/
可以指定超过81
的字符样式,现在我想运行命令而不是更改样式。
The CursorMovedI
event is triggered in insert mode whenever the cursor moves (due to typing, movement, etc.) The current screen column can be queried via virtcol('.')
; 每当光标移动(由于键入,移动等)时,在插入模式下都会触发CursorMovedI
事件。可以通过virtcol('.')
查询当前屏幕列; the col('.')
function returns the byte index , which is different when there are tabs, double-width characters, or any non-ASCII character. col('.')
函数返回字节索引 ,当存在制表符,全角字符或任何非ASCII字符时, 字节索引将有所不同。 So, you can trigger a custom function via 因此,您可以通过以下方式触发自定义功能
:autocmd CursorMovedI * if virtcol('.') > 80 | ... | endif
However, if you're just after automatically inserting a linebreak after a certain column, that functionality is built in. See :help 'textwidth'
(alternatively 'wrapmargin'
) and :help fo-table
. 但是,如果只是在某一列之后自动插入换行符之后,则内置该功能。请参见:help 'textwidth'
'wrapmargin'
(或者'wrapmargin'
)和:help fo-table
。 The following will break text after 80 columns: 以下内容将在80列后中断文本:
:set textwidth=80 formatoptions+=t
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.