Database autocompletion powered by https://github.com/tpope/vim-dadbod
797
stars
153
commits
Vim Script
primary language
Mar 19, 2025
updated
Database auto completion powered by vim-dadbod.
Supports:
omnifunc
Video presentation by TJ:
Dependencies:
For coc.nvim
:CocInstall coc-db
For deoplete, completion-nvim, nvim-compe, ddc and omnifunc, install it with your favorite plugin manager.
Plug 'tpope/vim-dadbod'
Plug 'kristijanhusak/vim-dadbod-ui' "Optional
Plug 'kristijanhusak/vim-dadbod-completion'
" For built in omnifunc
autocmd FileType sql setlocal omnifunc=vim_dadbod_completion#omni
" hrsh7th/nvim-compe
let g:compe.source.vim_dadbod_completion = v:true
" hrsh7th/nvim-cmp
autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })
" Shougo/ddc.vim
call ddc#custom#patch_filetype(['sql', 'mysql', 'plsql'], 'sources', 'dadbod-completion')
call ddc#custom#patch_filetype(['sql', 'mysql', 'plsql'], 'sourceOptions', {
\ 'dadbod-completion': {
\ 'mark': 'DB',
\ 'isVolatile': v:true,
\ },
\ })
Configuration using lazy.nvim with vim-dadbod-ui
return {
{
'kristijanhusak/vim-dadbod-ui',
dependencies = {
{ 'tpope/vim-dadbod', lazy = true },
{ 'kristijanhusak/vim-dadbod-completion', ft = { 'sql', 'mysql', 'plsql' }, lazy = true },
},
cmd = {
'DBUI',
'DBUIToggle',
'DBUIAddConnection',
'DBUIFindBuffer',
},
init = function()
-- Your DBUI configuration
vim.g.db_ui_use_nerd_fonts = 1
end,
},
{ -- optional saghen/blink.cmp completion source
'saghen/blink.cmp',
opts = {
sources = {
default = { "lsp", "path", "snippets", "buffer" },
per_filetype = {
sql = { 'snippets', 'dadbod', 'buffer' },
},
-- add vim-dadbod-completion to your completion providers
providers = {
dadbod = { name = "Dadbod", module = "vim_dadbod_completion.blink" },
},
},
},
}
}
select * from mytable tbl where tbl.id = 1). Currently works for PostgreSQL, MySQL, Oracle, SQLite (requires version 3.37.0 (2021-11-27)) and SQLserver/MSSQL.vim-dadbod-ui is not used, there are multiple ways to define the connection string, prioritized by this order:
let w:db = 'postgresql://user:pass@localhost:5432/db_name'let t:db = 'postgresql://user:pass@localhost:5432/db_name'let b:db = 'postgresql://user:pass@localhost:5432/db_name'. You can also add let b:db_table = 'table_name' to limit column completions only to this tablelet g:db = 'postgresql://user:pass@localhost:5432/db_name'$DATABASE_URL env variable, defined outside of Vim, or inside with let $DATABASE_URL = 'postgresql://user:pass@localhost:5432/db_name'Default mark for completion items is [DB]. To change it, add this to vimrc:
let g:vim_dadbod_completion_mark = 'MYMARK'
This plugin caches the database tables and columns to leverage maximum performance. If you want to clear the cache at any point just run:
:DBCompletionClearCache
Vim Script
83.5%
Lua
9.0%
JavaScript
4.1%
TypeScript
1.8%
Python
1.6%
Database autocompletion powered by https://github.com/tpope/vim-dadbod
797
stars
153
commits
Vim Script
primary language
Mar 19, 2025
updated
Database auto completion powered by vim-dadbod.
Supports:
omnifunc
Video presentation by TJ:
Dependencies:
For coc.nvim
:CocInstall coc-db
For deoplete, completion-nvim, nvim-compe, ddc and omnifunc, install it with your favorite plugin manager.
Plug 'tpope/vim-dadbod'
Plug 'kristijanhusak/vim-dadbod-ui' "Optional
Plug 'kristijanhusak/vim-dadbod-completion'
" For built in omnifunc
autocmd FileType sql setlocal omnifunc=vim_dadbod_completion#omni
" hrsh7th/nvim-compe
let g:compe.source.vim_dadbod_completion = v:true
" hrsh7th/nvim-cmp
autocmd FileType sql,mysql,plsql lua require('cmp').setup.buffer({ sources = {{ name = 'vim-dadbod-completion' }} })
" Shougo/ddc.vim
call ddc#custom#patch_filetype(['sql', 'mysql', 'plsql'], 'sources', 'dadbod-completion')
call ddc#custom#patch_filetype(['sql', 'mysql', 'plsql'], 'sourceOptions', {
\ 'dadbod-completion': {
\ 'mark': 'DB',
\ 'isVolatile': v:true,
\ },
\ })
Configuration using lazy.nvim with vim-dadbod-ui
return {
{
'kristijanhusak/vim-dadbod-ui',
dependencies = {
{ 'tpope/vim-dadbod', lazy = true },
{ 'kristijanhusak/vim-dadbod-completion', ft = { 'sql', 'mysql', 'plsql' }, lazy = true },
},
cmd = {
'DBUI',
'DBUIToggle',
'DBUIAddConnection',
'DBUIFindBuffer',
},
init = function()
-- Your DBUI configuration
vim.g.db_ui_use_nerd_fonts = 1
end,
},
{ -- optional saghen/blink.cmp completion source
'saghen/blink.cmp',
opts = {
sources = {
default = { "lsp", "path", "snippets", "buffer" },
per_filetype = {
sql = { 'snippets', 'dadbod', 'buffer' },
},
-- add vim-dadbod-completion to your completion providers
providers = {
dadbod = { name = "Dadbod", module = "vim_dadbod_completion.blink" },
},
},
},
}
}
select * from mytable tbl where tbl.id = 1). Currently works for PostgreSQL, MySQL, Oracle, SQLite (requires version 3.37.0 (2021-11-27)) and SQLserver/MSSQL.vim-dadbod-ui is not used, there are multiple ways to define the connection string, prioritized by this order:
let w:db = 'postgresql://user:pass@localhost:5432/db_name'let t:db = 'postgresql://user:pass@localhost:5432/db_name'let b:db = 'postgresql://user:pass@localhost:5432/db_name'. You can also add let b:db_table = 'table_name' to limit column completions only to this tablelet g:db = 'postgresql://user:pass@localhost:5432/db_name'$DATABASE_URL env variable, defined outside of Vim, or inside with let $DATABASE_URL = 'postgresql://user:pass@localhost:5432/db_name'Default mark for completion items is [DB]. To change it, add this to vimrc:
let g:vim_dadbod_completion_mark = 'MYMARK'
This plugin caches the database tables and columns to leverage maximum performance. If you want to clear the cache at any point just run:
:DBCompletionClearCache
Vim Script
83.5%
Lua
9.0%
JavaScript
4.1%
TypeScript
1.8%
Python
1.6%