Archive

Posts Tagged ‘gvim’

MacVim 7.3 is out

August 17th, 2010

But i am need my special version with perl, python and ruby interpreter.

This steps are needed to create this special version

git clone git://github.com/b4winckler/macvim.git vim73
cd vim73/src
./configure --with-features=huge --enable-cscope --enable-pythoninterp \
  --enable-rubyinterp --enable-perlinterp --with-macarchs=x86_64 \
  --with-macsdk=10.6
make
open MacVim/build/Release/

copy MacVim.app to  Applications

Development, Vi-IMproved , ,

GVIM: Has your menu disappeared and you want it back?

August 17th, 2010

Vim: xml.vim (Summary, Mappings)

July 24th, 2010

A filetype plugin to help edit XML and SGML documents.

Mappings

  • <LocalLeader><LocalLeader>
    Normal or Insert – Continue editing after the ending tag. This option requires xml_jump_string to be set to function. When a tag is completed it will append the xml_jump_string. Once this mapping is ran it will delete the next xml_jump_string pattern to the right of the curser and delete it leaving you in insert mode to continue editing.
  • <LocalLeader>w
    Normal – Will clear the entire file of left over xml_jump_string garbage.
    This will also happen automatically when you save the file.
  • <LocalLeader>x
    Visual – Place a custom XML tag to suround the selected text. You need to have selected text in visual mode before you can use this mapping. (surround.vim and zencoding.vim does this too)
  • <LocalLeader>. or      <LocalLeader>>
    Insert – Place a literal ‘>’ without parsing tag.
  • <LocalLeader>5 or      <LocalLeader>%
    Normal or Visual – Jump to the begining or end tag. (matchit.vim does this too)
  • <LocalLeader>d
    Normal – Deletes the surrounding tags from the cursor. (surround.vim does this too)

Development, Vi-IMproved , , ,

Vim: SQL Completion (Summary)

July 18th, 2010

The Structured Query Language (SQL) is a standard which specifies statements that allow a user to interact with a relational database.  Vim includes features for navigation, indentation and syntax highlighting.

1. SQL Dialects

  • sql-dialects sql-types
  • sybase TSQL Transact-SQL
  • sqlanywhere
  • oracle plsql sqlj
  • sqlserver
  • mysql postgress psql
  • informix

1.1 SQLSetType

For the people that work with many different databases, it is nice to be able to flip between the various vendors rules (indent, syntax) on a per buffer basis, at any time.  The ftplugin/sql.vim file defines this function:

SQLSetType

Executing this function without any parameters will set the indent and syntax scripts back to their defaults.

1.2 SQL Dialect Default

As mentioned earlier, the default syntax rules for Vim is based on Oracle (PL/SQL).  You can override this default by placing one of the following in your vimrc:

let g:sql_type_default = 'sqlanywhere'

2. SQL Completion Tutorial

First, create a new buffer:

:e tutorial.sql

Static features

To take you through the various lists, simply enter insert mode, hit:
<C-C>s (show SQL statements)

At this point, you can page down through the list until you find “select”.
If you are familiar with the item you are looking for, for example you know
the statement begins with the letter “s”.  You can type ahead (without the
quotes) “se” then press:
<C-Space>t

Assuming “select” is highlighted in the popup list press <Enter> to choose
the entry.  Now type:

fr<C-C>a (show all syntax items)

choose “from” from the popup list.

When writing stored procedures using the “type” list is useful.  It contains
a list of all the database supported types.  This may or may not be true
depending on the syntax file you are using.  The SQL Anywhere syntax file
(sqlanywhere.vim) has support for this: >

BEGIN
  DECLARE customer_id <C-C>T <-- Choose a type from the list

Dynamic features

To take advantage of the dynamic features you must first install the
dbext.vim plugin (http://vim.sourceforge.net/script.php?script_id=356).  It
also comes with a tutorial.

Assuming you have followed the dbext-tutorial you can press <C-C>t to
display a list of tables.  There is a delay while dbext is creating the table
list.  After the list is displayed press <C-W>.  This will remove both the
popup window and the table name already chosen when the list became active. >

2.1 Table Completion:

Press <C-C>t to display a list of tables from within the database you
have connected via the dbext plugin.

2.2 Column Completion:

The SQL completion plugin can also display a list of columns for particular
tables.  The column completion is trigger via <C-C>c.

Example of using column completion:

  • Press <C-C>t again to display the list of tables.
  • When the list is displayed in the completion window, press <Right>, this will replace the list of tables, with a list of columns for the table highlighted (after the same short delay).
  • If you press <Left>, this will again replace the column list with the list of tables.  This allows you to drill into tables and column lists very quickly.
  • Press <Right> again while the same table is highlighted.  You will notice there is no delay since the column list has been cached.  If you change the schema of a cached table you can press <C-C>R, which clears the SQL completion cache.

Lets look how we can build a SQL statement dynamically.  A select statement requires a list of columns.  There are two ways to build a column list using the SQL completion plugin.
One column at a time:

  1. After typing SELECT press <C-C>t to display a list of tables.
  2. Choose a table from the list.
  3. Press <Right> to display a list of columns.
  4. Choose the column from the list and press enter.
  5. Enter a “,” and press <C-C>c.  Generating a column list generally requires having the cursor on a table name.  The plugin uses this name to determine what table to retrieve the column list. In this step, since we are pressing <C-C>c without the cursor on a table name the column list displayed will be for the previous table.  Choose a different column and move on.
  6. Repeat step 5 as often as necessary.

All columns for a table:

  1. After typing SELECT press <C-C>t to display a list of tables.
  2. Highlight the table you need the column list for.
  3. Press <Enter> to choose the table from the list.
  4. Press <C-C>l to request a comma separated list of all columns for this table.
  5. Based on the table name chosen in step 3, the plugin attempts to decide on a reasonable table alias.  You are then prompted to either accept of change the alias.  Press OK.
  6. The table name is replaced with the column list of the table is replaced with the comma separate list of columns with the alias prepended to each of the columns.
  7. Step 3 and 4 can be replaced by pressing <C-C>L, which has a <C-Y> embedded in the map to choose the currently highlighted table in the list.

There is a special provision when writing select statements.  Consider the
following statement:

select *
  from customer c,
          contact cn,
          department as dp,
          employee e,
          site_options so
  where c.

In INSERT mode after typing the final “c.” which is an alias for the “customer” table, you can press either <C-C>c or <C-X><C-O>.  This will popup a list of columns for the customer table.  It does this by looking back
to the beginning of the select statement and finding a list of the tables specified in the FROM clause.  In this case it notes that in the string “customer c”, “c” is an alias for the customer table.  The optional “AS” keyword is also supported, “customer AS c”. >

3.0 SQL Maps

The default SQL maps have been described in other sections of this document in greater detail.  Here is a list of the maps with a brief description of each.

Static Maps

These are maps which use populate the completion list using Vim’s syntax highlighting rules.

  • <C-C>a – Displays all SQL syntax items.
  • <C-C>k – Displays all SQL syntax items defined as ‘sqlKeyword’.
  • <C-C>f – Displays all SQL syntax items defined as ‘sqlFunction.
  • <C-C>o – Displays all SQL syntax items defined as ‘sqlOption’.
  • <C-C>T – Displays all SQL syntax items defined as ‘sqlType’.
  • <C-C>s – Displays all SQL syntax items defined as ‘sqlStatement’.

Dynamic Maps

These are maps which use populate the completion list using the dbext.vim plugin.

  • <C-C>t - Displays a list of tables.
  • <C-C>p – Displays a list of procedures.
  • <C-C>v – Displays a list of views.
  • <C-C>c – Displays a list of columns for a specific table.
  • <C-C>l – Displays a comma separated list of columns for a specific table.
  • <C-C>L – Displays a comma separated list of columns for a specific table. This should only be used when the completion window is active.
  • <Right> – Displays a list of columns for the table currently highlighted in the completion window.  <Right> is not recognized on most Unix systems, so this maps is only created on the Windows platform. If you would like the same feature on Unix, choose a different key and make the same map in your vimrc. >
  • <Left> – Displays the list of tables.
    <Left> is not recognized on most Unix systems, so this maps is only created on the Windows platform.  If you would like the same feature on Unix, choose a different key and make the same map in your vimrc.
  • <C-C>R – This maps removes all cached items and forces the SQL completion to regenerate the list of items.

Development, Vi-IMproved , ,

VIM: dbext, mapping

February 15th, 2010
  • Executing commands
    • <Leader>sbp (:DBPromptForBufferParameters)
    • <Leader>sel – s (sql) e (execute) l (line)
    • <Leader>se – s (sql) e (execute) (:DBExecSQLUnderCursor)
    • <Leader>sE – s (sql) e (execute) Prompt the user for how many rows
    • <Leader>se – s (sql) e (execute)  (:DBExecVisualSQL) (Visual mode)
  • Selecting from tables
    • <Leader>st – s (sql) t (table) (:DBSelectFromTable)
    • <Leader>sT s (sql) T (table) – Capital (:DBSelectFromTableTopX)
    • <Leader>stw s (sql) t (table) w (where clause) (:DBSelectFromTableWithWhere)
    • <Leader>sta s (sql) t (table) a (ask name) (:DBSelectFromTableAskName)
  • Describing objects
    • <Leader>sdt s (sql) d (describe) t (table) (:DBDescribeTable)
    • <Leader>sda s (sql) d (describe table) a (ask name) (:DBDescribeTableAskName)
    • <Leader>sdp s (sql) d (describe) p (procedure) (:DBDescribeProcedure)
    • <Leader>sdpa s (sql) d (describe) p (procedure) a (ask name) (:DBDescribeProcedureAskName)

  • Listing object
    • <Leader>slt s (sql) l (list) t (table) (:DBListTable)
    • <Leader>slp s (sql) l (list) p (procedure) (:DBListProcedure)
    • <Leader>slv s (sql) l (list) v (view) (:DBListView)
    • <Leader>slc s (sql) l (list) c (column) (:DBListColumn) (Result is in paste register)

  • Object Completion
    • hit in insert mode: CTRL-X CTRL-K
    • Run :DBCompleteTable, :DBCompleteProcedures, :DBCompleteViews to enable completion for a buffer
  • Host variable replacement
    • <Leader>slr (slv was already taken) (:DBListVar)
    • stored variables can be removed by placing your cursor on the line above and hitting ‘dd
    • You can used the DBSetVar command to both define and remove variables:
      :DBSetVar :myvar1=’myvar1′
      :DBSetVar @myvar2=’myvar2′
      :DBSetVar @myint3=
    • DBSetVar supports TAB completion.
    • OR In a buffer you can have multiple set statements and use mappings to define (or execute) the variables:
      set :myvar4 = ‘myvar4′;
      set @myvar5 = ‘myvar5′;
      set @myint6 = 6;

      If your cursor is on one of these lines you can use <Leader>sal (sql – assign – line),
      or you can visually select all 3 lines and use <Leader>sa or :’<,’>DBVarRangeAssign.
  • History
    • <Leader>sh s (sql) h (history), (:DBHistory)
    • <Enter> – Execute the statement.
    • q – close the window
    • a – Toggle the autoclose feature
    • dd – To remove statements from the history you can press “dd” as you would delete a line in a regular Vim buffer
    • <Space> – If using a vertical window will toggle the width to make it easier to read.

Result Buffer:

  • q – close the window
  • R – repeat last query
  • a – Toggle the autoclose feature
  • O – toggle the orientation (vertical/horizontal) (<Leader>so)
  • <Space> – If using a vertical window will toggle the width to make it easier to read.

more later…

Vi-IMproved , ,