I recently had to write a lot of SQL code and thought it would be very neat to have some vim shortcuts to execute the current line or the current command. I want to share this with everyone as the second command needed some try-and-error on my part.
Adding the following to ~/.vimrc
map <F2> :.w !psql<CR>
map <F3> :.,/;/w !psql<CR>
map <F4> :w !psql<CR>
will enable you to execute the current line in psql with F2
. F3
executes the current line and the next lines until a;
.
F4
executes the whole file.
This can easily adapted to your needs. If you have any questions or improvemnts feel free to use the chat below.