5

I cannot figure out how to open a file that starts with +, e.g. +models/File.m. This is a naming convention for packages in Matlab.

I've tried escaping \+models/File.m. This doesn't work because the backslash is interpreted by the shell. Double escaping \\+models/File.m allows vim to receive the backslash, but it then opens \+models/File.m literally.

The only way to do this seems to be by creating the file first with touch or whatever, and then opening inside vim with Ctrl-P. I don't want to cd into +models because I am also working on files in sibling directories. Any Ideas?

Thanks

My shell is bash if that makes a difference.

  • 1
    On the command line: vim -- +models/File.m. From Vim: :e \+models/File.m – Sato Katsura Jul 7 '16 at 10:13
  • @SatoKatsura Please add the command line part as an answer. – maxf130 Jul 7 '16 at 10:16
6

From vim --help:

Arguments:
   --                   Only file names after this
...

So this works on the command line:

vim -- +models/File.m

From inside Vim you need to escape the +:

:e \+models/File.m
  • I was thrown off inside vim because tab-completion no longer works with the \. I never thought to just try it. Doh. – maxf130 Jul 7 '16 at 10:23
  • 1
    @maxf130 Tab completion works if you write the directory: :e \+models/<Tab> – Sato Katsura Jul 7 '16 at 10:25
  • Clearly my attention span is to low. I never made it past the first few characters. – maxf130 Jul 7 '16 at 10:27
  • 3
    @maxf130 Note that using -- to stop argument parsing is pretty standard for commandline tools. e.g. rm -- -r, less -- -f, etc. – Martin Tournoij Jul 7 '16 at 12:16
3

More generally, you can start by specifying a directory name, so that the + (plus sign) appears in the middle of the file specification instead of at the beginning.

Because all *nix operating systems, and others like MS-DOS / Windows that adopted Unix conventions, (just about any place you can run vim...,) refer to the current directory as . ("dot", "period", and so on,) then you can specify any file name beginning with an unusual symbol by preceding it with the string ./ (or in Windows with back- instead of forward-slash .<) and thus:

./+models/File.m

just about anywhere that you can use a "regular" file name.

2

You can open vim without any arguments. And then, in command line, type :e! \+filename

  • 1
    +1 This works, though it would be better if this were possible from the command line. – maxf130 Jul 7 '16 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.