Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke a text editor to edit query from within sqlite3 CLI?

Tags:

sqlite

psql

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?

like image 313
Stew Avatar asked Aug 15 '26 21:08

Stew


1 Answers

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.

like image 151
dcc310 Avatar answered Aug 19 '26 07:08

dcc310



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!