https://github.com/mfelici/v4v
Vim For Vertica - When the best editor meets the best database...
https://github.com/mfelici/v4v
sql vertica vim
Last synced: 8 months ago
JSON representation
Vim For Vertica - When the best editor meets the best database...
- Host: GitHub
- URL: https://github.com/mfelici/v4v
- Owner: mfelici
- Created: 2020-03-04T13:42:40.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-27T15:01:41.000Z (about 3 years ago)
- Last Synced: 2023-09-10T20:26:37.797Z (over 2 years ago)
- Topics: sql, vertica, vim
- Language: Vim Script
- Size: 331 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vim for Vertica (V4V)
When the [best editor](www.vim.org) meets the [best database](www.vertica.com)...
## Update May 2020
A lot of new functionalities have been added like:
- the possibility to get DDL and other info on tables
- the possibility to generate SQL starting from a table names thank to the scripts contributed by my colleague and friend Marco Gessner
- the possibility to get information about currently running SQL statements and other host information
- lot of small issues have been fixed and scripts are now easier to read and maintain
## What is V4V
V4V stands for *Vim for Vertica*. It's a set of VIM plugins and syntax files in order to:
- Highlight SQL Vertica "the right way"
- Format SQL commands
- Run vsql from within VIM getting the results back in VIM
- Copy SQL snippets in HTML format into your clipboard
## What V4V consists of
V4V consists of:
- VIM Syntax file: ```sqlvertica.vim```
- VIM File Type plugin: ```sql.vim```
- Several add-on scripts: ```vfv_```
- settings to be added to your VIM initialization file: ```.vimrc```
## Which tools are used by V4V
V4V uses:
- ```vsql``` to run you SQL commands. By default vsql is executed with the following options:
o ```-X``` to exclude local vsqlrc
o ```-i``` to add execution elapsed
o ```vsql``` uses standard ```VSQL_USER``, ```VSQL_PASSWORD```, ```VSQL_HOST```, etc settings.
- A SQL formatter called ```sqlformat``` (see in the following section how to install it)
- ```xclip```(Linux)/```pbcopy```(Mac) tool to copy formatted SQL to your clipboard
- ```sed``` to manipulate the SQL Interpreter (```vsql``` by default) output
- GraphViz's ```dot``` to transform the Vertica EXPLAIN plan into a graph
- ```xdg-open``` (Linux) or ```open``` to run the PDF visualizer installed on your system
You are free to use a different SQL clients and/or SQL formatters by changing the ``sql.vim`` file type plugin.
## How to Install V4V
### V4V Prerequisites
V4V uses an external SQL formatter. You can use any SQL formatter you like as long as you change the default ```sqlformat``` call in the V4V's sql.vim plugin file. The default formatter (```sqlformat```) can be installed either as a package:
```
sudo apt install sqlformat
```
or as a byproduct of ```python-sqlparse``` as follows:
- Download```python-sqlparse``` from https://github.com/andialbrecht/sqlparse
- Install the python setup tools: ```sudo apt install python-setuptools```
- Install sqlparse: ```cd sqlparse-master && sudo python setup.py install```
- Unzip sqlparse archihve: ```unzip sqlparse-master.zip```
This will create the /usr/local/bin/sqlformat executable which is then used by V4V.
```sqlformat``` has several options you might want to explore. This is the standard way v4v uses it:
```
sqlformat -k upper
-s
-r
--indent_width 4
--indent_columns.
```
You can change default sqlformat behaviour to better suit your needs by modifying V4V's ```sql.vim``` plugin.
V4V also uses ```xclip```(Linux) or ```pbcopy``` (Mac) to copy formatted and syntax highlighted SQL into your clipboard. To installl ```xclip``` under Ubuntu/Debian: ```sudo apt install xclip```.
Mac version doesn't need any installation because ```pbcopy``` is available by default.
And, finally, to produce the graphical EXPLAIN plan, V4V uses GraphViz.More specifically the program ```dot```. The installation of this product depends on your operating system... it could be ```sudo apt install graphviz``` under Linux Ubuntu, ```sudo yum install graphviz``` under Linux CentOS or ```brew install graphviz``` on your Mac.
## V4V Installation in 5 easy steps
- Step 1: Create a backup copy of your ```.vimrc``` before modifying it.
- Step 2: *merge* ```sample.vimrc``` with your pre-existing copy. The important settings are:
```vim
let g:sql_type_default = 'sqlvertica'
nnoremap za " Toggle to expand/close folds
menu 20.351 Edit.Copy\ to\ HTML :'<,'>Copy2HTML
vnoremenu 1.31 PopUp.Copy\ to\ HTML :'<,'>Copy2HTML
```
And the ```CopyToHTML``` function to copy formatted SQL:
```vim
function! CopyToHTML(line1, line2)
"Copy_to_HTML
function! CopyToHTML(line1, line2)
let g:html_number_lines=0
let g:html_ignore_folding=1
let g:html_dynamic_folds=0
let g:html_use_css=0
let g:html_font="Courier"
exec a:line1.','.a:line2.'TOhtml'
%g//
%s#\(.\|\n\)*