comparison doc/dbtables.txt @ 1:8530ebeda72c

Adding actual db tables implementation from original script.
author Luka Sitas <lsitas@avatarasoftware.com>
date Wed, 11 Mar 2026 08:53:55 -0400
parents 238b45cc333b
children
comparison
equal deleted inserted replaced
0:238b45cc333b 1:8530ebeda72c
1 *dbtables.txt* Simple example Vim plugin 1 *dbtables.txt* Database interaction in Vim
2 2
3 INTRODUCTION *dbtables* 3 INTRODUCTION *dbtables*
4 4
5 dbtables is a minimal example plugin. 5 dbtables is a small plugin to interact with a database from Vim:
6 - Browse tables in a dedicated window
7 - Execute SQL from the current buffer (normal and visual mode)
8 - Open a DB console
9 - Manage query history and snippets
10
11 It is intended as a lightweight helper for SQL work inside Vim.
12
13 INSTALLATION *dbtables-install*
14
15 Using vim-plug, add the following to your vimrc/init.vim:
16
17 Plug '/home/lsitas/repos/vim_plugins/dbtables'
18
19 Then run:
20
21 :PlugInstall
6 22
7 USAGE *dbtables-usage* 23 USAGE *dbtables-usage*
8 24
9 :DbtablesGreet 25 The plugin defines the following user commands and mappings.
10 Echo a greeting message. You can customize it with
11 g:dbtables_greeting:
12 26
13 > let g:dbtables_greeting = 'Hi there!' 27 COMMANDS *dbtables-commands*
14 28
15 INSTALLATION *dbtables-install* 29 *:DBTables*
30 :DBTables
31 Open the database tables window. Selecting a table can show
32 the schema of the table or all the data in the table.
16 33
17 Using vim-plug add the following: 34 *:DBConsole*
35 :DBConsole
36 Opens a console for interacting with the database.
18 37
19 Plug '/home/lsitas/repos/vim_plugins/dbtables' 38 *:ExecuteSQL*
39 :ExecuteSQL
40 Execute the SQL query from the current buffer. If there are
41 query parameters included, the user will be prompted to
42 fill them in.
43
44 Example:
45 """
46 SELECT
47 id,
48 name
49 FROM
50 my_table
51 WHERE
52 id > :min_id;
53 """
54
55 The user will be prompted for a value for `min_id`
20 56
57 *:QueryHistory*
58 :QueryHistory
59 Opens the list of recently ran queries. Selecting a query will
60 re-run the query. All parameters are already filled in.
61
62 *:QuerySnippets*
63 :QuerySnippets
64 Opens the list of saved query snippets. Selecting a snippet will
65 open the snippet in a new tab for modification or execution.
66
67 MAPPINGS *dbtables-mappings*
68
69 All mappings use the <Leader> key in normal or visual mode.
70
71 In NORMAL mode:
72
73 <Leader>dt
74 Same as |:DBTables|. Open the database tables window.
75
76 <Leader>eq
77 Same as |:ExecuteSQL|. Execute SQL from the current buffer.
78
79 <Leader>db
80 Same as |:DBConsole|. Open an interactive DB console.
81
82 <Leader>qh
83 Same as |:QueryHistory|. Open the query history list.
84
85 <Leader>qs
86 Same as |:QuerySnippets|. Open the query snippets list.
87
88 In VISUAL mode:
89
90 <Leader>ev
91 Call dbtables#ExecuteVisualSQLQuery(). Execute only the
92 visually selected SQL text.
93
94 CONFIGURATION *dbtables-config*
95
96 The plugin exposes several global variables you can set in your
97 vimrc/init.vim before the plugin is loaded. Each has a default value
98 if you do not define it.
99
100 *g:snippets_directory*
101 g:snippets_directory
102 Directory where query snippets are stored and loaded from.
103
104 Default:
105 $HOME/.config/heidisql/Snippets
106
107 Example:
108
109 let g:snippets_directory = expand('~/.vim/db_snippets')
110
111 *g:db_user*
112 g:db_user
113 Database username used by the plugin when connecting or running
114 queries.
115
116 Default:
117 '' (empty string; you must set this to actually connect)
118
119 Example:
120
121 let g:db_user = 'myuser'
122
123 *g:db_password*
124 g:db_password
125 Database password associated with |g:db_user|.
126
127 Default:
128 '' (empty string; set this if your DB requires a password)
129
130 Example:
131
132 let g:db_password = 'mypassword'
133
134 *g:db_name*
135 g:db_name
136 Default database/schema name to connect to.
137
138 Default:
139 '' (empty string; set this to the DB you want to use)
140
141 Example:
142
143 let g:db_name = 'mydatabase'
144
145 *g:db_host*
146 g:db_host
147 Hostname or IP address of the database server.
148
149 Default:
150 '' (empty string; set this to your DB host, e.g. 'localhost')
151
152 Example:
153
154 let g:db_host = 'localhost'
155
156 NOTES *dbtables-notes*
157
158 - All mappings are defined in the plugin by default. If you prefer
159 your own keybindings, you can `:nunmap` or `:xunmap` them and
160 create custom mappings to the same functions
161 (e.g. dbtables#ExecuteSQLQuery()).
162
163 - This help file documents only the public interface (commands,
164 mappings, and configuration variables). The internal functions
165 under the dbtables# namespace are intended to be called by these
166 interfaces, but you may also call them directly if you know what
167 you are doing.
21 168
22 *dbtables* Main help entry for this plugin. 169 *dbtables* Main help entry for this plugin.