Vim Tips Wiki
Register
(Created page with " Nice plugin, but it doesn't seem to work correctly when there are three files: i.e. foo.h foo.inl and foo.cpp")
 
(Format.)
Tag: sourceedit
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
  +
{{ScriptComments|a: switch between alternate files quickly (.c --> .h etc)}}
   
  +
==Three files==
 
Nice plugin, but it doesn't seem to work correctly when there are three files:
 
Nice plugin, but it doesn't seem to work correctly when there are three files:
 
 
i.e. foo.h foo.inl and foo.cpp
 
i.e. foo.h foo.inl and foo.cpp
  +
  +
:Solution: This is because already open files are scored higher than other files. Thus when there you have foo.h and foo.inl loaded, foo.cpp won't be considered. To fix, change the body of BufferOrFileExists to "return filereadable(a:fileName)". I also changed FindOrCreateBuffer to ignore a:findSimilar - I don't know if thats strictly necessary.
  +
  +
==Separate folders==
  +
Thanks for your contribution.
  +
But I have a challenge in switching between header files and source files when they are in directories such as src/ and include/.
  +
  +
If I'm editing foo.c in src/, it will look for foo.h in src. But I have foo.h in include/. Can you please help.
  +
  +
:Solution: the docs has a section on g:alternateSearchPath
  +
  +
==Bugs==
  +
This is a great plugin. The only drawback is that it does not handle folders with commas in it, unfortunately. For example, if I'm editing src,/foo.c, and want to switch to src,/foo.h, then :A does not work.
  +
  +
<leader>is is mapped to <Esc>:IHS<CR>:A<CR>, even in insert mode. My <leader> is space, so every time I type " is" it invokes that, which is really annoying. Thanks for your work.
  +
  +
== Directory structures ==
  +
  +
Very nice plugin. But I have some trouble with my directory structure and the regexp mode in alternateSearchPath. Imagine the following files structure:
  +
<pre>
  +
foo/include/foo/base.h
  +
foo/src/foo/base.cpp
  +
bar/include/bar/base.h
  +
bar/src/bar/base.cpp
  +
</pre>
  +
Then load the following files into Vim:
  +
<pre>
  +
foo/include/foo/base.h
  +
bar/src/bar/base.cpp
  +
</pre>
  +
Using these alterativeSearchPath:
  +
<pre>
  +
let g:alternateSearchPath='reg:/include/src/g/,reg:/src/include/g/'
  +
</pre>
  +
When I use :A while in base.h this will not open up foo/src/foo/base.cpp but bar/src/bar/base.cpp.
  +
  +
Why? --October 3, 2015
  +
  +
==Comments==

Latest revision as of 02:35, 8 October 2015

Use this page to discuss script 31 a: switch between alternate files quickly (.c --> .h etc)

  • Add constructive comments, bug reports, or discuss improvements (see the guideline).
  • Do not document the script here (the author should do that on vim.org).
  • This page may be out of date: check the script's vim.org page above, and its release notes.

Three files[]

Nice plugin, but it doesn't seem to work correctly when there are three files: i.e. foo.h foo.inl and foo.cpp

Solution: This is because already open files are scored higher than other files. Thus when there you have foo.h and foo.inl loaded, foo.cpp won't be considered. To fix, change the body of BufferOrFileExists to "return filereadable(a:fileName)". I also changed FindOrCreateBuffer to ignore a:findSimilar - I don't know if thats strictly necessary.

Separate folders[]

Thanks for your contribution. But I have a challenge in switching between header files and source files when they are in directories such as src/ and include/.

If I'm editing foo.c in src/, it will look for foo.h in src. But I have foo.h in include/. Can you please help.

Solution: the docs has a section on g:alternateSearchPath

Bugs[]

This is a great plugin. The only drawback is that it does not handle folders with commas in it, unfortunately. For example, if I'm editing src,/foo.c, and want to switch to src,/foo.h, then :A does not work.

<leader>is is mapped to <Esc>:IHS<CR>:A<CR>, even in insert mode. My <leader> is space, so every time I type " is" it invokes that, which is really annoying. Thanks for your work.

Directory structures[]

Very nice plugin. But I have some trouble with my directory structure and the regexp mode in alternateSearchPath. Imagine the following files structure:

foo/include/foo/base.h
foo/src/foo/base.cpp
bar/include/bar/base.h
bar/src/bar/base.cpp

Then load the following files into Vim:

foo/include/foo/base.h
bar/src/bar/base.cpp

Using these alterativeSearchPath:

let g:alternateSearchPath='reg:/include/src/g/,reg:/src/include/g/'

When I use :A while in base.h this will not open up foo/src/foo/base.cpp but bar/src/bar/base.cpp.

Why? --October 3, 2015

Comments[]