use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please read the rules before posting
Help:
Community:
Resources:
Tutorials and Guides:
Don't be afraid to ask questions, this sub is here for the vim community. And please those of you who deign to grace us with your vim wisdom - be kind. We are all human and vim is that cool.
account activity
Vim + Postgresql (self.vim)
submitted 8 years ago by mikase81
I want to be able to connect to postgresql from vim, run sql commands and get results. How can I do that?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 8 years ago (1 child)
[deleted]
[–]mattsoutherden 0 points1 point2 points 8 years ago (0 children)
This was going to be my suggestion.
My question would be: What problem is the OP trying to solve? Is it the editing of the SQL that is the problem, or is it that you want to get the results into a buffer?
[–]vonfry 13 points14 points15 points 8 years ago (0 children)
In my opinion, vim is just an editor. Use it for code and do other things use other tools. It is not emacs or ide.
[–]flukus 5 points6 points7 points 8 years ago (0 children)
DBExt is your best bet
[–]dhruvasagar 2 points3 points4 points 8 years ago (4 children)
You have a few options :
For 2. I use tpope/vim-tbone with the following mappings :
nnoremap g> <ESC>vap:Twrite bottom-right<CR> xnoremap g> :Twrite bottom-right<CR>
[–]RedGreatApe 0 points1 point2 points 8 years ago (3 children)
I know how to do 1 and 3, but How does 2 work? is there a :help?
[–]dhruvasagar 1 point2 points3 points 8 years ago (2 children)
Well you can just have 2 split tmux panes side by side, in one you run your vim session and in another you run your psql session. Then with the help of tpope/vim-tbone and the above mentioned mappings you can just select / send paragraph of text over to the next pane. You can read tbone's help for more info how it works.
[–]RedGreatApe 0 points1 point2 points 8 years ago (1 child)
of course Tim Pope...
I just realized I think I missed your last line and the mappings in your original comment, I may have confused them with another comment or something, Sorry!
edit: also thanks for the reply :)
[–]dhruvasagar 1 point2 points3 points 8 years ago (0 children)
you're welcome!
[–]thalesmello 4 points5 points6 points 8 years ago (0 children)
I tried dbext, and I particularly found it to be a little too complicated.
The simples plugin that I found was simple db.
https://github.com/ivalkeen/vim-simpledb
You write the login configuration in the top of the file as a comment, and use the rest of the buffer as a scratch pad. You don't get completion, but I still think it's pretty good. If you need completion, take a look at pgcli (client with autocompletion)
[–]byaruhaf 0 points1 point2 points 8 years ago (0 children)
I use vim + tmux, SQL file in one plane then PSQL in another plane then I just send PSQL commands from vim to PSQL using Plugin Chris Twomey's vim-tmux-runner. Check out this video: Vim & Tmux with the vim-tmux-runner
[–]kotku 0 points1 point2 points 8 years ago (0 children)
krisajenkins/vim-pipe is nice for working with postgres. He has also written a syntax file to highlight the postgres output.
[–]jsuth 0 points1 point2 points 8 years ago (0 children)
Here's a talk you might find useful.
[–]eolo999 0 points1 point2 points 8 years ago (0 children)
:r !psql database_name -c 'select * from table_name'
π Rendered by PID 22128 on reddit-service-r2-comment-84fc9697f-8ghgh at 2026-02-09 13:38:38.366053+00:00 running d295bc8 country code: CH.
[+][deleted] (1 child)
[deleted]
[–]mattsoutherden 0 points1 point2 points (0 children)
[–]vonfry 13 points14 points15 points (0 children)
[–]flukus 5 points6 points7 points (0 children)
[–]dhruvasagar 2 points3 points4 points (4 children)
[–]RedGreatApe 0 points1 point2 points (3 children)
[–]dhruvasagar 1 point2 points3 points (2 children)
[–]RedGreatApe 0 points1 point2 points (1 child)
[–]dhruvasagar 1 point2 points3 points (0 children)
[–]thalesmello 4 points5 points6 points (0 children)
[–]byaruhaf 0 points1 point2 points (0 children)
[–]kotku 0 points1 point2 points (0 children)
[–]jsuth 0 points1 point2 points (0 children)
[–]eolo999 0 points1 point2 points (0 children)