使用来自多个目录和多个扩展名的vim将头文件打开为C/C ++源文件 [英] Opening the header file to a C/C++ source file with vim from multiple directories and multiple extension

查看:121
本文介绍了使用来自多个目录和多个扩展名的vim将头文件打开为C/C ++源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我准备在vim中编写一个if/else语句的 long 列表,并意识到1)有一种更好的方法可以完成我想做的事情,以及2)SO在这个问题上的帮助将变得成熟.所以!我有各种各样类似的文件

First off, I was about to write a long list of if/else statements in vim and realized that 1) there was a better way to do what I was trying to do and 2) SO would be ripe with help on the subject. So! I have a variety of files spread about like

foo/src/file01.C
foo/src/file02.cc
foo/src/file03.c
foo/include/file01.hh
foo/include/file02.h
foo/include/file03.h

如果您发现C/H,cc/hh,c/h扩展名可能匹配或不匹配,那么您很热衷,希望您能提供帮助.我看过类似以下vim脚本的内容Vim Wiki上的轻松地在源文件和头文件之间切换",尽管我仅将数小时的时间浪费在a.vim中,但没有成功,但似乎其他人都无法通过该页面上的文档来工作.那么,谁能帮忙实现这项工作呢?

If you notice that the C/H, cc/hh, c/h extension may or may not match then you are keen and I'd like you to please help. I've look at things like the following vim scripts from the Vim wiki for "Easily switch between source and header file" and although I only dumped a few hours into a.vim without success, it doesn't seem that the others would work via the docs on that page. So can anyone help out on how to make this work?

我的一个很好的线索是快速如何轻松在标题和来源主题,但仍然无法使它起作用.

A good lead I had was a quick How to Easily Switch between Header and Source topic, but still couldn't make it work.

我想我真正想要的是如何避免使用多个if语句,并使用实数匹配来做我想要的事情.我想查找另一个目录,如果它是源C/C ++文件,则查找具有任何熟悉的扩展名的同名头文件,或者如果它是头文件,则寻找任何常规扩展名的源文件.感谢您的帮助!

I guess what I really want is how to avoid the multiple if statements and use real matching to do what I want. I want to look into another directory and if look for a header file of the same name with any familiar extension if it was a source C/C++ file, or look for a source file of any regular extension if it was a header file. Thanks for your help!

更新:我特别想在新标签页中打开文件.我住在vim标签上!

UPDATE: I specifically want to open the file in a new tab. I live on vim tabs!

推荐答案

我建议使用FSwitch插件. https://github.com/derekwyatt/vim-fswitch 开箱即用即可满足您的需求.它是对a.vim背后想法的重写.它在多个方面都比a.vim好.

I recommend using the FSwitch plugin. https://github.com/derekwyatt/vim-fswitch This does exactly what you need out of the box. It is better than a.vim in more than one way, being a rewrite of the idea behind a.vim.

您发布的链接也将其作为解决方案. 我刚刚将其安装到我的vim配置中,并且很好地完成了工作.

The link you posted presents it as a solution, too. I have just installed it to my vim configuration and it does its job well.

享受.

这篇关于使用来自多个目录和多个扩展名的vim将头文件打开为C/C ++源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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