Vim plugin to execute postgresql or mysql commands from VIM buffer
If you use git submodules, run this command from your .vim folder:
git submodule add https://github.com/ivalkeen/vim-simpledb bundle/simpledb
Otherwise, , run this command from your .vim folder:
git clone https://github.com/ivalkeen/vim-simpledb bundle/simpledb
Add this line to your vimrc
Bundle 'ivalkeen/vim-simpledb'
Default key mapping for execution: <enter>
.
-
Create new file with .sql extension (without extensions, mapping would not work)
-
Create first line with commented parameters:
for psql:
-- -h localhost -U postgres -d my_database
or for mysql:
-- db:mysql -D my_database -u root
Note: if you don't want to enter password each time, you should create .pgpass (.my.cnf for mysql) file
There is also usefull key
-q
to avoid messages like 'Timing is on' etc. -
Add sql statements to your file
-
Hit
<enter>
to execute all not commented queries -
Hit
<leader><enter>
to execute all queries in the current paragraph -
Select multiple lines in visual mode and hit
<enter>
to execute just those queries
If you do not want timings to be displayed, add this to your .vimrc
:
let g:simpledb_show_timing = 0
If you want to customize the key mappings,
set the variable simpledb_use_default_keybindings
to 0 and add your own mappings in ~/.vimrc
.
For example, to execute a sql statement by pressing "ctrl-q" instead of "enter",
add the following:
let g:simpledb_use_default_keybindings=0
vnoremap <buffer> <c-q> :SimpleDBExecuteSql<cr>
nnoremap <buffer> <c-q> m':SimpleDBExecuteSql <cr>g`'
nnoremap <buffer> <leader><c-q> m':'{,'}SimpleDBExecuteSql<cr>g`'
If you have any questions, mail me
- Rewrite code to match vim script conventions
- Intellisense
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
If you like this project, please follow the repository on GitHub. Also, you might consider visiting my blog and following me on Twitter and Github.