Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Bash, I can do EDITOR=vim command and command will be run with EDITOR set to vim, but this won't affect the value of EDITOR in the shell itself. Is it possible to do this in cmd.exe?

share|improve this question

2 Answers 2

up vote 24 down vote accepted

You can do it in windows like this no need for installing anything.

cmd /C "set EDITOR=vim && set"

You'll see a list of variables and you'll see EDITOR=vim, now run "set" again and it won't be listed.

You can do multiple &&'s to add additional commands:

cmd /C "set EDITOR=vim && do this && do that && otherstuff"

EDIT: /C exits the new cmd right away after running, if you produce output with the new one it will still be visible in the parent window.

You can opt to use /K in which case the new cmd window stays open at the end of the run.

share|improve this answer
Be careful. Setting the variable this way will result in a trailng space in the variable EDITOR: "vim ". To avoid the trailing space use: cmd /C "set "EDITOR=vim" && do this && do that" –  Gerd K Apr 3 at 12:00
This is not working on "Windows Server 2008", for example. I tried this: set name="username" && echo %username%. And username is empty. –  akozin May 15 at 12:10
@akozin Do you realize that you got the keyvalue backwards? Did you mean set name=foo&&echo %name% or set username=foo&&echo %username%? –  Phrogz Jul 30 at 23:00
@akozin see my answer below –  VonC Aug 5 at 6:03
@VonC, thanks to answer. It works for me! –  akozin Aug 5 at 7:40

Note that cmd /C "set "EDITOR=vim" && echo %EDITOR%" would not work.
Nor would cmd /C "setlocal ENABLEDELAYEDEXPANSION && set "EDITOR=vim" && echo !EDITOR!"

What would is the /V option, to enable delayed environment variable expansion using ! as delimiter.

cmd /V /C "set "EDITOR=vim" && echo !EDITOR!"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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