简体   繁体   中英

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 ? I can't find the event I need. If the event doesn't exist, can I customize event of 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.

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('.') ; the col('.') function returns the byte index , which is different when there are tabs, double-width characters, or any non-ASCII character. 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 . The following will break text after 80 columns:

:set textwidth=80 formatoptions+=t

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM