{"id":29892470,"url":"https://github.com/mfelici/v4v","last_synced_at":"2025-08-01T02:02:34.448Z","repository":{"id":193924402,"uuid":"244910702","full_name":"mfelici/v4v","owner":"mfelici","description":"Vim For Vertica - When the best editor meets the best database...","archived":false,"fork":false,"pushed_at":"2023-03-27T15:01:41.000Z","size":339,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-09-10T20:26:37.797Z","etag":null,"topics":["sql","vertica","vim"],"latest_commit_sha":null,"homepage":null,"language":"Vim Script","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfelici.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-03-04T13:42:40.000Z","updated_at":"2023-09-10T20:26:45.860Z","dependencies_parsed_at":"2023-09-10T20:36:46.492Z","dependency_job_id":null,"html_url":"https://github.com/mfelici/v4v","commit_stats":null,"previous_names":["mfelici/v4v"],"tags_count":1,"template":null,"template_full_name":null,"purl":"pkg:github/mfelici/v4v","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Fv4v","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Fv4v/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Fv4v/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Fv4v/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfelici","download_url":"https://codeload.github.com/mfelici/v4v/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfelici%2Fv4v/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268157504,"owners_count":24204755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sql","vertica","vim"],"created_at":"2025-08-01T02:01:10.934Z","updated_at":"2025-08-01T02:02:34.287Z","avatar_url":"https://github.com/mfelici.png","language":"Vim Script","readme":"﻿# Vim for Vertica (V4V)\nWhen the [best editor](www.vim.org) meets the [best database](www.vertica.com)...\n\n## Update May 2020\n\nA lot of new functionalities have been added like:\n\n- the possibility to get DDL and other info on tables\n- the possibility to generate SQL starting from a table names thank to the scripts contributed by my colleague and friend Marco Gessner\n- the possibility to get information about currently running SQL statements and other host information\n- lot of small issues have been fixed and scripts are now easier to read and maintain \n\n## What is V4V \nV4V stands for *Vim for Vertica*. It's a set of VIM plugins and syntax files in order to: \n- Highlight SQL Vertica \"the right way\" \n- Format SQL commands \n- Run vsql from within VIM getting the results back in VIM \n- Copy SQL snippets in HTML format into your clipboard \n\n## What V4V consists of \nV4V consists of: \n- VIM Syntax file: ```sqlvertica.vim```\n- VIM File Type plugin: ```sql.vim```\n- Several add-on scripts: ```vfv_\u003csomething\u003e```\n- settings to be added to your VIM initialization file: ```.vimrc``` \n\n## Which tools are used by V4V \nV4V uses: \n- ```vsql``` to run you SQL commands. By default vsql is executed with the following options: \n  o ```-X``` to exclude local vsqlrc \n  o ```-i``` to add execution elapsed \n  o ```vsql``` uses standard ```VSQL_USER``, ```VSQL_PASSWORD```, ```VSQL_HOST```, etc settings. \n- A SQL formatter called ```sqlformat``` (see in the following section how to install it) \n-  ```xclip```(Linux)/```pbcopy```(Mac) tool to copy formatted SQL to your clipboard \n- ```sed``` to manipulate the SQL Interpreter (```vsql``` by default) output\n- GraphViz's ```dot``` to transform the Vertica EXPLAIN plan into a graph\n- ```xdg-open``` (Linux) or ```open``` to run the PDF visualizer installed on your system\n\nYou are free to use a different SQL clients and/or SQL formatters by changing the ``sql.vim`` file type plugin. \n\n## How to Install V4V \n### V4V Prerequisites\nV4V 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:\n\n```\nsudo apt install sqlformat\n```\n\nor as a byproduct of ```python-sqlparse``` as follows:\n\n- Download```python-sqlparse``` from https://github.com/andialbrecht/sqlparse \n- Install the python setup tools: ```sudo apt install python-setuptools```  \n- Install sqlparse: ```cd sqlparse-master \u0026\u0026 sudo python setup.py install``` \n- Unzip sqlparse archihve: ```unzip sqlparse-master.zip``` \n\nThis will create the /usr/local/bin/sqlformat executable which is then used by V4V.\n\n```sqlformat``` has several options you might want to explore. This is the standard way v4v uses it:\n\n```\n    sqlformat -k upper \n              -s \n              -r \n             --indent_width 4 \n             --indent_columns.\n```\nYou can change default sqlformat behaviour to better suit your needs by modifying V4V's ```sql.vim``` plugin. \n\nV4V 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```.\nMac version doesn't need any installation because ```pbcopy``` is available by default.\n\nAnd, 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.\n\n## V4V Installation in 5 easy steps\n\n - Step 1: Create a backup copy of your ```.vimrc``` before modifying it. \n - Step 2:   *merge*  ```sample.vimrc``` with your pre-existing copy. The important settings are: \n```vim\nlet g:sql_type_default = 'sqlvertica'\nnnoremap \u003cTab\u003e za \" Toggle to expand/close folds \nmenu 20.351 Edit.Copy\\ to\\ HTML :'\u003c,'\u003eCopy2HTML\u003cCR\u003e \nvnoremenu 1.31 PopUp.Copy\\ to\\ HTML :'\u003c,'\u003eCopy2HTML\u003cCR\u003e \n```\nAnd the ```CopyToHTML``` function to copy formatted SQL:\n```vim\nfunction! CopyToHTML(line1, line2)\n\"Copy_to_HTML\nfunction! CopyToHTML(line1, line2)\n    let g:html_number_lines=0\n    let g:html_ignore_folding=1\n    let g:html_dynamic_folds=0\n    let g:html_use_css=0\n    let g:html_font=\"Courier\"\n    exec a:line1.','.a:line2.'TOhtml'\n    %g/\u003cbody/normal k$dgg\n    %s/\u003cbody\\s*\\(bgcolor=\"[^\"]*\"\\)\\s*text=\\(\"[^\"]*\"\\).*$/\u003ctable \\1 width=\"95%\" cellPadding=0\u003e\u003ctr\u003e\u003ctd\u003e\u003cfont color=\\2\u003e/\n    %s#\u003c/body\u003e\\(.\\|\\n\\)*\u003c/html\u003e#\\='\u003c/font\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e'#i\n    w !pbcopy \" Mac: pbcopy, Linux: xclip -selection clipboard\n    q!  \nendfunction\ncommand! -range=% Copy2HTML :silent call CopyToHTML(\u003cline1\u003e,\u003cline2\u003e)\n```\n\n- Step 3: copy V4V's syntax file ```sqlvertica.vim``` under your local syntax directory (for example ```~/.vim/syntax/```) \n- Step 4: copy V4V's File Type plugin ```sql.vim``` under your local *after-directory*. You can check the location in VIM with ```:echo \u0026rtp```. It could be something like ```~/.vim/after/ftplugin``` (Linux) or ```~.vim/ftplugin``` (Mac). \n- Step 5: create a directory ```~/.vim/vertica``` and copy under this directory the following files:\n  - ```vfv_info.sh``` (executable)\n  - ```vfv_prof.sh``` (executable)\n  - ```vfv_copy.sql``` \n  - ```vfv_insert.sql``` \n  - ```vfv_select.sql``` \n  - ```vfv_where.sql``` \n  - ```vfv_update.sql``` \n  - ```vfv_merge.sql``` \n  - ```vfv_jobs.sql``` \n  - ```vfv_host.sql``` \n  - ```vfv_help.txt``` \n## How to use V4V \nStart vim (or its GUI version gvim) and open your SQL file \n\n- To FORMAT your SQL: \n\t- Select the lines containing the SQL to be formatted \n   - Hit F3 or (gvim): right click and select ```SQL Format``` \n- To RUN your SQL: \n   - Select the lines containing the SQL you want to run \n   - Hit F4 or (gvim): right click and select ```SQL run```    \n- To EXPLAIN your SQL: \n   - Select the lines containing the SQL you want to EXPLAIN \n   - Hit F5 or (gvim): right click and select ```SQL explain text``` \n- To get the graphical EXPLAIN of your SQL: \n   - Select the lines containing the SQL you want to EXPLAIN \n   - Hit F6 or (gvim): right click and select ```SQL explain graph``` \n - To print current VSQL environment:  \n   - Hit F7  \n- To profile your SQL: \n   - Select the lines containing the SQL you want to PROFILE \n   - Hit F8 or (gvim): right click and select ```SQL prof``` \n   - a new tab with the profile information will be created\n- To VIM-source a block (containing for example ```let $VSQL_USER='xxx'```: \n   - put your cursor in the block of text (separated by blank lines) containing the VIM instructions you want to source\n   - Hit F9 or (gvim): right click and select ```VIM source block``` \n- To list currently running SQL statements: \n   - Hit F10 or (gvim): right click and select ```SQL running jobs``` \n- To list host resources: \n   - Hit F12 or (gvim): right click and select ```SQL host resources``` \n- To get table and associated projection definition (in a new tab): \n   - put your cursor on the table name\n   - Hit ```,D``` or (gvim): right click and select ```SQL get DDL``` \n- To get table information like rows distribution and encoding related information(in a new tab): \n   - put your cursor on the table name\n   - Hit ```,I``` or (gvim): right click and select ```SQL get info``` \n- To generate a COPY statement for a specific table: \n   - put your cursor on the table name\n   - Hit ```,c``` or (gvim): right click and select ```SQL gen copy``` to get the COPY statement in a new tab\n   - Hit ```,.c``` to get the COPY statement _inline_ in the same tab\n- To generate a SELECT statement for a specific table: \n   - put your cursor on the table name\n   - Hit ```,s``` or (gvim): right click and select ```SQL gen select``` to get the SELECT statement in a new tab\n   - Hit ```,.s``` to get the SELECT statement _inline_ in the same tab\n- To generate an INSERT statement for a specific table: \n   - put your cursor on the table name\n   - Hit ```,i``` or (gvim): right click and select ```SQL gen insert``` to get the INSERT statement in a new tab\n   - Hit ```,.i``` to get the INSERT statement _inline_ in the same tab\n- To generate a MERGE statement for a specific table: \n   - put your cursor on the table name\n   - Hit ```,m``` or (gvim): right click and select ```SQL gen merge``` to get the MERGE statement in a new tab\n   - Hit ```,.m``` to get the MERGE  statement _inline_ in the same tab\n- To generate an UPDATE statement for a specific table: \n   - put your cursor on the table name\n   - Hit ```,u``` or (gvim): right click and select ```SQL gen update``` to get the UPDATE statement in a new tab\n   - Hit ```,.u``` to get the UPDATE statement _inline_ in the same tab\n- To generate a WHERE clause for a specific table: \n   - put your cursor on the table name\n   - Hit ```,w``` or (gvim): right click and select ```SQL gen where``` to get the WHERE clause in a new tab\n   - Hit ```,.w``` to get the WHERE clause _inline_ in the same tab\n- To get help on the Function Keys and other command lines keys:  \n   - Hit ```,h``` \n- To EXPAND/CLOSE the result set:  \n   - Hit TAB \n- To COPY your SQL snippet to HTML: \n   - Select the lines you want to copy \n   - Run :```'\u003c,'\u003eCopy2HTML\u003cCR\u003e``` or (gvim): right click and select ```Copy to HTML``` \n\nWith a graphical version of Vim, right-clicking on a selected query should present a menu like this:\n![gvim-right click menu](images/gvim.png) \n\n## How to customize V4V\nAs we said Vim for Vertica uses - by default - ```vsql``` to interact with Vertica. Sometimes you might want to change the standard environment variables used by ```vsql``` in V4V to use a different database, or a different host or user.  \n - to check all environment variables used by VSQL: ```:!set | grep VSQL_```\n- to check  individual variables use, for example: ```:echo $VSQL_USER```\n\nTo set or change a VSQL environment variable:\n - ```:let $VSQL_DATABASE=\"\u003cmy db name\u003e\"```\n - ```:let $VSQL_HOST=\"\u003cmy Vertica host\u003e\"```\n - ```:let $VSQL_PASSWORD=\"\u003cmy secret password\u003e\"```\n - ```:let $VSQL_PORT=\"5433\"```\n - ```:let $VSQL_USER=\"\u003cmy user\u003e\"```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfelici%2Fv4v","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfelici%2Fv4v","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfelici%2Fv4v/lists"}