lbrayner / easy_db.vim

A SQL Vim-based client for everyone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Screenshot

This is a Vim distribution. It is meant to be used in Easy Mode.

Requirements

It requires gVim 8.0 or greater (+packages).

Packages

It's bundled with a few plugins as git submodules. To wit:

The main one is dbext.vim, which, in the author's own words, ...contains functions/mappings/commands to enable Vim to access several databases.

The only one that changes the behavior of the editor is delimitMate: it ...provides automatic closing of quotes, parenthesis, brackets, etc., besides some other related features that should make your time in insert mode a little bit easier...

Easy mode

-y    Easy mode.  ...  Starts with 'insertmode' set and behaves like a click-and-type
      editor. This sources the script $VIMRUNTIME/evim.vim.  Mappings are set up to
      work like most click-and-type editors, see evim-keys.  The GUI is started when
      available. {not in Vi}

Setup

$ git clone 'https://github.com/lbrayner/easy_dbext_bundle.vim'
$ cd easy_dbext_bundle.vim
easy_dbext_bundle.vim$ git submodule update --init

How to start it

Use init.vim as vimrc with the -u flag: it will make this repository the effective .vim folder, removing the standard locations from the RUNTIMEPATH. It's meant to be used with gVim Easy, so:

easy_dbext_bundle.vim$ gvim -y -u init.vim

Make a script of it or a Windows shortcut.

Setting up a connection

The best way to configure a connection is on a per file basis, with dbext modelines. If you're not sure what modelines are, consult the help files (:h modelines). If you've generated help tag file(s), you can also get help about dbext modelines (:h dbext-modelines).

As an example, the following dbext modeline defines a PostgreSQL connection:

-- dbext:type=PGSQL:user=baka:host=127.0.0.1:extra=--set=QUIET=off

Place the modeline at the beginning or at the end of the file.

Note that the following parameters are set:

  • type=PGSQL;
  • user=baka;
  • host=127.0.0.1;
  • extra=--set=QUIET=off.

The extra parameter is delivered verbatim to the underlying program (in this case, psql).

psql requires an empty $HOME/.pgpass file with permissions set to 0600. Beacause of quirks and details such as these, it's recommended trying to setup a connection on regular Vim first, so that you can follow the documentation as intended.

psqlrc is the configuration file read by psql. It will typically read both a systemwide psqlrc and the per-user one (~/.psqlrc on unix-ish systems, and %APPDATA%\postgresql\psqlrc.conf on Windows). These are some nice settings for it:

-- ~/.psqlrc

\timing on
\pset null 'Ø'
set search_path=public,crm
\pset border 2

-- vim: ft=sql

Please refer to the dbext.vim documentation for instructions on how to connect to a specific solution (Oracle, MySQL, SQL Server, PostgreSQL etc.).

Mappings (Insert Mode)

  • CTRL-Enter: execute SQL (SQL, DML or DDL) in paragraph.
  • CTRL-Enter (Select-mode): execute SQL (SQL, DML or DDL) in selection.
  • SHIFT-Enter: describe table under cursor.
  • F1: show these (and more) mappings (SQL and Result buffers only).
  • F2: toggle hlsearch (when there is a previous search pattern, highlight all its matches).
  • F5: refresh the file (:e) to reload the dbext modelines (SQL buffers only).
  • F8: toggle wrap (when on, lines longer than the width of the window will wrap and displaying continues on the next line).
  • F9: open Result if in a buffer other than it; toggle its size (tall or short) when in it.
  • F10: close the Result buffer.
  • F12: toggle List mode (useful to see the difference between tabs and spaces and for trailing blanks).
  • CTRL-NumpadMinus: resize the window with -5 as parameter.
  • CTRL-NumpadPlus: resize the window with +5 as parameter.
  • CTRL-F9: equalize all windows.
  • ESC ESC: close all windows except the current one (SQL buffers only).

Result buffer mappings:

  • C: clone the buffer (displays the current results in a separate window at the top).

These facilitate other plugins' functionalities:

  • ALT-/: toggle comment — it also works on selected text (vim-commentary).

Maintainer's mappings

Insert mode:

  • SHIFT-F3: set noinsertmode, effectively disabling Easy Mode so that the maintainer may expect normal Vim behavior.
  • F12: toggle list to, for example, differentiate between tabs and spaces.

Normal mode:

  • CTRL-F3: set insertmode to re-enable Easy Mode.
  • F12: same as above.

Other mappings

Insert mode:

  • CTRL-K: behave like Emacs' C-K, i.e., kill-line (erase everything until the end of the line).

Command-line mode:

  • CTRL-K: same as above.

Trailing spaces

Trailing white space is highlighted in red.

Custom menu items

They are:

  • Save As, in File (replaced);
  • Rename As, in File;
  • Delete trailing whitespace, in Edit;
  • Copy full path, in Buffer;
  • Copy full path (Cygwin), in Buffer;
  • Copy relative path, in Buffer;
  • Copy name, in Buffer;

Helptags

On easy_dbext_bundle.vim, don't forget to :helptags ALL (C-L will take you to Normal mode in Easy Mode). Ignore the errors.

vim-obsession

Vim features a :mksession command to write a file containing the current state of Vim: window positions, open folds, stuff like that.

If you're setting this up for someone else, don't forget to use tpope's vim-obsession.

On easy_dbext_bundle.vim, run the command :Obsession with a filename (e.g. sessions/session.vim), which will be the Vim session file.

:Obsession sessions/session.vim

(The sessions directory is created automatically when you start up easy_dbext_bundle.vim.)

To resume the session:

easy_dbext_bundle.vim$ gvim -y -S sessions/session.vim -u init.vim

Local configuration

Local packages can be installed in pack/local; and local configuration should reside in config.local.vim (both inside the easy_dbext_bundle.vim directory). For example, suppose you want to install the gruvbox color scheme:

easy_dbext_bundle.vim$ git clone 'https://github.com/morhetz/gruvbox' pack/local/start/gruvbox

Then create config.local.vim inside easy_dbext_bundle.vim and add colorscheme gruvbox to it.

GUI local configuration should reside in ginit.local.vim.

About

A SQL Vim-based client for everyone


Languages

Language:Vim Script 100.0%