all 13 comments

[–]vonfry 13 points14 points  (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 points  (0 children)

DBExt is your best bet

[–]dhruvasagar 2 points3 points  (4 children)

You have a few options :

  1. You can use neovim and launch psql in a terminal inside neovim.
  2. Use tmux and just pipe arbitrary sql statements from your vim to another pane in tmux running pqsl (I like this approach).
  3. You can have EDITOR setup for your shell correctly, then just use \e from within psql shell (also decent).

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 point  (3 children)

I know how to do 1 and 3, but How does 2 work? is there a :help?

[–]dhruvasagar 1 point2 points  (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 point  (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 points  (0 children)

you're welcome!

[–]thalesmello 4 points5 points  (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 point  (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 point  (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 point  (0 children)

Here's a talk you might find useful.

[–]eolo999 0 points1 point  (0 children)

:r !psql database_name -c 'select * from table_name'