First, I apologize if this is a trivial question.
I have the following file (main.ab) defining a Python snippet:
def main(args):
...
if name == 'main':
args = ...
main(args)
And in ftplugin/python.vim I defined
iabbrev <expr> main join(readfile($HOME . "/.vim/ftplugin/main.ab"), "\n")
which results in a badly indented output:
def main(args):
...
if __name__ == '__main__':
args = ...
main(args)
although executing :echo join(readfile($HOME . "/.vim/ftplugin/main.ab"), "\n") results in:
def main(args):
...
if name == 'main':
args = ...
main(args)
How should I correctly insert the file contents when expanding an abbreviation?
I assume this is related to PASTE mode, but I don't see an immediate solution. Is there an alternative to join(readfile(...))?
mainsnippets reading:h skeletonmight be interesting. – statox Jun 18 '21 at 11:29=and then paste from it:iabbrev <expr> main <c-r>=join(readfile($HOME . "/.vim/ftplugin/main.ab"), "\n")<CR>:put =<CR>, but I am getting the "invalid expression" error. Do you mean to bypassiabbreventirely? – Alexandru Dinu Jun 18 '21 at 12:00iabbrev main <C-r>=join(…)<CR>oriabbrev main <C-o>:put =join(…)<CR>, but I’m not in front of a kbd to test. – D. Ben Knoble Jun 18 '21 at 12:08