Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim 为没有扩展名的文件设置文件类型_Vim - Fatal编程技术网

Vim 为没有扩展名的文件设置文件类型

Vim 为没有扩展名的文件设置文件类型,vim,Vim,要将.txt文件设置为显示为标记,我可以执行以下操作: autocmd BufNewFile,BufRead *.txt colorscheme OceanicNext 有没有办法为没有扩展名的文件设置文件类型?例如,如果文件名为notes(无扩展名)。如何对其应用特定的配色方案,例如: autocmd BufNewFile,BufRead <no-extension> colorscheme PaperColor autocmd BufNewFile,BufRead配色方案Pa

要将
.txt
文件设置为显示为标记,我可以执行以下操作:

autocmd BufNewFile,BufRead *.txt colorscheme OceanicNext
有没有办法为没有扩展名的文件设置文件类型?例如,如果文件名为
notes
(无扩展名)。如何对其应用特定的配色方案,例如:

autocmd BufNewFile,BufRead <no-extension> colorscheme PaperColor
autocmd BufNewFile,BufRead配色方案PaperColor

您可以使用
[^.]\+
模式。然而,也有一些观点

  • BufNewFile、BufRead
    事件用于文件类型检测,可能用于一次性缓冲区内容操作等。所有设置更改通常在
    FileType
    事件上进行(这样您也可以支持手动文件类型设置)

  • 同样,您应该使用
    augroup
    ,或者最好将脚本放在
    ~/.vim/ftdetect/
    子目录下以使用标准脚本

  • 文件模式可能更具选择性

  • 那么比如说,

    ~/.vim/ftdetect/mynotes.vim

    ~/.vim/ftplugin/mynotes.vim

    标准序言 如果存在('b:did\ftplugin') 完成 恩迪夫 让b:didftplugin=1 “调整一些缓冲区本地选项 让b:undoftplugin='setl fooau BufNewFile,BufRead [a-z]\+ setf mynotes
    " standard preamble
    if exists('b:did_ftplugin')
        finish
    endif
    let b:did_ftplugin = 1
    
    " tweak some buffer-local options
    let b:undo_ftplugin = 'setl foo< bar< baz<'
    setlocal foo bar baz