Neovim Database Completion
This is an updated article on how to configure database completion in Neovim. In the previous articles, I talked about configuring Vim and Neovim to manage databases and setting up database completion using nvim-compe
. Since nvim-compe
is deprecated, let’s try out nvim-cmp
.
Setup
Plugins
- Using
packer.nvim
, installvim-dadbod
and its related plugins for user interface and completion.
use {
"tpope/vim-dadbod",
requires = {
"kristijanhusak/vim-dadbod-ui",
"kristijanhusak/vim-dadbod-completion"
},
config = function()
require("config.dadbod").setup()
end,
}
- Create a file called
dadbod.lua
underlua/config
folder with the following content. In this file, I specify the location to save the connection details.
local M = {}function M.setup()
vim.g.db_ui_save_location = "~/.config/nvim/db_ui"
endreturn M
Key Mappings
I configure the following key mappings using which-key.nvim
.
-- Database
x = {
name = "Database",
u = { "<Cmd>DBUIToggle<Cr>", "Toggle UI" },
f = { "<Cmd>DBUIFindBuffer<Cr>", "Find buffer" },
r = { "<Cmd>DBUIRenameBuffer<Cr>", "Rename buffer" },
q = { "<Cmd>DBUILastQueryInfo<Cr>", "Last query info" },
},
Screenshot
As you can see from the screenshot, I am able to connect to a PostgreSQL database now and run queries against it.
Configure Database Completion
Let’s continue to set up database completion using nvim-cmp
. If you are new to nvim-cmp
, check out this article.