dahu / vimple

Develop VimL
52 stars 2 forks source link

Vimple

Pacifying Vimmers

http://of-vim-and-vigor.blogspot.com/2012/03/pacifying-vimmers.html[Ad]

Perhaps most usefully, Vimple provides a few maps and commands to make the casual vimmer's life a little easier. If you don't want any of these maps and commands, they can be disabled by adding this line to your $MYVIMRC:

let g:init_vimple_maps_and_commands = 0

Here are a few examples of such maps and commands:

=== :View ex-command

Opens a split with the output of ex-command.

=== z=

Shows spelling suggestions in an overlay window. Pressing <enter> will replace the word under the cursor in the original window with the current word under the cursor in the overlay.

Use <plug>vimple_spell_suggest if you want to map this behaviour to a differnt key.

=== [I

Shows identifier search results in an overlay window. Pressing <enter> will jump to the associated line of the identifier under the cursor.

Use <plug>vimple_ident_search if you want to map this behaviour to a differnt key.

=== g]

Shows tag search results in an overlay window. Pressing <enter> will jump to the associated line of the tag under the cursor.

Use <plug>vimple_tag_search if you want to map this behaviour to a differnt key.

=== SCall( script , function , arg )

A function which calls script-local function in script with arguments arg. This lets you call <SNR> / s: functions by script name rather than SNR (script-number).

=== :Silently ex-command

Performs the series of bar-separated ex-commands silently.

=== :QFdo ex-command

Performs the series of bar-separated ex-commands over the buffers in the QuickFix list.

NOTE: The location-list analogue is :LLdo

=== :BufTypeDo type ex-commands

Performs the series of bar-separated ex-commands over the buffers of the given +type+.

=== :BufMatchDo pattern ex-commands

Performs the series of bar-separated ex-commands over the buffers with names matching +pattern+.

=== :Collect register-or-variable ex-command

Saves the output of ex-command into the specified register or variable.

=== Collect('register-or-variable ex-command')

Saves the output of ex-command into the specified register or variable and returns the output for further use in expressions.

=== GCollect( pattern )

Uses pattern in a :global /pattern/ command and returns the results as a list of lines.

:echo GCollect('^\s*===\s*')

=== GCCollect( pattern )

Uses pattern in a :global /pattern/ command and returns the results as a list of lines with the pattern stripped.

:echo GCCollect('^\s*===\s*')

=== :MyMaps

Shows your currently active |:map|s and |:imap|s in a new buffer. :MyMaps attempts to group related maps to more easily allow you to create a custom map layout for your various |'filetype'|s.

=== Scope()

The Scope() function attempts to show the current function or class/method scope. Some people like to display this information in their statusline, like:

set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]\%{Scope()}%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L]

Currently only Vim & Python (and Python only for testing purposes, created by a NON Pythonista -- patches welcome) have been implemented, but it is very easy for you to write scope functions for your own filetypes. Take Ruby for example: Create ~/.vim/ftplugin/ruby_scope.vim like this:


function! Scope_ruby() let classscope = scope#inspect('^\s*class\s+([a-zA-Z0-9.]+)', '^\send') let method_scope = scope#inspect('^\sdef\s+([a-zA-Z0-9_.]+)', '^\s*end') return ' ' . join(map(class_scope.stack, 'v:val.head_line_number . "," . v:val.tail_line_number . " " . v:val.head_string'), ' :: ') . ' >> ' . join(map(method_scope.stack, 'v:val.head_line_number . "," . v:val.tail_line_number . " " . v:val.head_string'), ' > ') endfunction

NOTE: The above example for Ruby is woefully inadequate. A better effect might be achievable with more context in the regex patterns. The patterns in syntax/ruby.vim might be useful. Parsing with regex is futile.

=== Composable Completions

By default, jj in insert mode activates a user-extendible meta-completion list. The default list includes abbreviations (if you have https://github.com/dahu/Aboriginal), some date-time patterns and the built-in dictionary completion (<c-x><c-k>).

The default jj can be overridden like this:

imap vimple_completers_trigger

Two other example shortcuts provided by vimple by default:

These defaults can be disabled by adding these lines to your $MYVIMRC:

imap vimple_completers_trigger imap vimple_completers_abbrev_trigger imap vimple_completers_datetime_trigger

NOTE: <unique> is used here to trigger a warning if you're re-using a <nop- n > map.

Vimple also provides VimLOO (Object Oriented VimL) objects for these read-only ++:ex++ commands:

NOTE: The awesome plugin https://github.com/Raimondi/vim-buffalo[buffalo] uses the vimple#bl object.

In addition to these existing ++:ex++ wrappers, Vimple allows developers to craft their own objects too. See autoload/vimple/*.vim for examples.