如何编写(自动)仅适用于特定文件夹的 vimrc 文件 [英] how to write a vimrc file that (automatically) applies only to a specific folder

查看:27
本文介绍了如何编写(自动)仅适用于特定文件夹的 vimrc 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个项目位于名为bin"的文件夹中,我希望在编辑项目文件夹中的任何文件时自动加载一些特定的 vim 配置.我该怎么做?

say that i have a project which lies in a folder called 'bin', and i want some specific vim configuration automatically loaded when i edit any file inside the project folder. how can i do that?

推荐答案

我认为你想要的是一个自动命令.也许是这样的:

I think what you want is an autocommand. Perhaps something like this:

autocmd BufRead,BufNewFile ~/bin/* call SetBinOptions()

function SetBinOptions() {
    setlocal number
    setlocal nowrap
    ...
}

如果您需要对路径匹配做一些复杂的事情,您可以采用稍微不同的方法,决定是否在函数内应用选项.假设你有一些路径必须匹配的正则表达式:

If you need to do something complex with the path matching, you can take a slightly different approach, making the decision about whether to apply the options within the function. Suppose you had some regex the path had to match:

autocmd BufRead,BufNewFile * call SetCustomOptions()

function SetCustomOptions() {
    if (match(expand("%:p"), /regex/) {
        setlocal number
        setlocal nowrap
        ...
    }
}

这篇关于如何编写(自动)仅适用于特定文件夹的 vimrc 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆