view doc/dbtables.txt @ 2:c19add1b66a9 default tip

updated mappings
author Luka Sitas <lsitas@avatarasoftware.com>
date Wed, 11 Mar 2026 12:03:31 -0400
parents 8530ebeda72c
children
line wrap: on
line source

*dbtables.txt*   Database interaction in Vim

INTRODUCTION                                        *dbtables*

dbtables is a small plugin to interact with a database from Vim:
- Browse tables in a dedicated window
- Execute SQL from the current buffer (normal and visual mode)
- Open a DB console
- Manage query history and snippets

It is intended as a lightweight helper for SQL work inside Vim.

INSTALLATION                                       *dbtables-install*

Using vim-plug, add the following to your vimrc/init.vim:

    Plug '/home/lsitas/repos/vim_plugins/dbtables'

Then run:

    :PlugInstall

USAGE                                              *dbtables-usage*

The plugin defines the following user commands and mappings.

COMMANDS                                           *dbtables-commands*

                                                    *:DBTables*
:DBTables
    Open the database tables window. Selecting a table can show
	the schema of the table or all the data in the table.

                                                    *:DBConsole*
:DBConsole
    Opens a console for interacting with the database. 

                                                    *:ExecuteSQL*
:ExecuteSQL
    Execute the SQL query from the current buffer. If there are
	query parameters included, the user will be prompted to 
	fill them in. 
	
	Example:
	"""
	SELECT
		id,
		name
	FROM 
		my_table
	WHERE 
		id > :min_id;
	"""
	
	The user will be prompted for a value for `min_id`

                                                    *:QueryHistory*
:QueryHistory
	Opens the list of recently ran queries. Selecting a query will
	re-run the query. All parameters are already filled in.

                                                    *:QuerySnippets*
:QuerySnippets
	Opens the list of saved query snippets. Selecting a snippet will
	open the snippet in a new tab for modification or execution.

MAPPINGS                                           *dbtables-mappings*

All mappings use the <Leader> key in normal or visual mode.

In NORMAL mode:

    <Leader>dt
        Same as |:DBTables|. Open the database tables window.

    <Leader>eq
        Same as |:ExecuteSQL|. Execute SQL from the current buffer.

    <Leader>db
        Same as |:DBConsole|. Open an interactive DB console.

    <Leader>qh
        Same as |:QueryHistory|. Open the query history list.

    <Leader>qs
        Same as |:QuerySnippets|. Open the query snippets list.

In VISUAL mode:

    <Leader>ev
        Call dbtables#ExecuteVisualSQLQuery(). Execute only the
        visually selected SQL text.

CONFIGURATION                                      *dbtables-config*

The plugin exposes several global variables you can set in your
vimrc/init.vim before the plugin is loaded. Each has a default value
if you do not define it.

                                                    *g:snippets_directory*
g:snippets_directory
    Directory where query snippets are stored and loaded from.

    Default:
        $HOME/.config/heidisql/Snippets

    Example:

        let g:snippets_directory = expand('~/.vim/db_snippets')

                                                    *g:db_user*
g:db_user
    Database username used by the plugin when connecting or running
    queries.

    Default:
        ''  (empty string; you must set this to actually connect)

    Example:

        let g:db_user = 'myuser'

                                                    *g:db_password*
g:db_password
    Database password associated with |g:db_user|.

    Default:
        ''  (empty string; set this if your DB requires a password)

    Example:

        let g:db_password = 'mypassword'

                                                    *g:db_name*
g:db_name
    Default database/schema name to connect to.

    Default:
        ''  (empty string; set this to the DB you want to use)

    Example:

        let g:db_name = 'mydatabase'

                                                    *g:db_host*
g:db_host
    Hostname or IP address of the database server.

    Default:
        ''  (empty string; set this to your DB host, e.g. 'localhost')

    Example:

        let g:db_host = 'localhost'

NOTES                                              *dbtables-notes*

- All mappings are defined in the plugin by default. If you prefer
  your own keybindings, you can `:nunmap` or `:xunmap` them and
  create custom mappings to the same functions
  (e.g. dbtables#ExecuteSQLQuery()).

- This help file documents only the public interface (commands,
  mappings, and configuration variables). The internal functions
  under the dbtables# namespace are intended to be called by these
  interfaces, but you may also call them directly if you know what
  you are doing.

*dbtables*      Main help entry for this plugin.