From within psql, I can type \e or \edit to begin editing the current query buffer in Vim (or other configured text editor).
Is there an analogous feature using the sqlite3 CLI?
That would be nice! Your question specifically asks about the current query buffer, which I also find useful in psql. A half-solution in sqlite for new queries could be: .shell vim foo.sql followed by .read foo.sql to execute it.
Or, if you're going through your history with arrow keys, for example, you could prefix the line with .shell echo "old query here" > foo.sql, though you might hit some quoting gotchas. (Then .shell vim foo.sql)
More foolproof might be: .trace foo.sql, which should log all your queries to that file. You could run the query from your history to populate that file, maybe aborting the command if it's too slow. It seems there's some buffering of that logging, so .trace off seems to flush it to the file, or .quit would too.
Edit: One downside of these is that .read doesn't seem to put the query into the history, only the .read itself. So, you'd have to remember which file you put your query in to see it again, instead of reviewing your sqlite command history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With