Multi-line completion inserts have "^@" instead of newlines
Multi-line inserts, like overriding a parent method in Python or complex Rust functions defined by traits, are inserted with a "^@" (null character? \n?) instead.
I've managed to produce this with two language servers, pyright and rust-analyzer.
Pyright:
Rust-analyzer:
Vim version: 9.1.1033 LSP revision: 68a3696e1138f4906a2c863916115bc420396080 (latest as of writing this)
I used this mostly clean vimrc to reproduce it:
set nocompatible
" Plugins
call plug#begin('~/.vim/plugged')
"" Language server client
Plug 'yegappan/lsp'
call plug#end()
"" lsp
""" Configuration
autocmd User LspSetup call LspOptionsSet(#{
\ autoHighlight: v:true,
\ autoHighlightDiags: v:true,
\ showInlayHints: v:true,
\ showDiagsWithVirtualText: v:true,
\ })
""" Language server definitions
let lspServers = [#{
\ name: 'pyright',
\ filetype: 'python',
\ path: 'pyright-langserver',
\ args: ['--stdio'],
\ workspaceConfig: #{
\ python: #{
\ pythonPath: 'python3'
\ }}
\},
\#{
\ name: 'rust-analyzer',
\ filetype: ['rust'],
\ path: 'rust-analyzer',
\ args: [],
\ syncInit: v:true,
\ initializationOptions: #{
\ inlayHints: #{
\ typeHints: #{
\ enable: v:true
\ },
\ parameterHints: #{
\ enable: v:true
\ }
\ },
\ }
\}
\]
autocmd User LspSetup call LspAddServer(lspServers)
This seems to be a known limitation of vim that multiline inserts are not (yet) supported: Proposal: multiline completion support #2505
There is a draft pull-request for solving this in vim: feat(completion): support insert special characters when completion #15373
Interesting, I wasn't expecting it to be a limitation of vim because coc.nvim is able to insert multiple lines. I wonder how it does it.
edit: as far as I can tell coc.nvim overrides some things, takes completion items coming from it's Node.js backend and inserts them like they are snippets.