maehue
maehue

Reputation: 504

Setting mongodb editor path in mongorc on windows

I'm trying to set the path to sublime text editor for mongodb in the .mongorc.js on windows 8 so I add this line to .mongorc.js ...

EDITOR = "C:\\Program Files\\Sublime Text 3\sublime_text.exe";

which when I start mongo.exe from the command prompt and then type:

> edit blah

it returns:

'C\Program' is not recognized as an internal or external command

so I try

EDITOR = "C:\\Program\u0020Files\\Sublime\u0020Text\u00203\\sublime_text.exe";

and even

EDITOR = "C:\\Program%20Files\\Sublime%20Text%203\\sublime_text.exe";

and I get

The system cannot find the path specified.

Upvotes: 4

Views: 2572

Answers (2)

Asya Kamsky
Asya Kamsky

Reputation: 42352

You can have spaces in your editor name, you just have to be sure to escape everything properly. I don't have the editor you have installed, so I used wordpad.

> EDITOR="\"C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe\""
"C:\Program Files\Windows NT\Accessories\wordpad.exe"
> edit a

works for me. You need to enclose the whole thing in quotes, and then backslash escape backslashes and double quotes around the entire executable.

You can also make sure the path to your editor is in your default/system path, then you only need to assign the editor executable name to EDITOR.

Upvotes: 7

WiredPrairie
WiredPrairie

Reputation: 59773

Apparently, the path cannot include spaces.

The simplest workaround for this is to use the generated 8.3 names for the folders rather than the path with spaces.

From a command prompt, you'll use the /x switch which displays the normally hidden 8.3 directory and file names:

c:
cd \
dir pro* /x

Should return something like this:

Directory of C:\

11/05/2013  07:19 PM    <DIR>          PROGRA~1     Program Files
11/05/2013  07:19 PM    <DIR>          PROGRA~2     Program Files (x86)

If you're using the 64 bit version of Sublime, you'd choose PROGRA~1.

Change to the Program Files directory:

cd Program Files

Then, find the Sublime folder's 8.3 name:

C:\Program Files>dir Subl* /x

 Directory of C:\Program Files

 09/08/2013  02:17 PM    <DIR>          SUBLIM~1     Sublime Text 2

On my system, it's SUBLIM~1. Then, change the EDITOR value, using the values from your system to something like:

EDITOR="C:\\PROGRA~1\\SUBLIM~1\\sublime_text.exe"

You could also create a junction somewhere (without spaces), but the above trick should work fine (I tested it on my machine and it works correctly). The only issue with using Sublime I've noticed is that the edit command in the MongoDB console waits for the entire editor process to exit, so you can't use tabs for example.

Upvotes: 2

Related Questions