问题
This is driving me slightly insane. I'm trying to edit a query using \e in postgres, but upon savequitting :wq nothing happens.
Running \p, which shows what the editor saved, just comes up with a blank line, or whatever I ran most recently in the cli. It seems likethe editor is not persisting whatsoever.
I'm using vim as my default editor, and I'm on psql version 9.5.4. Operating system is OSX and I'm using iterm2. The only similar problem I could find online was here, and no advice there seemed to help.
All ideas are welcomed!
EDIT: Found the problem. It was something to do with my vim -- things worked when I set my editor to Pico, so I nuked my vimrc and slowly readded things. Oddly, when everything was up again it continued to work. So check if it works with another editor!
回答1:
I don't know why exactly but it looks like the $EDITOR environment variable needs to be set for this to work.
Start psql like this:
EDITOR=vim psql ...
Or longer term, add
export EDITOR=vim
to your .bashrc or equivalent.
回答2:
I have confirmed that this occurs when using the Janus vim distribution, and have created an issue over there to track it. Once resolved over there it'll give us a clue and I can give a specific answer here.
In the interim add the following to your ~/.profile as a workaround:
export PSQL_EDITOR="vim -u NONE"
You will lose Janus functionality (and anything else in your .vimrc.before and .after, but it will let you use vim.
See:
- vim -u switch.
- PSQL_EDITOR env var.
来源:https://stackoverflow.com/questions/41472024/postgres-external-editor-does-not-execute-query-on-savequit