I am trying to make a plugin, which will be displaying a content of registers in the side bar and updating this side bar at every register's changing.
To accomplish this task I decided to set a hook on the
TextYankPost event and to write a changed register's dictionary into the side bar window when this event happens.
But there is a problem - the
autocmd doesn't allow writing commands like
:put inside a called function, so when I do:
function! Write_to_buffer() put ='hello' endfunction autocmd TextYankPost * :call Write_to_buffer()
I get an error
Error detected while processing function Write_to_buffer: line 1: E523: Not allowed here
Without a writing command all works as expected:
function! Write_to_buffer() echo 'hello' endfunction autocmd TextYankPost * :call Write_to_buffer()
:h E523 says:
When on, ":autocmd", shell and write commands are not allowed in ".vimrc" and ".exrc" in the current directory and map commands are displayed. Switch it off only if you know that you will not run into problems, or when the 'exrc' option is off. On Unix this option is only used if the ".vimrc" or ".exrc" is not owned by you. This can be dangerous if the systems allows users to do a "chown". You better set 'secure' at the end of your ~/.vimrc then.
exrc options are off in my case:
echo printf('secure = %s, exrc = %s', &secure, &exrc) " Output: secure = 0, exrc = 0
So the questions:
- Is the usage of the
autocmdfor tracking register changes right/optimal?
- How can a function called by the
autocmdbe used for writing into a buffer?