TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

PostgreSQL Sessions in Vim

51 pointsby patriciusover 2 years ago
Really just a few lines of code to have a REPL-like experience with Vim and Postgres.

6 comments

mfontaniover 2 years ago
Using neovim + <a href="https:&#x2F;&#x2F;github.com&#x2F;kassio&#x2F;neoterm" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kassio&#x2F;neoterm</a> I have a similar, possibly simpler, workflow that doesn&#x27;t require any other program (especially listening willy nilly with no authentication&#x2F;authorization whatsoever) other than your normal SQL client running:<p>- I open a :Term window, in which I run the sql client (i.e. &quot;:Texec sqlite\ foo.sqlite&quot; or &quot;:Texec mysql\ foo&quot;, etc)<p>- From there, I can run whatever SQL command normally.<p>If I&#x27;m then in another buffer, and assuming there&#x27;s only one :Term open, I can:<p>- visually select something, and :TREPLSendSelection to have it sent to the terminal along with a newline, thus executed (i.e. type &quot;.schema&quot; on one line, V then :TREPLSendSelection, ENTER, done - it gets executed in the terminal and the output shown) or &quot;vap&quot; to select a full paragraph and :TREPLSendSelection to send it all, for multi-line queries<p>- alternatively, :TREPLSendLine to send the current line<p>- alternatively, :TREPLSendFile to send the whole file (useful when the whole file both undoes and does things, to easily recreate a database structure)<p>I&#x27;ve found those simple things (&quot;just have a terminal&quot;, &quot;send stuff to it&quot;) to be very powerful, without having additional tools which, moreover, listen willy nilly on the network.
gwn7over 2 years ago
These kinds of plugins are not worth installing &amp; configuring &amp; learning in my humble opinion. Just type \e in the psql shell and voila, edit your sql in vim.<p>Just a little bit of UNIX knowledge saves you a load of unnecessary plugin installs.<p>To be clear; this is not some kind of premature optimization argument. I think plugin installs are ok as well as their memory &amp; persistent storage requirements. What I worry about is the storage capacity of my brain.<p>I don&#x27;t want to know about one more plugin unless it introduces a significant benefit on top of the already existing capabilities of the program in question.
thomover 2 years ago
Religious affiliations aside, I&#x27;d be somewhat surprised if Vim doesn&#x27;t have some generic mechanism to talk to external interactive processes like Emacs&#x27; comint. I use sql-mode on top of that for most of my database interactions and it&#x27;s great being able to use all my normal editor commands and muscle memory there (same as my terminal and various REPLs).
RupertEisenhartover 2 years ago
I used dadbod[0] and the following in my vimrc[1] to do a similar thing, only I haven&#x27;t make the shortcuts for sending a block yet.<p>Looks nice though, maybe I&#x27;ll try it out sometime!<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;tpope&#x2F;vim-dadbod" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tpope&#x2F;vim-dadbod</a><p>[1] au FileType sql nmap &lt;leader&gt;d :%:DB g:db&lt;CR&gt;
pastageover 2 years ago
Multiline is what makes REPLs or CLI break, interesting and simple take on it. Fish tries to solve this by having a good CLI editor for multilines. This is preferable to a notebook for me especially if done with the &quot;paste to tmux pane&quot; described in comments. I will use this in FWed production systems next week!
nicolaslemover 2 years ago
See also Dadbod UI on (neo)vim to interact with databases: <a href="https:&#x2F;&#x2F;github.com&#x2F;kristijanhusak&#x2F;vim-dadbod-ui" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;kristijanhusak&#x2F;vim-dadbod-ui</a>
评论 #33468085 未加载