Using a.vim for C++

2019-04-27 02:16发布

is there a way to use the a.vim plugin to switch between .h, .cxx and .txx files? Alternatively, can you provide another solution? The idea is to automagically switch from .h -> .txx -> .cxx at the press of a key.

A Big Thanks to both of you!

3条回答
对你真心纯属浪费
2楼-- · 2019-04-27 02:27

Look for the lines in a.vim that contain AddAlternateExtensionMapping. The first argument is the extension of the current file, the second is a list of extensions of the file you'd like to switch to with :A. They are listed in order of preference. In your case, you'd have to set it up so that it would go in a cycle.

call <SID>AddAlternateExtensionMapping('h', 'txx,cxx')
call <SID>AddAlternateExtensionMapping('txx', 'cxx,h')
call <SID>AddAlternateExtensionMapping('cxx', 'h,txx')

So now you go from .h to .txx if it exists or .cxx if it doesn't.

查看更多
迷人小祖宗
3楼-- · 2019-04-27 02:43

IIRC, with the latest versions of alternate, there is an option that tells the preferred extensions to use. Did you have a look in the doc/first comment lines of the plugin?

查看更多
爷的心禁止访问
4楼-- · 2019-04-27 02:49

A worthy alternative to a.vim is altr.

altr – Switch to the missing file without interaction

By default this plugin lets you switch between "alternate" Vim script files, C, C++, and Objective-C files, and ASP.NET files, but you can easily add your own alternates too.

After installation, set up the mappings that you prefer,

  • either the a.vim way, using an Ex command

    command! A call altr#forward()
    
  • or using mappings

    nmap <Leader>a <Plug>(altr-forward)
    nmap <Leader>A <Plug>(altr-back)
    
查看更多
登录 后发表回答