gpt4 book ai didi

vim - 使用单个 `.vimrc` 按文件类型更改 Vim 行为(不带 ftplugin)

转载 作者:行者123 更新时间:2023-12-02 01:16:22 24 4
gpt4 key购买 nike

如何使用单个 .vimrc 文件(无需 ftplugin)以优雅的方式更改 Vim 行为?

我的意思是...如果我对 C/C++ 文件运行许多推荐,例如:

set nu
set cin
set ai
set mouse=a
color elflord

以及对 AsciiDoc 文件的另一堆赞扬,例如:

set syntax=asciidoc
set nocin
set spell spl=en

更不用说 Python、LaTeX 等......

已提出解决方案 https://stackoverflow.com/a/159065/544721用于将 autocommand 放在每个自定义命令之前。

有没有一种好的方法可以将它们分组为 autocommand 而无需使用 ftplugin - 以便将所有内容保留在单个 .vimrc 文件中(更好用于在许多机器周围移动等)?相当于带有括号 {}if 语句?

最佳答案

您可以使用以下内容:

if has("autocmd")
augroup LISP
au!
au BufReadPost *.cl :set lisp
au BufReadPost *.cl :set showmatch
au BufReadPost *.cl :set cpoptions-=m
au BufReadPost *.cl :set autoindent
augroup END
augroup C
au!
autocmd BufNewFile,BufRead *.cpp set formatprg=c:\\AStyle\\bin\\AStyle.exe\ -A4Sm0pHUk3s4
autocmd BufNewFile,BufRead *.c set formatprg=c:\\AStyle\\bin\\AStyle.exe\ -A4Sm0pHUk3s4
autocmd BufNewFile,BufRead *.h set formatprg=c:\\AStyle\\bin\\AStyle.exe\ -A4Sm0pHUk3s4
autocmd BufNewFile,BufRead *.cpp set tw=80
autocmd BufNewFile,BufRead *.c set tw=80
autocmd BufNewFile,BufRead *.h set tw=80
augroup END
endif

这会根据打开的文件类型(在 autocmd 部分中指定)创建命令分组。您仍然需要在每个命令之前指定 autocmd 或 au,但它们很好地分组。

关于vim - 使用单个 `.vimrc` 按文件类型更改 Vim 行为(不带 ftplugin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11785260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com