Up to now I have been using Sublime Text as my preferred editor, before that it was TextMate, before that it was BBEdit and sometimes in between it has been Atom, Komodo, Vim and vi.
I have come really, really excited with Visual Studio Code (code) and most of my programing and text editing is being done using that editor.
Normally I start code from the command line, but today I decided to go all the way a specified
it as the editor to be executed when edits are initiated from other command line tools using the $EDITOR
or $VISUAL
variable.
export EDITOR="code --wait --new-window"
This mean that for example can edit, complex command line constructs in code using the CTRL-x
,
CTRL-e
combination.
code has marvellous Git integration, but if you like me sometime work on the command line instead of the editor with your version control tasks, setting the $GIT_EDITOR
environment variable can be quite useful.
This might not be necessary, if you have set $EDITOR
or $VISUAL
as described above (see also: the Git man page), but if you have special command line setting and would like to differenciate, this could be an option and therefor worth a mention.
export GIT_EDITOR="code --wait --new-window"
And now I can edit commit messages and command lines using code and all the other CLI relying on the $EDITOR integration.
References
Hand-picked from my TIL collection.
Top comments (7)
I made a little experiment this morning, exchanging
$EDITOR
for$VISUAL
and it works as expected.I guess the recommendation should be to use
$VISUAL
for you GUI enabled editor and then define$EDITOR
point to a non-gui likevi
,nano
,vim
or similar for hosts where you access viassh
.Which makes your shell configuration portable, which holds a lot of benefits.
So I ended up with the following:
Thanks for the pointer. I do however wonder where this is documented, would love to know a know authoritative resource. I will update my TIL accordingly.
On mac, start code in bash.
You can also use the official approach, described here: code.visualstudio.com/docs/setup/mac.
As always, and luckily, there is more than one way to do it :-)
Cool, more simple. thanks. :)
I find your recommendation much more correct, the more I think about it - thanks again.
My
.bash_profile
has followed me for many years, glad to learn that I can still improve it.