如何在 Neovim 中插入缩写标签起始行

How to insert abbreviate hashtag-starting lines in Neovim

我的 ftplugin/cpp.vim 文件夹中有以下行:

inorea <buffer> #def #define

每当我进入 Neovim 时,它总是弹出错误。整个代码是这样的:

if (&ft != 'cpp')
    finish
endif

inorea <buffer> #inc<lt> #include <lt>><left>
inorea <buffer> #inc #include ""<left>
inorea <buffer> #def #define
nnoremap <buffer> #inc<lt> i#include <lt>><left>
nnoremap <buffer> #inc" i#include ""<left>
nnoremap <buffer> #def<Space> i#define 
inoremap <buffer> /* /**/<left><left>

" For Single-File Codes : Save, Compile, and Run
nnoremap <buffer> <F5> :w<CR>:!g++ % -o %<.exe<CR><CR>:!%<.exe<CR>
nnoremap <buffer> <C-F5> :w<CR>:!g++ % -o %<.exe<CR><CR>:tabe<CR>:terminal<CR>3j$a

有趣的是,第 5 行没有弹出错误,它们确实在 .cpp 文件中工作。任何帮助将不胜感激。

缩写的工作方式取决于 'iskeyword' 选项。参见 :h Abbreviations

缩写的左侧可以仅是关键字字符 (full-id),也可以是以关键字字符结尾的非关键字字符 ( end-id), 或任何以非关键字字符结尾的字符 (non-id).

如果#字符不是'iskeyword'部分,则#def是三种类型中的none并且因此 :ab #def ... 无效。因为这是以非关键字字符开头的关键字字符。

'iskeyword' 的格式相当神秘(参见 :h 'isfname'),但默认情况下它设置为 @,48-57,_,192-255。它不包括 #.

快速测试:

:set isk=a-z
:ab #def foo
E474: Invalid argument
:set isk=a-z,#
:ab #def foo

因此,您可以将 set iskeyword+=# 放在缩写之前,但这也可能导致其他问题,因为 'iskeyword' 中的字符用于很多事情。