Vim configuration

This commit is contained in:
Joe Ferris 2011-01-13 17:54:08 -05:00
parent f8f427ef17
commit b291659f29
40 changed files with 11594 additions and 0 deletions

14
gvimrc Normal file
View file

@ -0,0 +1,14 @@
" No audible bell
set vb
" No toolbar
set guioptions-=T
" Use console dialogs
set guioptions+=c
" Local config
if filereadable($HOME . "/.gvimrc.local")
source ~/.gvimrc.local
endif

View file

@ -0,0 +1,2 @@
let g:html_indent_tags = g:html_indent_tags . '\|li'

4647
vim/autoload/rails.vim Normal file

File diff suppressed because it is too large Load diff

29
vim/compiler/cucumber.vim Normal file
View file

@ -0,0 +1,29 @@
" Vim compiler file
" Compiler: Cucumber
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 Aug 09
if exists("current_compiler")
finish
endif
let current_compiler = "cucumber"
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
let s:cpo_save = &cpo
set cpo-=C
CompilerSet makeprg=cucumber
CompilerSet errorformat=
\%W%m\ (Cucumber::Undefined),
\%E%m\ (%.%#),
\%Z%f:%l,
\%Z%f:%l:%.%#
let &cpo = s:cpo_save
unlet s:cpo_save
" vim:set sw=2 sts=2:

161
vim/doc/greplace.txt Normal file
View file

@ -0,0 +1,161 @@
*greplace.txt* Plugin for replacing pattern across multiple files
Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
For Vim version 7.0 and above
Last change: 2007 March 2
Overview~
The Global Replace plugin allows you to search and replace a pattern across
multiple files. The lines containing a specified pattern in multiple files are
displayed in a buffer. You can edit the lines in this buffer and make the
desired modifications to them. The plugin can then incorporate these changes
back into the corresponding files interactively.
==============================================================================
Installation~
1. Download the greplace.vim file and unzip the files into the $HOME/.vim
or the $HOME/vimfiles or the $VIM/vimfiles directory. After this step, you
should have the following two files (the directory structure should be
preserved):
plugin/greplace.vim - main global replace plugin file
doc/greplace.txt - documentation (help) file
2. Change to the $HOME/.vim/doc or $HOME/vimfiles/doc or $VIM/vimfiles/doc
directory, start Vim and run the ":helptags ." command to process the
help file. Without this step, you cannot jump to the help topics.
3. Restart Vim.
To uninstall the global replace plugin, remove the plugin/greplace.vim and
doc/greplace.txt files from the $HOME/.vim or $HOME/vimfiles directory.
==============================================================================
The following commands are provided by this plugin:
:Gsearch Search for a given pattern in the specified group of
files and display the matches in the replace buffer.
:Gbuffersearch Search for a given pattern in all the buffers
in the Vim buffer list.
:Gargsearch Search for a given pattern in all the files in the
Vim argument list.
:Gqfopen Use the results from the quickfix list.
:Greplace Incorporate the modifications from the replace buffer
into the corresponding files.
One example sequence of commands for using this plugin is:
:Gsearch mypattern *.java *.c
<The above command will search for mypattern in *.java and *.c
files in the current directory and display the matching lines
in a buffer.>
<You can now use the Vim editing commands to modify the buffer>
:Greplace
<The above command will load each of the buffer which needs to be changed
and ask you to confirm whether to make the change or not>
:wall
<To save all the modified buffers>
In the above sequence, instead of ":Gsearch", you can use ":Gbuffersearch" or
":Gargsearch" commands to search for a pattern in the files in the Vim buffer
list or the argument list.
The ":Gsearch" command uses the Vim ":grep" command to search for the pattern
in the specified files. The ":grep" command uses the program specified by the
"grepprg" option to search for the pattern. By default, the "grepprg" option
is set to either grep (on Unix) or findstr (on MS-Windows). By modifying the
"grepprg" option, you can also use other programs for searching. To use the
Vim internal grep, set the "grepprg" option to "internal".
The syntax of the ":Gsearch" command is:
>
:Gsearch [<grep-option(s)>] [[<pattern>] [<filename(s)>]]
<
The arguments to the ":Gsearch" command are optional.
The first set of arguments, if present, specify the options to the grep
program. These options must start with "-" (for Unix) and "/" (for
MS-Windows). For example, to ignore case, you can use "-i" for the Unix
grep program.
The next argument specifies the pattern. You cannot use space characters in
the pattern. To specify space characters in the pattern, don't specify the
pattern in the command-line. See below for more information.
The last set of arguments specify the filenames. You can use wildcards in the
filenames. You can also complete directory and file names by pressing <Tab>.
If the pattern or the filenames is not supplied as argument to the ":Gsearch"
command, then you will be prompted to enter the pattern and the filenames. The
default value for the search pattern is the keyword under the cursor. In the
prompt for entering the pattern, you can enter a pattern with space
characters. In the prompt for entering the filenames, you can press <Tab> to
complete the directory and file names.
To search for a pattern in the files in the Vim buffer list, use the
":Gbuffersearch" command. The syntax of this command is:
>
:Gbuffersearch [<grep-option(s)>]
<
This command is similar to the ":Gsearch" command. This command searches for
the specified pattern in all the files in the buffer list. You cannot specify
filenames to this command.
To search for a pattern in the files in the Vim argument list, use the
":Gargsearch" command. The syntax of this command is:
>
:Gargsearch [<grep-option(s)>]
<
This command is similar to the ":Gsearch" command. This command will search
for the specified pattern in all the files in the argument list. You cannot
specify filenames to this command.
The difference between the ":Gbuffersearch" command and the Vim
":bufdo %s/pattern/replace/c" command is that the ":Gbuffersearch" command
allows you to inspect and change the matching lines in a buffer and then
incorporate the changes. You can also make different changes to different
lines. With a single ":bufdo" command, you can make only the one type of
change in all the buffers. The same difference applies for the ":Gargsearch"
and the ":argdo" command.
Sometimes, you may have the desired list of filenames and the matching lines
in them already in the quickfix list. For example, you can run tools like
cscope, GNU id-utils, GNU global, etc., and get the results into the quickfix
list. To use this list of files for replacing text, you can use the ":Gqfopen"
command. This command doesn't take the pattern or filenames arguments. It
parses the file names and lines in them from the current quickfix list and
displays it in the replace buffer.
You can edit the contents of the replace buffer using the Vim editing
commands. You cannot save the contents to a regular file. You should not
change the filename or line numbers in the replace buffer. You should not add
additional lines in this buffer. If you don't want to make any changes, you
can close the replace buffer.
You can use the ":Greplace" command to store the modified lines from the
replace buffer back to the corresponding files. This command is available only
in the replace buffer.
The ":Greplace" command will prompt you to confirm each of the changes. At
this prompt, you can press 'y' to accept the change, 'n' to reject the change,
'a' to accept all the changes, 'b' to accept all the changes in the current
buffer and 'q' or <Escape> to exit the replace prompt and stop making the
changes.
To incorporate the modifications without the prompt, add "!" to the
":Greplace" command. This will force the ":Greplace" command to make the
changes without any prompts for confirmation.
The modified files will not be automatically saved. You can save all of them
using the ":wall" command or you can individually inspect the buffers for the
changes and then save the buffer using the ":w" command. You can undo the
changes individually by using the Vim "u" command.
==============================================================================
vim:tw=78:ts=8:noet:ft=help:

406
vim/doc/matchit.txt Normal file
View file

@ -0,0 +1,406 @@
*matchit.txt* Extended "%" matching
For instructions on installing this file, type
:help matchit-install
inside Vim.
For Vim version 6.3. Last change: 2007 Aug 29
VIM REFERENCE MANUAL by Benji Fisher
*matchit* *matchit.vim*
1. Extended matching with "%" |matchit-intro|
2. Activation |matchit-activate|
3. Configuration |matchit-configure|
4. Supporting a New Language |matchit-newlang|
5. Known Bugs and Limitations |matchit-bugs|
The functionality mentioned here is a plugin, see |add-plugin|.
This plugin is only available if 'compatible' is not set.
You can avoid loading this plugin by setting the "loaded_matchit" variable
in your |vimrc| file: >
:let loaded_matchit = 1
{Vi does not have any of this}
==============================================================================
1. Extended matching with "%" *matchit-intro*
*matchit-%*
% Cycle forward through matching groups, such as "if", "else", "endif",
as specified by |b:match_words|.
*g%* *v_g%* *o_g%*
g% Cycle backwards through matching groups, as specified by
|b:match_words|. For example, go from "if" to "endif" to "else".
*[%* *v_[%* *o_[%*
[% Go to [count] previous unmatched group, as specified by
|b:match_words|. Similar to |[{|.
*]%* *v_]%* *o_]%*
]% Go to [count] next unmatched group, as specified by
|b:match_words|. Similar to |]}|.
*v_a%*
a% In Visual mode, select the matching group, as specified by
|b:match_words|, containing the cursor. Similar to |v_a[|.
A [count] is ignored, and only the first character of the closing
pattern is selected.
In Vim, as in plain vi, the percent key, |%|, jumps the cursor from a brace,
bracket, or paren to its match. This can be configured with the 'matchpairs'
option. The matchit plugin extends this in several ways:
You can match whole words, such as "if" and "endif", not just
single characters. You can also specify a |regular-expression|.
You can define groups with more than two words, such as "if",
"else", "endif". Banging on the "%" key will cycle from the "if" to
the first "else", the next "else", ..., the closing "endif", and back
to the opening "if". Nested structures are skipped. Using |g%| goes
in the reverse direction.
By default, words inside comments and strings are ignored, unless
the cursor is inside a comment or string when you type "%". If the
only thing you want to do is modify the behavior of "%" so that it
behaves this way, you do not have to define |b:match_words|, since the
script uses the 'matchpairs' option as well as this variable.
See |matchit-details| for details on what the script does, and |b:match_words|
for how to specify matching patterns.
MODES: *matchit-modes* *matchit-v_%* *matchit-o_%*
Mostly, % and related motions (|g%| and |[%| and |]%|) work just like built-in
|motion| commands in |Operator-pending| and |Visual| modes. However, you
cannot make these motions |linewise| or |characterwise|, since the |:omap|s
that define them start with "v" in order to make the default behavior
inclusive. (See |o_v|.) In other words, "dV%" will not work. The
work-around is to go through Visual mode: "V%d" will work.
LANGUAGES: *matchit-languages*
Currently, the following languages are supported: Ada, ASP with VBS, Csh,
DTD, Entity, Essbase, Fortran, HTML, JSP (same as HTML), LaTeX, Lua, Pascal,
SGML, Shell, Tcsh, Vim, XML. Other languages may already have support via
the default |filetype-plugin|s in the standard vim distribution.
To support a new language, see |matchit-newlang| below.
DETAILS: *matchit-details* *matchit-parse*
Here is an outline of what matchit.vim does each time you hit the "%" key. If
there are |backref|s in |b:match_words| then the first step is to produce a
version in which these back references have been eliminated; if there are no
|backref|s then this step is skipped. This step is called parsing. For
example, "\(foo\|bar\):end\1" is parsed to yield
"\(foo\|bar\):end\(foo\|bar\)". This can get tricky, especially if there are
nested groups. If debugging is turned on, the parsed version is saved as
|b:match_pat|.
*matchit-choose*
Next, the script looks for a word on the current line that matches the pattern
just constructed. It includes the patterns from the 'matchpairs' option.
The goal is to do what you expect, which turns out to be a little complicated.
The script follows these rules:
Insist on a match that ends on or after the cursor.
Prefer a match that includes the cursor position (that is, one that
starts on or before the cursor).
Prefer a match that starts as close to the cursor as possible.
If more than one pattern in |b:match_words| matches, choose the one
that is listed first.
Examples:
Suppose you >
:let b:match_words = '<:>,<tag>:</tag>'
< and hit "%" with the cursor on or before the "<" in "a <tag> is born".
The pattern '<' comes first, so it is preferred over '<tag>', which
also matches. If the cursor is on the "t", however, then '<tag>' is
preferred, because this matches a bit of text containing the cursor.
If the two groups of patterns were reversed then '<' would never be
preferred.
Suppose you >
:let b:match_words = 'if:end if'
< (Note the space!) and hit "%" with the cursor at the end of "end if".
Then "if" matches, which is probably not what you want, but if the
cursor starts on the "end " then "end if" is chosen. (You can avoid
this problem by using a more complicated pattern.)
If there is no match, the cursor does not move. (Before version 1.13 of the
script, it would fall back on the usual behavior of |%|). If debugging is
turned on, the matched bit of text is saved as |b:match_match| and the cursor
column of the start of the match is saved as |b:match_col|.
Next, the script looks through |b:match_words| (original and parsed versions)
for the group and pattern that match. If debugging is turned on, the group is
saved as |b:match_ini| (the first pattern) and |b:match_tail| (the rest). If
there are |backref|s then, in addition, the matching pattern is saved as
|b:match_word| and a table of translations is saved as |b:match_table|. If
there are |backref|s, these are determined from the matching pattern and
|b:match_match| and substituted into each pattern in the matching group.
The script decides whether to search forwards or backwards and chooses
arguments for the |searchpair()| function. Then, the cursor is moved to the
start of the match, and |searchpair()| is called. By default, matching
structures inside strings and comments are ignored. This can be changed by
setting |b:match_skip|.
==============================================================================
2. Activation *matchit-activate*
You can use this script as a plugin, by copying it to your plugin directory.
See |add-global-plugin| for instructions. You can also add a line to your
|vimrc| file, such as >
:source $VIMRUNTIME/macros/matchit.vim
or >
:runtime macros/matchit.vim
Either way, the script should start working the next time you start up Vim.
(Earlier versions of the script did nothing unless a |buffer-variable| named
|b:match_words| was defined. Even earlier versions contained autocommands
that set this variable for various file types. Now, |b:match_words| is
defined in many of the default |filetype-plugin|s instead.)
For a new language, you can add autocommands to the script or to your vimrc
file, but the recommended method is to add a line such as >
let b:match_words = '\<foo\>:\<bar\>'
to the |filetype-plugin| for your language. See |b:match_words| below for how
this variable is interpreted.
TROUBLESHOOTING *matchit-troubleshoot*
The script should work in most installations of Vim. It may not work if Vim
was compiled with a minimal feature set, for example if the |+syntax| option
was not enabled. If your Vim has support for syntax compiled in, but you do
not have |syntax| highlighting turned on, matchit.vim should work, but it may
fail to skip matching groups in comments and strings. If the |filetype|
mechanism is turned off, the |b:match_words| variable will probably not be
defined automatically.
==============================================================================
3. Configuration *matchit-configure*
There are several variables that govern the behavior of matchit.vim. Note
that these are variables local to the buffer, not options, so use |:let| to
define them, not |:set|. Some of these variables have values that matter; for
others, it only matters whether the variable has been defined. All of these
can be defined in the |filetype-plugin| or autocommand that defines
|b:match_words| or "on the fly."
The main variable is |b:match_words|. It is described in the section below on
supporting a new language.
*MatchError* *matchit-hl* *matchit-highlight*
MatchError is the highlight group for error messages from the script. By
default, it is linked to WarningMsg. If you do not want to be bothered by
error messages, you can define this to be something invisible. For example,
if you use the GUI version of Vim and your command line is normally white, you
can do >
:hi MatchError guifg=white guibg=white
<
*b:match_ignorecase*
If you >
:let b:match_ignorecase = 1
then matchit.vim acts as if 'ignorecase' is set: for example, "end" and "END"
are equivalent. If you >
:let b:match_ignorecase = 0
then matchit.vim treats "end" and "END" differently. (There will be no
b:match_infercase option unless someone requests it.)
*b:match_debug*
Define b:match_debug if you want debugging information to be saved. See
|matchit-debug|, below.
*b:match_skip*
If b:match_skip is defined, it is passed as the skip argument to
|searchpair()|. This controls when matching structures are skipped, or
ignored. By default, they are ignored inside comments and strings, as
determined by the |syntax| mechanism. (If syntax highlighting is turned off,
nothing is skipped.) You can set b:match_skip to a string, which evaluates to
a non-zero, numerical value if the match is to be skipped or zero if the match
should not be skipped. In addition, the following special values are
supported by matchit.vim:
s:foo becomes (current syntax item) =~ foo
S:foo becomes (current syntax item) !~ foo
r:foo becomes (line before cursor) =~ foo
R:foo becomes (line before cursor) !~ foo
(The "s" is meant to suggest "syntax", and the "r" is meant to suggest
"regular expression".)
Examples:
You can get the default behavior with >
:let b:match_skip = 's:comment\|string'
<
If you want to skip matching structures unless they are at the start
of the line (ignoring whitespace) then you can >
:let b:match_skip = 'R:^\s*'
< Do not do this if strings or comments can span several lines, since
the normal syntax checking will not be done if you set b:match_skip.
In LaTeX, since "%" is used as the comment character, you can >
:let b:match_skip = 'r:%'
< Unfortunately, this will skip anything after "\%", an escaped "%". To
allow for this, and also "\\%" (an excaped backslash followed by the
comment character) you can >
:let b:match_skip = 'r:\(^\|[^\\]\)\(\\\\\)*%'
<
See the $VIMRUNTIME/ftplugin/vim.vim for an example that uses both
syntax and a regular expression.
==============================================================================
4. Supporting a New Language *matchit-newlang*
*b:match_words*
In order for matchit.vim to support a new language, you must define a suitable
pattern for |b:match_words|. You may also want to set some of the
|matchit-configure| variables, as described above. If your language has a
complicated syntax, or many keywords, you will need to know something about
Vim's |regular-expression|s.
The format for |b:match_words| is similar to that of the 'matchpairs' option:
it is a comma (,)-separated list of groups; each group is a colon(:)-separated
list of patterns (regular expressions). Commas and backslashes that are part
of a pattern should be escaped with backslashes ('\:' and '\,'). It is OK to
have only one group; the effect is undefined if a group has only one pattern.
A simple example is >
:let b:match_words = '\<if\>:\<endif\>,'
\ . '\<while\>:\<continue\>:\<break\>:\<endwhile\>'
(In Vim regular expressions, |\<| and |\>| denote word boundaries. Thus "if"
matches the end of "endif" but "\<if\>" does not.) Then banging on the "%"
key will bounce the cursor between "if" and the matching "endif"; and from
"while" to any matching "continue" or "break", then to the matching "endwhile"
and back to the "while". It is almost always easier to use |literal-string|s
(single quotes) as above: '\<if\>' rather than "\\<if\\>" and so on.
Exception: If the ":" character does not appear in b:match_words, then it is
treated as an expression to be evaluated. For example, >
:let b:match_words = 'GetMatchWords()'
allows you to define a function. This can return a different string depending
on the current syntax, for example.
Once you have defined the appropriate value of |b:match_words|, you will
probably want to have this set automatically each time you edit the
appropriate file type. The recommended way to do this is by adding the
definition to a |filetype-plugin| file.
Tips: Be careful that your initial pattern does not match your final pattern.
See the example above for the use of word-boundary expressions. It is usually
better to use ".\{-}" (as many as necessary) instead of ".*" (as many as
possible). See |\{-|. For example, in the string "<tag>label</tag>", "<.*>"
matches the whole string whereas "<.\{-}>" and "<[^>]*>" match "<tag>" and
"</tag>".
*matchit-spaces* *matchit-s:notend*
If "if" is to be paired with "end if" (Note the space!) then word boundaries
are not enough. Instead, define a regular expression s:notend that will match
anything but "end" and use it as follows: >
:let s:notend = '\%(\<end\s\+\)\@<!'
:let b:match_words = s:notend . '\<if\>:\<end\s\+if\>'
< *matchit-s:sol*
This is a simplified version of what is done for Ada. The s:notend is a
|script-variable|. Similarly, you may want to define a start-of-line regular
expression >
:let s:sol = '\%(^\|;\)\s*'
if keywords are only recognized after the start of a line or after a
semicolon (;), with optional white space.
*matchit-backref* *matchit-\1*
In any group, the expressions |\1|, |\2|, ..., |\9| refer to parts of the
INITIAL pattern enclosed in |\(|escaped parentheses|\)|. These are referred
to as back references, or backrefs. For example, >
:let b:match_words = '\<b\(o\+\)\>:\(h\)\1\>'
means that "bo" pairs with "ho" and "boo" pairs with "hoo" and so on. Note
that "\1" does not refer to the "\(h\)" in this example. If you have
"\(nested \(parentheses\)\) then "\d" refers to the d-th "\(" and everything
up to and including the matching "\)": in "\(nested\(parentheses\)\)", "\1"
refers to everything and "\2" refers to "\(parentheses\)". If you use a
variable such as |s:notend| or |s:sol| in the previous paragraph then remember
to count any "\(" patterns in this variable. You do not have to count groups
defined by |\%(\)|.
It should be possible to resolve back references from any pattern in the
group. For example, >
:let b:match_words = '\(foo\)\(bar\):more\1:and\2:end\1\2'
would not work because "\2" cannot be determined from "morefoo" and "\1"
cannot be determined from "andbar". On the other hand, >
:let b:match_words = '\(\(foo\)\(bar\)\):\3\2:end\1'
should work (and have the same effect as "foobar:barfoo:endfoobar"), although
this has not been thoroughly tested.
You can use |zero-width| patterns such as |\@<=| and |\zs|. (The latter has
not been thouroughly tested in matchit.vim.) For example, if the keyword "if"
must occur at the start of the line, with optional white space, you might use
the pattern "\(^\s*\)\@<=if" so that the cursor will end on the "i" instead of
at the start of the line. For another example, if HTML had only one tag then
one could >
:let b:match_words = '<:>,<\@<=tag>:<\@<=/tag>'
so that "%" can bounce between matching "<" and ">" pairs or (starting on
"tag" or "/tag") between matching tags. Without the |\@<=|, the script would
bounce from "tag" to the "<" in "</tag>", and another "%" would not take you
back to where you started.
DEBUGGING *matchit-debug* *:MatchDebug*
If you are having trouble figuring out the appropriate definition of
|b:match_words| then you can take advantage of the same information I use when
debugging the script. This is especially true if you are not sure whether
your patterns or my script are at fault! To make this more convenient, I have
made the command :MatchDebug, which defines the variable |b:match_debug| and
creates a Matchit menu. This menu makes it convenient to check the values of
the variables described below. You will probably also want to read
|matchit-details| above.
Defining the variable |b:match_debug| causes the script to set the following
variables, each time you hit the "%" key. Several of these are only defined
if |b:match_words| includes |backref|s.
*b:match_pat*
The b:match_pat variable is set to |b:match_words| with |backref|s parsed.
*b:match_match*
The b:match_match variable is set to the bit of text that is recognized as a
match.
*b:match_col*
The b:match_col variable is set to the cursor column of the start of the
matching text.
*b:match_wholeBR*
The b:match_wholeBR variable is set to the comma-separated group of patterns
that matches, with |backref|s unparsed.
*b:match_iniBR*
The b:match_iniBR variable is set to the first pattern in |b:match_wholeBR|.
*b:match_ini*
The b:match_ini variable is set to the first pattern in |b:match_wholeBR|,
with |backref|s resolved from |b:match_match|.
*b:match_tail*
The b:match_tail variable is set to the remaining patterns in
|b:match_wholeBR|, with |backref|s resolved from |b:match_match|.
*b:match_word*
The b:match_word variable is set to the pattern from |b:match_wholeBR| that
matches |b:match_match|.
*b:match_table*
The back reference '\'.d refers to the same thing as '\'.b:match_table[d] in
|b:match_word|.
==============================================================================
5. Known Bugs and Limitations *matchit-bugs*
Just because I know about a bug does not mean that it is on my todo list. I
try to respond to reports of bugs that cause real problems. If it does not
cause serious problems, or if there is a work-around, a bug may sit there for
a while. Moral: if a bug (known or not) bothers you, let me know.
The various |:vmap|s defined in the script (%, |g%|, |[%|, |]%|, |a%|) may
have undesired effects in Select mode |Select-mode-mapping|. At least, if you
want to replace the selection with any character in "ag%[]" there will be a
pause of |'updatetime'| first.
It would be nice if "\0" were recognized as the entire pattern. That is, it
would be nice if "foo:\end\0" had the same effect as "\(foo\):\end\1". I may
try to implement this in a future version. (This is not so easy to arrange as
you might think!)
==============================================================================
vim:tw=78:fo=tcq2:

1202
vim/doc/rails.txt Normal file

File diff suppressed because it is too large Load diff

218
vim/doc/surround.txt Normal file
View file

@ -0,0 +1,218 @@
*surround.txt* Plugin for deleting, changing, and adding "surroundings"
Author: Tim Pope <vimNOSPAM@tpope.info> *surround-author*
License: Same terms as Vim itself (see |license|)
This plugin is only available if 'compatible' is not set.
INTRODUCTION *surround*
This plugin is a tool for dealing with pairs of "surroundings." Examples
of surroundings include parentheses, quotes, and HTML tags. They are
closely related to what Vim refers to as |text-objects|. Provided
are mappings to allow for removing, changing, and adding surroundings.
Details follow on the exact semantics, but first, consider the following
examples. An asterisk (*) is used to denote the cursor position.
Old text Command New text ~
"Hello *world!" ds" Hello world!
[123+4*56]/2 cs]) (123+456)/2
"Look ma, I'm *HTML!" cs"<q> <q>Look ma, I'm HTML!</q>
if *x>3 { ysW( if ( x>3 ) {
my $str = *whee!; vlllls' my $str = 'whee!';
While a few features of this plugin will work in older versions of Vim,
Vim 7 is recommended for full functionality.
MAPPINGS *surround-mappings*
Delete surroundings is *ds* . The next character given determines the target
to delete. The exact nature of the target are explained in |surround-targets|
but essentially it is the last character of a |text-object|. This mapping
deletes the difference between the "inner" object and "an" object. This is
easiest to understand with some examples:
Old text Command New text ~
"Hello *world!" ds" Hello world!
(123+4*56)/2 ds) 123+456/2
<div>Yo!*</div> dst Yo!
Change surroundings is *cs* . It takes two arguments, a target like with
|ds|, and a replacement. Details about the second argument can be found
below in |surround-replacements|. Once again, examples are in order.
Old text Command New text ~
"Hello *world!" cs"' 'Hello world!'
"Hello *world!" cs"<q> <q>Hello world!</q>
(123+4*56)/2 cs)] [123+456]/2
(123+4*56)/2 cs)[ [ 123+456 ]/2
<div>Yo!*</div> cst<p> <p>Yo!</p>
*ys* takes an valid Vim motion or text object as the first object, and wraps
it using the second argument as with |cs|. (Unfortunately there's no good
mnemonic for "ys".)
Old text Command New text ~
Hello w*orld! ysiw) Hello (world)!
As a special case, *yss* operates on the current line, ignoring leading
whitespace.
Old text Command New text ~
Hello w*orld! yssB {Hello world!}
There is also *yS* and *ySS* which indent the surrounded text and place it
on a line of its own.
In visual mode, a simple "s" with an argument wraps the selection. This is
referred to as the *vs* mapping, although ordinarily there will be
additional keystrokes between the v and s. In linewise visual mode, the
surroundings are placed on separate lines. In blockwise visual mode, each
line is surrounded.
An "S" in visual mode (*vS*) behaves similarly but always places the
surroundings on separate lines. Additionally, the surrounded text is
indented. In blockwise visual mode, using "S" instead of "s" instead skips
trailing whitespace.
Note that "s" and "S" already have valid meaning in visual mode, but it is
identical to "c". If you have muscle memory for "s" and would like to use a
different key, add your own mapping and the existing one will be disabled.
>
vmap <Leader>s <Plug>Vsurround
vmap <Leader>S <Plug>VSurround
<
*i_CTRL-G_s* *i_CTRL-G_S*
Finally, there is an experimental insert mode mapping on <C-G>s and <C-S>.
Beware that the latter won't work on terminals with flow control (if you
accidentally freeze your terminal, use <C-Q> to unfreeze it). The mapping
inserts the specified surroundings and puts the cursor between them. If,
immediately after the mapping and before the replacement, a second <C-S> or
carriage return is pressed, the prefix, cursor, and suffix will be placed on
three separate lines. <C-G>S (not <C-G>s) also exhibits this behavior.
TARGETS *surround-targets*
The |ds| and |cs| commands both take a target as their first argument. The
possible targets are based closely on the |text-objects| provided by Vim.
In order for a target to work, the corresponding text object must be
supported in the version of Vim used (Vim 7 adds several text objects, and
thus is highly recommended). All targets are currently just one character.
Eight punctuation marks, (, ), {, }, [, ], <, and >, represent themselves
and their counterpart. If the opening mark is used, contained whitespace is
also trimmed. The targets b, B, r, and a are aliases for ), }, ], and >
(the first two mirror Vim; the second two are completely arbitrary and
subject to change).
Three quote marks, ', ", `, represent themselves, in pairs. They are only
searched for on the current line.
A t is a pair of HTML or XML tags. See |tag-blocks| for details. Remember
that you can specify a numerical argument if you want to get to a tag other
than the innermost one.
The letters w, W, and s correspond to a |word|, a |WORD|, and a |sentence|,
respectively. These are special in that they have nothing to delete, and
used with |ds| they are a no-op. With |cs|, one could consider them a
slight shortcut for ysi (cswb == ysiwb, more or less).
A p represents a |paragraph|. This behaves similarly to w, W, and s above;
however, newlines are sometimes added and/or removed.
REPLACEMENTS *surround-replacements*
A replacement argument is a single character, and is required by |cs|, |ys|,
and |vs|. Undefined replacement characters (with the exception of alphabetic
characters) default to placing themselves at the beginning and end of the
destination, which can be useful for characters like / and |.
If either ), }, ], or > is used, the text is wrapped in the appropriate pair
of characters. Similar behavior can be found with (, {, and [ (but not <),
which append an additional space to the inside. Like with the targets above,
b, B, r, and a are aliases for ), }, ], and >. To fulfill the common need for
code blocks in C-style languages, <C-}> (which is really <C-]>) adds braces on
lines separate from the content.
If t or < is used, Vim prompts for an HTML/XML tag to insert. You may specify
attributes here and they will be stripped from the closing tag. End your
input by pressing <CR> or >. If <C-T> is used, the tags will appear on lines
by themselves.
A deprecated replacement of a LaTeX environment is provided on \ and l. The
name of the environment and any arguments will be input from a prompt. This
will be removed once a more fully functional customization system is
implemented. The following shows the resulting environment from
csp\tabular}{lc<CR>
>
\begin{tabular}{lc}
\end{tabular}
<
CUSTOMIZING *surround-customizing*
The following adds a potential replacement on "-" (ASCII 45) in PHP files.
(To determine the ASCII code to use, :echo char2nr("-")). The carriage
return will be replaced by the original text.
>
autocmd FileType php let b:surround_45 = "<?php \r ?>"
<
This can be used in a PHP file as in the following example.
Old text Command New text ~
print "Hello *world!" yss- <?php print "Hello world!" ?>
Additionally, one can use a global variable for globally available
replacements.
>
let g:surround_45 = "<% \r %>"
let g:surround_61 = "<%= \r %>"
<
Advanced, experimental, and subject to change: One can also prompt for
replacement text. The syntax for this is to surround the replacement in pairs
of low numbered control characters. If this sounds confusing, that's because
it is (but it makes the parsing easy). Consider the following example for a
LaTeX environment on the "l" replacement.
>
let g:surround_108 = "\\begin{\1environment: \1}\r\\end{\1\1}"
<
When this replacement is used, the user is prompted with an "environment: "
prompt for input. This input is inserted between each set of \1's.
Additional inputs up to \7 can be used.
Furthermore, one can specify a regular expression substitution to apply.
>
let g:surround_108 = "\\begin{\1environment: \1}\r\\end{\1\r}.*\r\1}"
<
This will remove anything after the first } in the input when the text is
placed within the \end{} slot. The first \r marks where the pattern begins,
and the second where the replacement text begins.
Here's a second example for creating an HTML <div>. The substitution cleverly
prompts for an id, but only adds id="" if it is non-blank. You may have to
read this one a few times slowly before you understand it.
>
let g:surround_{char2nr("d")} = "<div\1id: \r..*\r id=\"&\"\1>\r</div>"
<
Inputting text replacements is a proof of concept at this point. The ugly,
unintuitive interface and the brevity of the documentation reflect this.
Finally, It is possible to always append a string to surroundings in insert
mode (and only insert mode). This is useful with certain plugins and mappings
that allow you to jump to such markings.
>
let g:surround_insert_tail = "<++>"
<
ISSUES *surround-issues*
Vim could potentially get confused when deleting/changing occurs at the very
end of the line. Please report any repeatable instances of this.
Do we need to use |inputsave()|/|inputrestore()| with the tag replacement?
Indenting is handled haphazardly. Need to decide the most appropriate
behavior and implement it. Right now one can do :let b:surround_indent = 1
(or the global equivalent) to enable automatic re-indenting by Vim via |=|;
should this be the default?
vim:tw=78:ts=8:ft=help:norl:

208
vim/doc/tComment.txt Normal file
View file

@ -0,0 +1,208 @@
*tComment.txt* tComment -- An easily extensible & universal comment plugin
Author: Thomas Link, micathom AT gmail com?subject=vim
tComment provides easy to use, file-type sensible comments for Vim. It
can handle embedded syntax.
*tComment-Installation*
Installation~
Edit the vba file and type:
:so %
See :help vimball for details. If you use vim 7.0, you may need to
update your vimball installation first.
*tComment-Usage*
Usage~
TComment works like a toggle, i.e., it will comment out text that
contains uncommented lines, and it will remove comment markup for
already commented text (i.e. text that contains no uncommented lines).
If the file-type is properly defined, TComment will figure out which
comment string to use. Otherwise you use |TCommentDefineType()| to
override the default choice.
TComment can properly handle an embedded syntax, e.g., ruby/python/perl
regions in vim scripts, HTML or JavaScript in php code etc.
*tComment-Key-Bindings*
Key bindings~
Most of the time the default toggle keys will do what you want (or to be
more precise: what I think it should to ;-).
*g:tcommentMapLeaderOp1*
*g:tcommentMapLeaderOp2*
As operator (the prefix can be customized via g:tcommentMapLeaderOp1
and g:tcommentMapLeaderOp2):
gc{motion} :: Toggle comments (for small comments within one line
the &filetype_inline style will be used, if
defined)
gcc :: Toggle comment for the current line
gC{motion} :: Comment region
gCc :: Comment the current line
*g:tcommentOpModeExtra*
By default the cursor stays put. If you want the cursor to the end of
the commented text, set g:tcommentOpModeExtra to '>' (but this may not
work properly with exclusive motions).
Primary key maps:
<c-_><c-_> :: :TComment
<c-_><space> :: :TComment <QUERY COMMENT-BEGIN ?COMMENT-END>
<c-_>b :: :TCommentBlock
<c-_>a :: :TCommentAs <QUERY COMMENT TYPE>
<c-_>n :: :TCommentAs &filetype <QUERY COUNT>
<c-_>s :: :TCommentAs &filetype_<QUERY COMMENT SUBTYPE>
<c-_>i :: :TCommentInline
<c-_>r :: :TCommentRight
<c-_>p :: Comment the current inner paragraph
A secondary set of key maps is defined for normal mode.
<Leader>__ :: :TComment
<Leader>_p :: Comment the current inner paragraph
<Leader>_<space> :: :TComment <QUERY COMMENT-BEGIN ?COMMENT-END>
<Leader>_i :: :TCommentInline
<Leader>_r :: :TCommentRight
<Leader>_b :: :TCommentBlock
<Leader>_a :: :TCommentAs <QUERY COMMENT TYPE>
<Leader>_n :: :TCommentAs &filetype <QUERY COUNT>
<Leader>_s :: :TCommentAs &filetype_<QUERY COMMENT SUBTYPE>
Keymaps are configurable via the following variables:
*g:tcommentMapLeader1*
g:tcommentMapLeader1 string (default: <c-_>)
Prefix for the keymaps. Set to '' to disable keymaps with this
prefix.
*g:tcommentMapLeader2*
g:tcommentMapLeader2 string (default: <Leader>_)
Secondary prefix. (The reason for why there are two prefixes is
that <c-_> appears preferable with gvim but can be difficult to
type on the terminal. The secondary prefix isn't used for insert
mode maps. Set to '' to disable keymaps with this prefix.
*tComment-commands*
Alternatively, you can type (? meaning "optional argument"):
*:TComment*
:?<range> TComment ?commentBegin ?commentEnd
:?<range> TComment! ?commentBegin ?commentEnd
NOTE: If there is a visual selection that begins and ends in the same
line, then TCommentInline is used instead.
NOTE: The range is optional and defaults to the current line.
*:TCommentInline*
:?<range> TCommentInline ?commentBegin ?commentEnd
:?<range> TCommentInline! ?commentBegin ?commentEnd
Use the {&ft}_inline comment style.
*:TCommentBlock*
:?<range> TCommentBlock ?commentBegin ?commentEnd
:?<range> TCommentBlock! ?commentBegin ?commentEnd
Comment as "block", e.g. use the {&ft}_block comment style.
NOTE: This command is kind of crude. It doesn't indent or reformat
the text.
*:TCommentAs*
:?<range> TCommentAs filetype
:?<range> TCommentAs! filetype
NOTE: TCommentAs requires g:tcomment_{filetype} to be defined.
NOTE: This command supports command line completion. See 'wildmode'
and 'wildmenu' for how to get the most out of it.
*:TCommentRight*
:?<range> TCommentRight
:?<range> TCommentRight!
NOTE: This command comments out the text to the right of the cursor.
If a visual selection was made (be it block-wise or not), all lines
are commented out at from the current cursor position downwards.
The bang (!) variants always comment out the selected text and don't
work as toggles.
*TCommentDefineType()*
Using this command you can also use different comment styles with
the TCommentDefineType(name, commentstring) function. This function
takes two arguments:
name :: The name is either &filetype or {&filetype}_{style}.
I.e., For block comments the {&filetype}_block and for
inline comments the {&filetype}_inline styles are used.
comment string :: a string mostly as described in
'commentstring'.
If you want to define, e.g., a fancy block comment style for html
you put something like this into ~/.vim/after/plugin/tComment.vim:>
call TCommentDefineType("html_fancy_block", "<!--%s -->\n -- ")
< The part after the newline character is used for marking "middle"
lines.
This comment style could then be accessed via (this command has
command line completion): >
'<,'>TCommentAs html_fancy_block
< If you're editing a html file, this could best be done by the <c-_>s
key map.
Goals~
- Maintain indentation of selected text; the comment markers are left
aligned but the text on the right (i.e., the comment) is indented
like the original text
- Handle embedded syntax like php+html or html+javaScript+css; you
have to set g:tcommentGuessFileType_{&filetype} to 1 or to the
fall-back file-type in order to activate this feature for other file
types than php or html
tComment deduces the correct file type from the syntax name, similar
to the way EnhancedCommentify.vim does it. In opposition to
EnhancedCommentify.vim, it matches the syntax name against a list the
known file types, so that it can deal with, e.g., embedded javaScript
- Easy to customize/adapt for an yet unknown syntax by setting buffer
local variables (b:commentStart, b:commentEnd, or b:commentstring),
global variables (g:tcomment_{&ft} and g:tcomment_{&ft}_block), or the
buffer local &commentstring option (which can be set on a vim
|modeline|)
- Use 'commentstring' or 'comments' as a fallback (i.e., if a file-type
is properly defined, TComment will automatically support it)
- Same short-cut for commenting text and for removing comment markup
- The decision whether text should be commented or uncommented is made
on the basis of the whole selection (not line by line); comments in
code that should be commented aren't uncommented as it is the case
with some other plug-ins
As of version 1.5, the following file types are explicitly defined
(other file-types are most likely supported through the 'commentstring'
or 'comments' variables):
ada, apache, autoit, catalog, cpp, css, c, cfg, conf, desktop,
docbk, dosbatch, dosini, dsl, dylan, eiffel, gtkrc, haskell, html,
io, javaScript, java, lisp, m4, nroff, objc, ocaml, pascal, perl,
php, prolog, ruby, r, scheme, sgml, sh, sql, spec, sps, tcl, tex,
tpl, viki, vim, websec, xml, xslt, yaml
Credits~
The way we check for embedded syntax was originally adapted
from/inspired by Meikel Brandmeyer's EnhancedCommentify.vim
(vimscript #23) but has evolved since.
vim: tw=72

269
vim/doc/tags Normal file
View file

@ -0,0 +1,269 @@
:MatchDebug matchit.txt /*:MatchDebug*
:Snippet snippets_emu.txt /*:Snippet*
:TComment tComment.txt /*:TComment*
:TCommentAs tComment.txt /*:TCommentAs*
:TCommentBlock tComment.txt /*:TCommentBlock*
:TCommentInline tComment.txt /*:TCommentInline*
:TCommentRight tComment.txt /*:TCommentRight*
CreateBundleSnippet snippets_emu.txt /*CreateBundleSnippet*
CreateSnippet snippets_emu.txt /*CreateSnippet*
MatchError matchit.txt /*MatchError*
TCommentDefineType() tComment.txt /*TCommentDefineType()*
[% matchit.txt /*[%*
]% matchit.txt /*]%*
b:match_col matchit.txt /*b:match_col*
b:match_debug matchit.txt /*b:match_debug*
b:match_ignorecase matchit.txt /*b:match_ignorecase*
b:match_ini matchit.txt /*b:match_ini*
b:match_iniBR matchit.txt /*b:match_iniBR*
b:match_match matchit.txt /*b:match_match*
b:match_pat matchit.txt /*b:match_pat*
b:match_skip matchit.txt /*b:match_skip*
b:match_table matchit.txt /*b:match_table*
b:match_tail matchit.txt /*b:match_tail*
b:match_wholeBR matchit.txt /*b:match_wholeBR*
b:match_word matchit.txt /*b:match_word*
b:match_words matchit.txt /*b:match_words*
basic-snippet snippets_emu.txt /*basic-snippet*
config/rails.vim rails.txt /*config\/rails.vim*
creating-snippets snippets_emu.txt /*creating-snippets*
cs surround.txt /*cs*
ds surround.txt /*ds*
g% matchit.txt /*g%*
g:loaded_rails rails.txt /*g:loaded_rails*
g:rails_abbreviations rails.txt /*g:rails_abbreviations*
g:rails_dbext rails.txt /*g:rails_dbext*
g:rails_default_database rails.txt /*g:rails_default_database*
g:rails_default_file rails.txt /*g:rails_default_file*
g:rails_expensive rails.txt /*g:rails_expensive*
g:rails_gnu_screen rails.txt /*g:rails_gnu_screen*
g:rails_history_size rails.txt /*g:rails_history_size*
g:rails_mappings rails.txt /*g:rails_mappings*
g:rails_menu rails.txt /*g:rails_menu*
g:rails_modelines rails.txt /*g:rails_modelines*
g:rails_statusline rails.txt /*g:rails_statusline*
g:rails_syntax rails.txt /*g:rails_syntax*
g:rails_tabstop rails.txt /*g:rails_tabstop*
g:rails_url rails.txt /*g:rails_url*
g:tcommentMapLeader1 tComment.txt /*g:tcommentMapLeader1*
g:tcommentMapLeader2 tComment.txt /*g:tcommentMapLeader2*
g:tcommentMapLeaderOp1 tComment.txt /*g:tcommentMapLeaderOp1*
g:tcommentMapLeaderOp2 tComment.txt /*g:tcommentMapLeaderOp2*
g:tcommentOpModeExtra tComment.txt /*g:tcommentOpModeExtra*
greplace.txt greplace.txt /*greplace.txt*
i_CTRL-G_S surround.txt /*i_CTRL-G_S*
i_CTRL-G_s surround.txt /*i_CTRL-G_s*
macros/rails.vim rails.txt /*macros\/rails.vim*
matchit matchit.txt /*matchit*
matchit-% matchit.txt /*matchit-%*
matchit-\1 matchit.txt /*matchit-\\1*
matchit-activate matchit.txt /*matchit-activate*
matchit-backref matchit.txt /*matchit-backref*
matchit-bugs matchit.txt /*matchit-bugs*
matchit-choose matchit.txt /*matchit-choose*
matchit-configure matchit.txt /*matchit-configure*
matchit-debug matchit.txt /*matchit-debug*
matchit-details matchit.txt /*matchit-details*
matchit-highlight matchit.txt /*matchit-highlight*
matchit-hl matchit.txt /*matchit-hl*
matchit-intro matchit.txt /*matchit-intro*
matchit-languages matchit.txt /*matchit-languages*
matchit-modes matchit.txt /*matchit-modes*
matchit-newlang matchit.txt /*matchit-newlang*
matchit-o_% matchit.txt /*matchit-o_%*
matchit-parse matchit.txt /*matchit-parse*
matchit-s:notend matchit.txt /*matchit-s:notend*
matchit-s:sol matchit.txt /*matchit-s:sol*
matchit-spaces matchit.txt /*matchit-spaces*
matchit-troubleshoot matchit.txt /*matchit-troubleshoot*
matchit-v_% matchit.txt /*matchit-v_%*
matchit.txt matchit.txt /*matchit.txt*
matchit.vim matchit.txt /*matchit.vim*
named-tags snippets_emu.txt /*named-tags*
o_[% matchit.txt /*o_[%*
o_]% matchit.txt /*o_]%*
o_g% matchit.txt /*o_g%*
rails rails.txt /*rails*
rails-'cfu' rails.txt /*rails-'cfu'*
rails-'completefunc' rails.txt /*rails-'completefunc'*
rails-'efm' rails.txt /*rails-'efm'*
rails-'errorformat' rails.txt /*rails-'errorformat'*
rails-'et' rails.txt /*rails-'et'*
rails-'expandtab' rails.txt /*rails-'expandtab'*
rails-'filetype' rails.txt /*rails-'filetype'*
rails-'ft' rails.txt /*rails-'ft'*
rails-'includeexpr' rails.txt /*rails-'includeexpr'*
rails-'inex' rails.txt /*rails-'inex'*
rails-'makeprg' rails.txt /*rails-'makeprg'*
rails-'mp' rails.txt /*rails-'mp'*
rails-'pa' rails.txt /*rails-'pa'*
rails-'path' rails.txt /*rails-'path'*
rails-'shiftwidth' rails.txt /*rails-'shiftwidth'*
rails-'softtabstop' rails.txt /*rails-'softtabstop'*
rails-'statusline' rails.txt /*rails-'statusline'*
rails-'stl' rails.txt /*rails-'stl'*
rails-'sts' rails.txt /*rails-'sts'*
rails-'sua' rails.txt /*rails-'sua'*
rails-'suffixesadd' rails.txt /*rails-'suffixesadd'*
rails-'sw' rails.txt /*rails-'sw'*
rails-:A rails.txt /*rails-:A*
rails-:AE rails.txt /*rails-:AE*
rails-:AS rails.txt /*rails-:AS*
rails-:AT rails.txt /*rails-:AT*
rails-:AV rails.txt /*rails-:AV*
rails-:OpenURL rails.txt /*rails-:OpenURL*
rails-:R rails.txt /*rails-:R*
rails-:RE rails.txt /*rails-:RE*
rails-:RS rails.txt /*rails-:RS*
rails-:RT rails.txt /*rails-:RT*
rails-:RV rails.txt /*rails-:RV*
rails-:Rabbrev rails.txt /*rails-:Rabbrev*
rails-:Rabbrev! rails.txt /*rails-:Rabbrev!*
rails-:Rails rails.txt /*rails-:Rails*
rails-:Rake rails.txt /*rails-:Rake*
rails-:Rake! rails.txt /*rails-:Rake!*
rails-:Rapi rails.txt /*rails-:Rapi*
rails-:Rcd rails.txt /*rails-:Rcd*
rails-:Rcommand rails.txt /*rails-:Rcommand*
rails-:Rconsole rails.txt /*rails-:Rconsole*
rails-:Rcontroller rails.txt /*rails-:Rcontroller*
rails-:Rdbext rails.txt /*rails-:Rdbext*
rails-:Rdbext! rails.txt /*rails-:Rdbext!*
rails-:Rdestroy rails.txt /*rails-:Rdestroy*
rails-:Rdoc rails.txt /*rails-:Rdoc*
rails-:Rdoc! rails.txt /*rails-:Rdoc!*
rails-:Redit rails.txt /*rails-:Redit*
rails-:Rextract rails.txt /*rails-:Rextract*
rails-:Rfind rails.txt /*rails-:Rfind*
rails-:Rfixtures rails.txt /*rails-:Rfixtures*
rails-:Rfunctionaltest rails.txt /*rails-:Rfunctionaltest*
rails-:Rgenerate rails.txt /*rails-:Rgenerate*
rails-:Rhelper rails.txt /*rails-:Rhelper*
rails-:Rintegrationtest rails.txt /*rails-:Rintegrationtest*
rails-:Rinvert rails.txt /*rails-:Rinvert*
rails-:Rjavascript rails.txt /*rails-:Rjavascript*
rails-:Rlayout rails.txt /*rails-:Rlayout*
rails-:Rlcd rails.txt /*rails-:Rlcd*
rails-:Rlib rails.txt /*rails-:Rlib*
rails-:Rlog rails.txt /*rails-:Rlog*
rails-:Rmigration rails.txt /*rails-:Rmigration*
rails-:Rmodel rails.txt /*rails-:Rmodel*
rails-:Rnavcommand rails.txt /*rails-:Rnavcommand*
rails-:Robserver rails.txt /*rails-:Robserver*
rails-:Rp rails.txt /*rails-:Rp*
rails-:Rpartial rails.txt /*rails-:Rpartial*
rails-:Rplugin rails.txt /*rails-:Rplugin*
rails-:Rpp rails.txt /*rails-:Rpp*
rails-:Rpreview rails.txt /*rails-:Rpreview*
rails-:Rpreview! rails.txt /*rails-:Rpreview!*
rails-:Rproject rails.txt /*rails-:Rproject*
rails-:Rproject! rails.txt /*rails-:Rproject!*
rails-:Rrefresh rails.txt /*rails-:Rrefresh*
rails-:Rrefresh! rails.txt /*rails-:Rrefresh!*
rails-:Rrunner rails.txt /*rails-:Rrunner*
rails-:Rscript rails.txt /*rails-:Rscript*
rails-:Rserver rails.txt /*rails-:Rserver*
rails-:Rserver! rails.txt /*rails-:Rserver!*
rails-:Rset rails.txt /*rails-:Rset*
rails-:Rspec rails.txt /*rails-:Rspec*
rails-:Rstylesheet rails.txt /*rails-:Rstylesheet*
rails-:Rtags rails.txt /*rails-:Rtags*
rails-:Rtask rails.txt /*rails-:Rtask*
rails-:Runittest rails.txt /*rails-:Runittest*
rails-:Rview rails.txt /*rails-:Rview*
rails-:Ry rails.txt /*rails-:Ry*
rails-:autocmd rails.txt /*rails-:autocmd*
rails-@params rails.txt /*rails-@params*
rails-abbreviations rails.txt /*rails-abbreviations*
rails-about rails.txt /*rails-about*
rails-alternate rails.txt /*rails-alternate*
rails-alternate-related rails.txt /*rails-alternate-related*
rails-autocommands rails.txt /*rails-autocommands*
rails-commands rails.txt /*rails-commands*
rails-configuration rails.txt /*rails-configuration*
rails-controller-navigation rails.txt /*rails-controller-navigation*
rails-cream rails.txt /*rails-cream*
rails-custom-navigation rails.txt /*rails-custom-navigation*
rails-dbext rails.txt /*rails-dbext*
rails-gf rails.txt /*rails-gf*
rails-global-settings rails.txt /*rails-global-settings*
rails-install-plugin rails.txt /*rails-install-plugin*
rails-install-vim rails.txt /*rails-install-vim*
rails-installation rails.txt /*rails-installation*
rails-integration rails.txt /*rails-integration*
rails-introduction rails.txt /*rails-introduction*
rails-license rails.txt /*rails-license*
rails-menu rails.txt /*rails-menu*
rails-merb rails.txt /*rails-merb*
rails-migrations rails.txt /*rails-migrations*
rails-misc-navigation rails.txt /*rails-misc-navigation*
rails-model-navigation rails.txt /*rails-model-navigation*
rails-modelines rails.txt /*rails-modelines*
rails-navigation rails.txt /*rails-navigation*
rails-options rails.txt /*rails-options*
rails-partials rails.txt /*rails-partials*
rails-plugin-author rails.txt /*rails-plugin-author*
rails-project rails.txt /*rails-project*
rails-rails-integration rails.txt /*rails-rails-integration*
rails-refactoring rails.txt /*rails-refactoring*
rails-related rails.txt /*rails-related*
rails-rspec rails.txt /*rails-rspec*
rails-screen rails.txt /*rails-screen*
rails-scripts rails.txt /*rails-scripts*
rails-slow rails.txt /*rails-slow*
rails-snippets rails.txt /*rails-snippets*
rails-surround rails.txt /*rails-surround*
rails-syntax rails.txt /*rails-syntax*
rails-syntax-assertions rails.txt /*rails-syntax-assertions*
rails-syntax-classes rails.txt /*rails-syntax-classes*
rails-syntax-deprecated rails.txt /*rails-syntax-deprecated*
rails-syntax-keywords rails.txt /*rails-syntax-keywords*
rails-syntax-strings rails.txt /*rails-syntax-strings*
rails-syntax-yaml rails.txt /*rails-syntax-yaml*
rails-tabs rails.txt /*rails-tabs*
rails-template-types rails.txt /*rails-template-types*
rails-vim-integration rails.txt /*rails-vim-integration*
rails.txt rails.txt /*rails.txt*
snip-advanced-tag-commands snippets_emu.txt /*snip-advanced-tag-commands*
snip-buffer-specific snippets_emu.txt /*snip-buffer-specific*
snip-bundles snippets_emu.txt /*snip-bundles*
snip-contact-details snippets_emu.txt /*snip-contact-details*
snip-contributors snippets_emu.txt /*snip-contributors*
snip-detailed-explanations snippets_emu.txt /*snip-detailed-explanations*
snip-elem-delimiter snippets_emu.txt /*snip-elem-delimiter*
snip-ftplugin snippets_emu.txt /*snip-ftplugin*
snip-limitations snippets_emu.txt /*snip-limitations*
snip-menu snippets_emu.txt /*snip-menu*
snip-remap-key snippets_emu.txt /*snip-remap-key*
snip-snippet-commands snippets_emu.txt /*snip-snippet-commands*
snip-special-vars snippets_emu.txt /*snip-special-vars*
snip-start-end-tags snippets_emu.txt /*snip-start-end-tags*
snip-tag-name-syntax snippets_emu.txt /*snip-tag-name-syntax*
snippet-commands snippets_emu.txt /*snippet-commands*
snippets_emu-bugs snippets_emu.txt /*snippets_emu-bugs*
snippets_emu-features snippets_emu.txt /*snippets_emu-features*
snippets_emu-options snippets_emu.txt /*snippets_emu-options*
snippets_emu-troubleshooting snippets_emu.txt /*snippets_emu-troubleshooting*
snippets_emu.txt snippets_emu.txt /*snippets_emu.txt*
surround surround.txt /*surround*
surround-author surround.txt /*surround-author*
surround-customizing surround.txt /*surround-customizing*
surround-issues surround.txt /*surround-issues*
surround-mappings surround.txt /*surround-mappings*
surround-replacements surround.txt /*surround-replacements*
surround-targets surround.txt /*surround-targets*
surround.txt surround.txt /*surround.txt*
tComment-Installation tComment.txt /*tComment-Installation*
tComment-Key-Bindings tComment.txt /*tComment-Key-Bindings*
tComment-Usage tComment.txt /*tComment-Usage*
tComment-commands tComment.txt /*tComment-commands*
tComment.txt tComment.txt /*tComment.txt*
v_[% matchit.txt /*v_[%*
v_]% matchit.txt /*v_]%*
v_a% matchit.txt /*v_a%*
v_g% matchit.txt /*v_g%*
vs surround.txt /*vs*
yS surround.txt /*yS*
ySS surround.txt /*ySS*
ys surround.txt /*ys*
yss surround.txt /*yss*

52
vim/doc/textile.txt Normal file
View file

@ -0,0 +1,52 @@
*textile.txt* Textile for Vim Last Change: November 3, 2008
===============================================================================
REQUIREMENTS *textile-requirements*
- ruby - http://ruby-lang.org/ (seperate executable, not compiled in)
- RedCloth - http://whytheluckystiff.net/ruby/redcloth/
Files with the extension *.textile will auto-detected. If editing a new file,
or otherwise, run ":setf textile" to enable textile commands.
==============================================================================
CHANGELOG *textile-changelog*
0.3 - Fixed keymappings in the documentation
0.2 - Added multiple colors for headers, and alternating colors for list
items
- Fixed error in the vim script for TextileRenderBufferToFile
- Changed shortcut keys from \tp to \rp (render preview instead of
textile preview, since it's file-type specific anyways)
0.1 - Initial Release
==============================================================================
COMMANDS *textile-commands*
h2. Commands
:TextilePreview - Render the current buffer to a temp file, and open it in
your web browser (OSX only)
<Leader>rp
:TextileRenderTab - ... to a new tab
<Leader>rt
:TextileRenderFile - ... to a file
<Leader>rf
<Leader> is \ by default, so <Leader>rp == \rp
==============================================================================
CREDITS *textile-credits*
- "Dominic Mitchell":http://happygiraffe.net/: initial syntax highlighting
- "Aaron Bieber":http://blog.aaronbieber.com/: improved syntax highlighting
- "Tim Harper":http://tim.theenchanter.com/ : improved syntax highlighting,
plugin
vim:tw=78:noet:wrap:ts=2:expandtab:ft=help:norl:

View file

@ -0,0 +1,2 @@
" Cucumber
autocmd BufNewFile,BufReadPost *.feature,*.story set filetype=cucumber

3
vim/ftdetect/haml.vim Normal file
View file

@ -0,0 +1,3 @@
autocmd BufNewFile,BufRead *.haml setf haml
autocmd BufNewFile,BufRead *.sass setf sass
autocmd BufNewFile,BufRead *.scss setf scss

132
vim/ftplugin/cucumber.vim Normal file
View file

@ -0,0 +1,132 @@
" Vim filetype plugin
" Language: Cucumber
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 Aug 09
" Only do this when not done yet for this buffer
if (exists("b:did_ftplugin"))
finish
endif
let b:did_ftplugin = 1
setlocal formatoptions-=t formatoptions+=croql
setlocal comments=:# commentstring=#\ %s
setlocal omnifunc=CucumberComplete
let b:undo_ftplugin = "setl fo< com< cms< ofu<"
let b:cucumber_root = expand('%:p:h:s?.*[\/]\%(features\|stories\)\zs[\/].*??')
if !exists("g:no_plugin_maps") && !exists("g:no_cucumber_maps")
nmap <silent><buffer> <C-]> :<C-U>exe <SID>jump('edit',v:count)<CR>
nmap <silent><buffer> <C-W>] :<C-U>exe <SID>jump('split',v:count)<CR>
nmap <silent><buffer> <C-W><C-]> :<C-U>exe <SID>jump('split',v:count)<CR>
nmap <silent><buffer> <C-W>} :<C-U>exe <SID>jump('pedit',v:count)<CR>
let b:undo_ftplugin .= "| sil! iunmap! <C-]>| sil! iunmap! <C-W>]| sil! iunmap! <C-W><C-]>| sil! iunmap! <C-W>}"
endif
function! s:jump(command,count)
let steps = s:steps('.')
if len(steps) == 0 || len(steps) < a:count
return 'echoerr "No matching step found"'
elseif len(steps) > 1 && !a:count
return 'echoerr "Multiple matching steps found"'
else
let c = a:count ? a:count-1 : 0
return a:command.' +'.steps[c][1].' '.escape(steps[c][0],' %#')
endif
endfunction
function! s:allsteps()
let step_pattern = '\C^\s*\K\k*\>\s*\zs\S.\{-\}\ze\s*\%(do\|{\)\s*\%(|[^|]*|\s*\)\=\%($\|#\)'
let steps = []
for file in split(glob(b:cucumber_root.'/**/*.rb'),"\n")
let lines = readfile(file)
let num = 0
for line in lines
let num += 1
if line =~ step_pattern
let type = matchstr(line,'\w\+')
let steps += [[file,num,type,matchstr(line,step_pattern)]]
endif
endfor
endfor
return steps
endfunction
function! s:steps(lnum)
let c = indent(a:lnum) + 1
while synIDattr(synID(a:lnum,c,1),'name') !~# '^$\|Region$'
let c = c + 1
endwhile
let step = matchstr(getline(a:lnum)[c-1 : -1],'^\s*\zs.\{-\}\ze\s*$')
return filter(s:allsteps(),'s:stepmatch(v:val[3],step)')
endfunction
function! s:stepmatch(receiver,target)
if a:receiver =~ '^[''"].*[''"]$'
let pattern = '^'.escape(substitute(a:receiver[1:-2],'$\w\+','(.*)','g'),'/').'$'
elseif a:receiver =~ '^/.*/$'
let pattern = a:receiver[1:-2]
elseif a:receiver =~ '^%r..*.$'
let pattern = escape(a:receiver[3:-2],'/')
else
return 0
endif
try
let vimpattern = substitute(substitute(pattern,'\\\@<!(?:','%(','g'),'\\\@<!\*?','{-}','g')
if a:target =~# '\v'.vimpattern
return 1
endif
catch
endtry
if has("ruby") && pattern !~ '\\\@<!#{'
ruby VIM.command("return #{if (begin; Kernel.eval('/'+VIM.evaluate('pattern')+'/'); rescue SyntaxError; end) === VIM.evaluate('a:target') then 1 else 0 end}")
else
return 0
endif
endfunction
function! s:bsub(target,pattern,replacement)
return substitute(a:target,'\C\\\@<!'.a:pattern,a:replacement,'g')
endfunction
function! CucumberComplete(findstart,base) abort
let indent = indent('.')
let group = synIDattr(synID(line('.'),indent+1,1),'name')
let type = matchstr(group,'\Ccucumber\zs\%(Given\|When\|Then\)')
let e = matchend(getline('.'),'^\s*\S\+\s')
if type == '' || col('.') < col('$') || e < 0
return -1
endif
if a:findstart
return e
endif
let steps = []
for step in s:allsteps()
if step[2] ==# type
if step[3] =~ '^[''"]'
let steps += [step[3][1:-2]]
elseif step[3] =~ '^/\^.*\$/$'
let pattern = step[3][2:-3]
let pattern = substitute(pattern,'\C^(?:|I )','I ','')
let pattern = s:bsub(pattern,'\\[Sw]','w')
let pattern = s:bsub(pattern,'\\d','1')
let pattern = s:bsub(pattern,'\\[sWD]',' ')
let pattern = s:bsub(pattern,'\[\^\\\="\]','_')
let pattern = s:bsub(pattern,'[[:alnum:]. _-][?*]?\=','')
let pattern = s:bsub(pattern,'\[\([^^]\).\{-\}\]','\1')
let pattern = s:bsub(pattern,'+?\=','')
let pattern = s:bsub(pattern,'(\([[:alnum:]. -]\{-\}\))','\1')
let pattern = s:bsub(pattern,'\\\([[:punct:]]\)','\1')
if pattern !~ '[\\()*?]'
let steps += [pattern]
endif
endif
endif
endfor
call filter(steps,'strpart(v:val,0,strlen(a:base)) ==# a:base')
return sort(steps)
endfunction
" vim:set sts=2 sw=2:

67
vim/ftplugin/haml.vim Normal file
View file

@ -0,0 +1,67 @@
" Vim filetype plugin
" Language: Haml
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 May 21
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
let s:save_cpo = &cpo
set cpo-=C
" Define some defaults in case the included ftplugins don't set them.
let s:undo_ftplugin = ""
let s:browsefilter = "All Files (*.*)\t*.*\n"
let s:match_words = ""
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
unlet! b:did_ftplugin
" Override our defaults if these were set by an included ftplugin.
if exists("b:undo_ftplugin")
let s:undo_ftplugin = b:undo_ftplugin
unlet b:undo_ftplugin
endif
if exists("b:browsefilter")
let s:browsefilter = b:browsefilter
unlet b:browsefilter
endif
if exists("b:match_words")
let s:match_words = b:match_words
unlet b:match_words
endif
runtime! ftplugin/ruby.vim ftplugin/ruby_*.vim ftplugin/ruby/*.vim
let b:did_ftplugin = 1
" Combine the new set of values with those previously included.
if exists("b:undo_ftplugin")
let s:undo_ftplugin = b:undo_ftplugin . " | " . s:undo_ftplugin
endif
if exists ("b:browsefilter")
let s:browsefilter = substitute(b:browsefilter,'\cAll Files (\*\.\*)\t\*\.\*\n','','') . s:browsefilter
endif
if exists("b:match_words")
let s:match_words = b:match_words . ',' . s:match_words
endif
" Change the browse dialog on Win32 to show mainly Haml-related files
if has("gui_win32")
let b:browsefilter="Haml Files (*.haml)\t*.haml\nSass Files (*.sass)\t*.sass\n" . s:browsefilter
endif
" Load the combined list of match_words for matchit.vim
if exists("loaded_matchit")
let b:match_words = s:match_words
endif
setlocal comments= commentstring=-#\ %s
let b:undo_ftplugin = "setl cms< com< "
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
let &cpo = s:save_cpo
" vim:set sw=2:

22
vim/ftplugin/sass.vim Normal file
View file

@ -0,0 +1,22 @@
" Vim filetype plugin
" Language: Sass
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 Jul 26
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
let b:undo_ftplugin = "setl cms< def< inc< inex< ofu< sua<"
setlocal commentstring=//\ %s
setlocal define=^\\s*\\%(@mixin\\\|=\\)
setlocal includeexpr=substitute(v:fname,'\\%(.*/\\\|^\\)\\zs','_','')
setlocal omnifunc=csscomplete#CompleteCSS
setlocal suffixesadd=.sass,.scss,.css
let &l:include = '^\s*@import\s\+\%(url(\)\=["'']\='
" vim:set sw=2:

12
vim/ftplugin/scss.vim Normal file
View file

@ -0,0 +1,12 @@
" Vim filetype plugin
" Language: SCSS
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 Jul 26
if exists("b:did_ftplugin")
finish
endif
runtime! ftplugin/sass.vim
" vim:set sw=2:

51
vim/ftplugin/textile.vim Normal file
View file

@ -0,0 +1,51 @@
" textile.vim
"
" Tim Harper (tim.theenchanter.com)
command! -nargs=0 TextileRenderFile call TextileRenderBufferToFile()
command! -nargs=0 TextileRenderTab call TextileRenderBufferToTab()
command! -nargs=0 TextilePreview call TextileRenderBufferToPreview()
noremap <buffer> <Leader>rp :TextilePreview<CR>
noremap <buffer> <Leader>rf :TextileRenderFile<CR>
noremap <buffer> <Leader>rt :TextileRenderTab<CR>
setlocal ignorecase
setlocal wrap
setlocal lbr
function! TextileRender(lines)
if (system('which ruby') == "")
throw "Could not find ruby!"
end
let text = join(a:lines, "\n")
let html = system("ruby -e \"def e(msg); puts msg; exit 1; end; begin; require 'rubygems'; rescue LoadError; e('rubygems not found'); end; begin; require 'redcloth'; rescue LoadError; e('RedCloth gem not installed. Run this from the terminal: sudo gem install RedCloth'); end; puts(RedCloth.new(\\$stdin.read).to_html(:textile))\"", text)
return html
endfunction
function! TextileRenderFile(lines, filename)
let html = TextileRender(getbufline(bufname("%"), 1, '$'))
let html = "<html><head><title>" . bufname("%") . "</title><body>\n" . html . "\n</body></html>"
return writefile(split(html, "\n"), a:filename)
endfunction
function! TextileRenderBufferToPreview()
let filename = "/tmp/textile-preview.html"
call TextileRenderFile(getbufline(bufname("%"), 1, '$'), filename)
" Modify this line to make it compatible on other platforms
call system("open -a Safari ". filename)
endfunction
function! TextileRenderBufferToFile()
let filename = input("Filename:", substitute(bufname("%"), "textile$", "html", ""), "file")
call TextileRenderFile(getbufline(bufname("%"), 1, '$'), filename)
echo "Rendered to '" . filename . "'"
endfunction
function! TextileRenderBufferToTab()
let html = TextileRender(getbufline(bufname("%"), 1, '$'))
tabnew
call append("^", split(html, "\n"))
set syntax=html
endfunction

14
vim/gvimrc Normal file
View file

@ -0,0 +1,14 @@
" No audible bell
set vb
" No toolbar
set guioptions-=T
" Use console dialogs
set guioptions+=c
" Local config
if filereadable($HOME . "/.gvimrc.local")
source ~/.gvimrc.local
endif

60
vim/indent/cucumber.vim Normal file
View file

@ -0,0 +1,60 @@
" Vim indent file
" Language: Cucumber
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 May 21
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent
setlocal indentexpr=GetCucumberIndent()
setlocal indentkeys=o,O,*<Return>,<:>,0<Bar>,0#,=,!^F
" Only define the function once.
if exists("*GetCucumberIndent")
finish
endif
function! s:syn(lnum)
return synIDattr(synID(a:lnum,1+indent(a:lnum),1),'name')
endfunction
function! GetCucumberIndent()
let line = getline(prevnonblank(v:lnum-1))
let cline = getline(v:lnum)
let syn = s:syn(prevnonblank(v:lnum-1))
let csyn = s:syn(v:lnum)
if csyn ==# 'cucumberFeature' || cline =~# '^\s*Feature:'
return 0
elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):'
return 2 * &sw
elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
return &sw
elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:'
return &sw
elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):'
return 3 * &sw
elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):'
return 2 * &sw
elseif cline =~# '^\s*@' && (s:syn(nextnonblank(v:lnum+1)) == 'cucumberFeature' || getline(nextnonblank(v:lnum+1)) =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0)
return 0
elseif line =~# '^\s*@'
return &sw
elseif cline =~# '^\s*|' && line =~# '^\s*|'
return indent(prevnonblank(v:lnum-1))
elseif cline =~# '^\s*|' && line =~# '^\s*[^|#]'
return indent(prevnonblank(v:lnum-1)) + &sw
elseif cline =~# '^\s*[^|# \t]' && line =~# '^\s*|'
return indent(prevnonblank(v:lnum-1)) - &sw
elseif cline =~# '^\s*$' && line =~# '^\s*|'
let in = indent(prevnonblank(v:lnum-1))
return in == indent(v:lnum) ? in : in - &sw
elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && getline(v:lnum+1) =~# '\S'
return indent(getline(v:lnum+1))
endif
return indent(prevnonblank(v:lnum-1))
endfunction
" vim:set sts=2 sw=2:

73
vim/indent/haml.vim Normal file
View file

@ -0,0 +1,73 @@
" Vim indent file
" Language: Haml
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 May 21
if exists("b:did_indent")
finish
endif
runtime! indent/ruby.vim
unlet! b:did_indent
let b:did_indent = 1
setlocal autoindent sw=2 et
setlocal indentexpr=GetHamlIndent()
setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when
" Only define the function once.
if exists("*GetHamlIndent")
finish
endif
let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)'
let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
if !exists('g:haml_self_closing_tags')
let g:haml_self_closing_tags = 'meta|link|img|hr|br'
endif
function! GetHamlIndent()
let lnum = prevnonblank(v:lnum-1)
if lnum == 0
return 0
endif
let line = substitute(getline(lnum),'\s\+$','','')
let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
let lastcol = strlen(line)
let line = substitute(line,'^\s\+','','')
let indent = indent(lnum)
let cindent = indent(v:lnum)
if cline =~# '\v^-\s*%(elsif|else|when)>'
let indent = cindent < indent ? cindent : indent - &sw
endif
let increase = indent + &sw
if indent == indent(lnum)
let indent = cindent <= indent ? -1 : increase
endif
let group = synIDattr(synID(lnum,lastcol,1),'name')
if line =~ '^!!!'
return indent
elseif line =~ '^/\%(\[[^]]*\]\)\=$'
return increase
elseif group == 'hamlFilter'
return increase
elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)'
return increase
elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
return increase
elseif line == '-#'
return increase
elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^%\v%('.g:haml_self_closing_tags.')>'
return indent
elseif group =~? '\v^%(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$'
return increase
elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter'
return GetRubyIndent()
else
return indent
endif
endfunction
" vim:set sw=2:

39
vim/indent/sass.vim Normal file
View file

@ -0,0 +1,39 @@
" Vim indent file
" Language: Sass
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 May 21
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
setlocal autoindent sw=2 et
setlocal indentexpr=GetSassIndent()
setlocal indentkeys=o,O,*<Return>,<:>,!^F
" Only define the function once.
if exists("*GetSassIndent")
finish
endif
let s:property = '^\s*:\|^\s*[[:alnum:]-]\+\%(:\|\s*=\)'
function! GetSassIndent()
let lnum = prevnonblank(v:lnum-1)
let line = substitute(getline(lnum),'\s\+$','','')
let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
let lastcol = strlen(line)
let line = substitute(line,'^\s\+','','')
let indent = indent(lnum)
let cindent = indent(v:lnum)
if line !~ s:property && cline =~ s:property
return indent + &sw
"elseif line =~ s:property && cline !~ s:property
"return indent - &sw
else
return -1
endif
endfunction
" vim:set sw=2:

12
vim/indent/scss.vim Normal file
View file

@ -0,0 +1,12 @@
" Vim indent file
" Language: SCSS
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Last Change: 2010 Jul 26
if exists("b:did_indent")
finish
endif
runtime! indent/css.vim
" vim:set sw=2:

10
vim/plugin/ctags.vim Normal file
View file

@ -0,0 +1,10 @@
function! UpdateCtags()
if filereadable("tmp/tags") && strpart(expand("%"), 0, len(getcwd())) == expand("%")
execute "silent! !ctags -f tmp/tags -a " . expand("%:p")
endif
endfunction
augroup ctags
autocmd!
autocmd BufWritePost * call UpdateCtags()
augroup END

132
vim/plugin/endwise.vim Normal file
View file

@ -0,0 +1,132 @@
" endwise.vim - EndWise
" Author: Tim Pope <vimNOSPAM@tpope.info>
" Version: 1.0
" Distributable under the same terms as Vim itself (see :help license)
" Exit quickly when:
" - this plugin was already loaded (or disabled)
" - when 'compatible' is set
if (exists("g:loaded_endwise") && g:loaded_endwise) || &cp
finish
endif
let g:loaded_endwise = 1
let s:cpo_save = &cpo
set cpo&vim
augroup endwise " {{{1
au!
autocmd FileType ruby
\ let b:endwise_addition = '\=submatch(0)=="{" ? "}" : "end"' |
\ let b:endwise_words = 'module,class,def,if,unless,case,while,until,begin,do' |
\ let b:endwise_pattern = '^\s*\zs\%(module\|class\|def\|if\|unless\|case\|while\|until\|for\|\|begin\)\>\%(.*[^.:@$]\<end\>\)\@!\|\<do\ze\%(\s*|.*|\)\=\s*$' |
\ let b:endwise_syngroups = 'rubyModule,rubyClass,rubyDefine,rubyControl,rubyConditional,rubyRepeat'
autocmd FileType vb,vbnet,aspvbs
\ let b:endwise_addition = 'End &' |
\ let b:endwise_words = 'Function,Sub,Class,Module,Enum,Namespace' |
\ let b:endwise_pattern = '\%(\<End\>.*\)\@<!\<&\>' |
\ let b:endwise_syngroups = 'vbStatement,vbnetStorage,vbnetProcedure,vbnet.*Words,AspVBSStatement'
autocmd FileType vim
\ let b:endwise_addition = 'end&' |
\ let b:endwise_words = 'fu\%[nction],wh\%[ile],if,for,try' |
\ let b:endwise_syngroups = 'vimFuncKey,vimNotFunc,vimCommand'
augroup END " }}}1
" Maps {{{1
if maparg("<Plug>DiscretionaryEnd") == ""
inoremap <silent> <SID>DiscretionaryEnd <C-R>=<SID>crend(0)<CR>
inoremap <silent> <SID>AlwaysEnd <C-R>=<SID>crend(1)<CR>
imap <script> <Plug>DiscretionaryEnd <SID>DiscretionaryEnd
imap <script> <Plug>AlwaysEnd <SID>AlwaysEnd
endif
if maparg('<CR>','i') =~# '<C-R>=.*crend(.)<CR>\|<\%(Plug\|SID\)>.*End'
" Already mapped
elseif maparg('<CR>','i') =~ '<CR>'
exe "imap <script> <C-X><CR> ".maparg('<CR>','i')."<SID>AlwaysEnd"
exe "imap <script> <CR> ".maparg('<CR>','i')."<SID>DiscretionaryEnd"
else
imap <C-X><CR> <CR><Plug>AlwaysEnd
imap <CR> <CR><Plug>DiscretionaryEnd
endif
if maparg('<M-o>','i') == ''
inoremap <M-o> <C-O>o
endif
" }}}1
" Code {{{1
function! s:mysearchpair(beginpat,endpat,synpat)
let g:endwise_syntaxes = ""
let s:lastline = line('.')
call s:synname()
let line = searchpair(a:beginpat,'',a:endpat,'Wn','<SID>synname() !~# "^'.substitute(a:synpat,'\\','\\\\','g').'$"',line('.')+50)
return line
endfunction
function! s:crend(always)
let n = ""
if !exists("b:endwise_addition") || !exists("b:endwise_words") || !exists("b:endwise_syngroups")
return n
end
let synpat = '\%('.substitute(b:endwise_syngroups,',','\\|','g').'\)'
let wordchoice = '\%('.substitute(b:endwise_words,',','\\|','g').'\)'
if exists("b:endwise_pattern")
let beginpat = substitute(b:endwise_pattern,'&',substitute(wordchoice,'\\','\\&','g'),'g')
else
let beginpat = '\<'.wordchoice.'\>'
endif
let lnum = line('.') - 1
let space = matchstr(getline(lnum),'^\s*')
let col = match(getline(lnum),beginpat) + 1
let word = matchstr(getline(lnum),beginpat)
let endpat = substitute(word,'.*',b:endwise_addition,'')
let y = n.endpat."\<C-O>O"
let endpat = '\<'.substitute(wordchoice,'.*',b:endwise_addition,'').'\>'
if a:always
return y
elseif col <= 0 || synIDattr(synID(lnum,col,1),'name') !~ '^'.synpat.'$'
return n
elseif getline('.') !~ '^\s*#\=$'
return n
endif
let line = s:mysearchpair(beginpat,endpat,synpat)
" even is false if no end was found, or if the end found was less
" indented than the current line
let even = strlen(matchstr(getline(line),'^\s*')) >= strlen(space)
if line == 0
let even = 0
endif
let g:endwise_debug = line . "(" . even . ")"
if !even && line == line('.') + 1
return y
endif
if even
return n
endif
return y
endfunction
function! s:synname()
" Checking this helps to force things to stay in sync
while s:lastline < line('.')
let s = synIDattr(synID(s:lastline,indent(s:lastline)+1,1),'name')
let s:lastline = nextnonblank(s:lastline + 1)
endwhile
let s = synIDattr(synID(line('.'),col('.'),1),'name')
let g:endwise_syntaxes = g:endwise_syntaxes . line('.').','.col('.')."=".s."\n"
let s:lastline = line('.')
return s
endfunction
" }}}1
let &cpo = s:cpo_save
" vim:set ft=vim ff=unix ts=8 sw=4 sts=4:

310
vim/plugin/greplace.vim Normal file
View file

@ -0,0 +1,310 @@
" File: greplace.vim
" Script to search and replace pattern across multiple files
" Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com)
" Version: 1.0 Beta1
" Last Modified: March 3, 2007
"
if exists("loaded_greplace")
finish
endif
let loaded_greplace = 1
" Requires Vim 7.0 and above
if v:version < 700
finish
endif
" Line continuation used here
let s:cpo_save = &cpo
set cpo&vim
if &isfname =~ '['
let s:gRepl_bufname = '[Global\ Replace]'
else
let s:gRepl_bufname = '\[Global\ Replace\]'
endif
" Character to use to quote patterns
if !exists("Greplace_Shell_Quote_Char")
if has("win32") || has("win16") || has("win95")
let Greplace_Shell_Quote_Char = ''
else
let Greplace_Shell_Quote_Char = "'"
endif
endif
let s:save_qf_list = {}
function! s:warn_msg(msg)
echohl WarningMsg
echomsg a:msg
echohl None
endfunction
highlight GReplaceText term=reverse cterm=reverse gui=reverse
function! s:gReplace()
if empty(s:save_qf_list)
return
endif
let change_all = v:cmdbang
let changeset = {}
" Parse the replace buffer contents and get a List of changed lines
let lines = getbufline('%', 1, '$')
for l in lines
if l !~ '[^:]\+:\d\+:.*'
continue
endif
let match_l = matchlist(l, '\([^:]\+\):\(\d\+\):\(.*\)')
let fname = match_l[1]
let lnum = match_l[2]
let text = match_l[3]
let key = fname . ':' . lnum
if s:save_qf_list[key].text == text
" This line is not changed
continue
endif
let fname = s:save_qf_list[key].fname
if !has_key(changeset, fname)
let changeset[fname] = {}
endif
let changeset[fname][lnum] = text
endfor
if empty(changeset)
" The replace buffer is not changed by the user
call s:warn_msg('Error: No changes in the replace buffer')
return
endif
" Make the changes made by the user to the buffers
for f in keys(changeset)
let f_l = changeset[f]
if !filereadable(f)
continue
endif
silent! exe 'hide edit ' . f
let change_buf_all = 0 " Accept all the changes in this buffer
for lnum in keys(f_l)
exe lnum
let cur_ltext = getline(lnum)
let new_ltext = f_l[lnum]
let s_idx =0
while cur_ltext[s_idx] == new_ltext[s_idx]
let s_idx += 1
endwhile
let e_idx1 = strlen(cur_ltext) - 1
let e_idx2 = strlen(new_ltext) - 1
while e_idx1 >= 0 && cur_ltext[e_idx1] == new_ltext[e_idx2]
let e_idx1 -= 1
let e_idx2 -= 1
endwhile
let e_idx1 += 2
if (s_idx + 1) == e_idx1
" If there is nothing to highlight, then highlight the
" last character
let e_idx1 += 1
endif
let hl_pat = '/\%'.lnum.'l\%>'.s_idx.'v.*\%<'.e_idx1.'v/'
exe '2match GReplaceText ' . hl_pat
redraw!
try
let change_line = 0
if !change_all && !change_buf_all
let new_text_frag = strpart(new_ltext, s_idx,
\ e_idx2 - s_idx + 1)
echo "Replace with '" . new_text_frag . "' (y/n/a/b/q)?"
let ans = 'x'
while ans !~? '[ynab]'
let ans = nr2char(getchar())
if ans == 'q' || ans == "\<Esc>" " Quit
return
endif
endwhile
if ans == 'a' " Accept all
let change_all = 1
endif
if ans == 'b' " Accept changes in the current buffer
let change_buf_all = 1
endif
if ans == 'y' " Yes
let change_line = 1
endif
endif
if change_all || change_buf_all || change_line
call setline(lnum, f_l[lnum])
endif
finally
2match none
endtry
endfor
endfor
endfunction
function! s:gReplace_show_matches()
let qf = getqflist()
if empty(qf)
call s:warn_msg('Error: Quickfix list is empty')
return
endif
let new_qf = {}
" Populate the buffer with the current quickfix list
let lines = []
for l in qf
if l.valid && l.lnum > 0 && l.bufnr > 0
let fname = fnamemodify(bufname(l.bufnr), ':.')
let buf_text = fname . ':' . l.lnum . ':' . l.text
let k = fname . ':' . l.lnum
let new_qf[k] = {}
let new_qf[k].fname = fnamemodify(bufname(l.bufnr), ':p')
let new_qf[k].text = l.text
else
let buf_text = l.text
endif
call add(lines, buf_text)
endfor
if empty(lines)
" No valid matching lines
return
endif
let w = bufwinnr(s:gRepl_bufname)
if w == -1
" Create a new window
silent! exe 'new ' . s:gRepl_bufname
else
exe w . 'wincmd w'
" Discard the contents of the buffer
%d _
endif
call append(0, '#')
call append(1, '# Modify the contents of this buffer and then')
call append(2, '# use the ":Greplace" command to merge the changes.')
call append(3, '#')
call append(4, lines)
call cursor(5, 1)
setlocal buftype=nofile
setlocal bufhidden=wipe
setlocal nomodified
command! -buffer -nargs=0 -bang Greplace call s:gReplace()
let s:save_qf_list = new_qf
endfunction
" gSearch
" Search for a pattern in a group of files using ':grep'
function! s:gSearch(type, ...)
let grep_opt = ''
let pattern = ''
let filenames = ''
" Parse the arguments
" grep command-line flags are specified using the "-flag" format
" the next argument is assumed to be the pattern
" and the next arguments are assumed to be filenames or file patterns
let argcnt = 1
while argcnt <= a:0
if &grepprg =~ 'findstr' && a:{argcnt} =~ '^/'
let grep_opt = grep_opt . ' ' . a:{argcnt}
elseif a:{argcnt} =~ '^-'
let grep_opt = grep_opt . ' ' . a:{argcnt}
elseif pattern == ''
let pattern = a:{argcnt}
else
let filenames = filenames . ' ' . a:{argcnt}
endif
let argcnt += 1
endwhile
" If search pattern is not specified on command-line, ask for it
if pattern == ''
let pattern = input('Search pattern: ', expand('<cword>'))
if pattern == ''
return
endif
" Quote the supplied pattern
let pattern = g:Greplace_Shell_Quote_Char . pattern .
\ g:Greplace_Shell_Quote_Char
endif
if a:type == 'grep'
if filenames == ''
let filenames = input('Search in files: ', '*', 'file')
endif
elseif a:type == 'args'
" Search in all the filenames in the argument list
let arg_cnt = argc()
if arg_cnt == 0
call s:warn_msg('Error: Argument list is empty')
return
endif
let filenames = ''
for i in range(0, arg_cnt - 1)
let filenames .= ' ' . argv(i)
endfor
else
" Get a list of all the buffer names
let filenames = ''
for i in range(1, bufnr('$'))
let bname = bufname(i)
if bufexists(i) && buflisted(i) && filereadable(bname) &&
\ getbufvar(i, '&buftype') == ''
let filenames .= ' ' . bufname(i)
endif
endfor
endif
if filenames == ''
call s:warn_msg('Error: No valid file names')
return
endif
" Use ! after grep, so that Vim doesn't automatically jump to the
" first match
let grep_cmd = 'grep! ' . grep_opt . ' ' . pattern . ' ' . filenames
" Run the grep and get the matches
exe grep_cmd
call s:gReplace_show_matches()
endfunction
command! -nargs=0 Gqfopen call s:gReplace_show_matches()
command! -nargs=* -complete=file Gsearch call s:gSearch('grep', <f-args>)
command! -nargs=* Gargsearch call s:gSearch('args', <f-args>)
command! -nargs=* Gbuffersearch call s:gSearch('buffer', <f-args>)
" restore 'cpo'
let &cpo = s:cpo_save
unlet s:cpo_save

812
vim/plugin/matchit.vim Normal file
View file

@ -0,0 +1,812 @@
" matchit.vim: (global plugin) Extended "%" matching
" Last Change: Fri Jan 25 10:00 AM 2008 EST
" Maintainer: Benji Fisher PhD <benji@member.AMS.org>
" Version: 1.13.2, for Vim 6.3+
" URL: http://www.vim.org/script.php?script_id=39
" Documentation:
" The documentation is in a separate file, matchit.txt .
" Credits:
" Vim editor by Bram Moolenaar (Thanks, Bram!)
" Original script and design by Raul Segura Acevedo
" Support for comments by Douglas Potts
" Support for back references and other improvements by Benji Fisher
" Support for many languages by Johannes Zellner
" Suggestions for improvement, bug reports, and support for additional
" languages by Jordi-Albert Batalla, Neil Bird, Servatius Brandt, Mark
" Collett, Stephen Wall, Dany St-Amant, Yuheng Xie, and Johannes Zellner.
" Debugging:
" If you'd like to try the built-in debugging commands...
" :MatchDebug to activate debugging for the current buffer
" This saves the values of several key script variables as buffer-local
" variables. See the MatchDebug() function, below, for details.
" TODO: I should think about multi-line patterns for b:match_words.
" This would require an option: how many lines to scan (default 1).
" This would be useful for Python, maybe also for *ML.
" TODO: Maybe I should add a menu so that people will actually use some of
" the features that I have implemented.
" TODO: Eliminate the MultiMatch function. Add yet another argument to
" Match_wrapper() instead.
" TODO: Allow :let b:match_words = '\(\(foo\)\(bar\)\):\3\2:end\1'
" TODO: Make backrefs safer by using '\V' (very no-magic).
" TODO: Add a level of indirection, so that custom % scripts can use my
" work but extend it.
" allow user to prevent loading
" and prevent duplicate loading
if exists("loaded_matchit") || &cp
finish
endif
let loaded_matchit = 1
let s:last_mps = ""
let s:last_words = ":"
let s:save_cpo = &cpo
set cpo&vim
nnoremap <silent> % :<C-U>call <SID>Match_wrapper('',1,'n') <CR>
nnoremap <silent> g% :<C-U>call <SID>Match_wrapper('',0,'n') <CR>
vnoremap <silent> % :<C-U>call <SID>Match_wrapper('',1,'v') <CR>m'gv``
vnoremap <silent> g% :<C-U>call <SID>Match_wrapper('',0,'v') <CR>m'gv``
onoremap <silent> % v:<C-U>call <SID>Match_wrapper('',1,'o') <CR>
onoremap <silent> g% v:<C-U>call <SID>Match_wrapper('',0,'o') <CR>
" Analogues of [{ and ]} using matching patterns:
nnoremap <silent> [% :<C-U>call <SID>MultiMatch("bW", "n") <CR>
nnoremap <silent> ]% :<C-U>call <SID>MultiMatch("W", "n") <CR>
vmap [% <Esc>[%m'gv``
vmap ]% <Esc>]%m'gv``
" vnoremap <silent> [% :<C-U>call <SID>MultiMatch("bW", "v") <CR>m'gv``
" vnoremap <silent> ]% :<C-U>call <SID>MultiMatch("W", "v") <CR>m'gv``
onoremap <silent> [% v:<C-U>call <SID>MultiMatch("bW", "o") <CR>
onoremap <silent> ]% v:<C-U>call <SID>MultiMatch("W", "o") <CR>
" text object:
vmap a% <Esc>[%v]%
" Auto-complete mappings: (not yet "ready for prime time")
" TODO Read :help write-plugin for the "right" way to let the user
" specify a key binding.
" let g:match_auto = '<C-]>'
" let g:match_autoCR = '<C-CR>'
" if exists("g:match_auto")
" execute "inoremap " . g:match_auto . ' x<Esc>"=<SID>Autocomplete()<CR>Pls'
" endif
" if exists("g:match_autoCR")
" execute "inoremap " . g:match_autoCR . ' <CR><C-R>=<SID>Autocomplete()<CR>'
" endif
" if exists("g:match_gthhoh")
" execute "inoremap " . g:match_gthhoh . ' <C-O>:call <SID>Gthhoh()<CR>'
" endif " gthhoh = "Get the heck out of here!"
let s:notslash = '\\\@<!\%(\\\\\)*'
function! s:Match_wrapper(word, forward, mode) range
" In s:CleanUp(), :execute "set" restore_options .
let restore_options = (&ic ? " " : " no") . "ignorecase"
if exists("b:match_ignorecase")
let &ignorecase = b:match_ignorecase
endif
let restore_options = " ve=" . &ve . restore_options
set ve=
" If this function was called from Visual mode, make sure that the cursor
" is at the correct end of the Visual range:
if a:mode == "v"
execute "normal! gv\<Esc>"
endif
" In s:CleanUp(), we may need to check whether the cursor moved forward.
let startline = line(".")
let startcol = col(".")
" Use default behavior if called with a count.
if v:count
exe "normal! " . v:count . "%"
return s:CleanUp(restore_options, a:mode, startline, startcol)
end
" First step: if not already done, set the script variables
" s:do_BR flag for whether there are backrefs
" s:pat parsed version of b:match_words
" s:all regexp based on s:pat and the default groups
"
if !exists("b:match_words") || b:match_words == ""
let match_words = ""
" Allow b:match_words = "GetVimMatchWords()" .
elseif b:match_words =~ ":"
let match_words = b:match_words
else
execute "let match_words =" b:match_words
endif
" Thanks to Preben "Peppe" Guldberg and Bram Moolenaar for this suggestion!
if (match_words != s:last_words) || (&mps != s:last_mps) ||
\ exists("b:match_debug")
let s:last_words = match_words
let s:last_mps = &mps
" The next several lines were here before
" BF started messing with this script.
" quote the special chars in 'matchpairs', replace [,:] with \| and then
" append the builtin pairs (/*, */, #if, #ifdef, #else, #elif, #endif)
" let default = substitute(escape(&mps, '[$^.*~\\/?]'), '[,:]\+',
" \ '\\|', 'g').'\|\/\*\|\*\/\|#if\>\|#ifdef\>\|#else\>\|#elif\>\|#endif\>'
let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") .
\ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>'
" s:all = pattern with all the keywords
let match_words = match_words . (strlen(match_words) ? "," : "") . default
if match_words !~ s:notslash . '\\\d'
let s:do_BR = 0
let s:pat = match_words
else
let s:do_BR = 1
let s:pat = s:ParseWords(match_words)
endif
let s:all = substitute(s:pat, s:notslash . '\zs[,:]\+', '\\|', 'g')
let s:all = '\%(' . s:all . '\)'
" let s:all = '\%(' . substitute(s:all, '\\\ze[,:]', '', 'g') . '\)'
if exists("b:match_debug")
let b:match_pat = s:pat
endif
endif
" Second step: set the following local variables:
" matchline = line on which the cursor started
" curcol = number of characters before match
" prefix = regexp for start of line to start of match
" suffix = regexp for end of match to end of line
" Require match to end on or after the cursor and prefer it to
" start on or before the cursor.
let matchline = getline(startline)
if a:word != ''
" word given
if a:word !~ s:all
echohl WarningMsg|echo 'Missing rule for word:"'.a:word.'"'|echohl NONE
return s:CleanUp(restore_options, a:mode, startline, startcol)
endif
let matchline = a:word
let curcol = 0
let prefix = '^\%('
let suffix = '\)$'
" Now the case when "word" is not given
else " Find the match that ends on or after the cursor and set curcol.
let regexp = s:Wholematch(matchline, s:all, startcol-1)
let curcol = match(matchline, regexp)
" If there is no match, give up.
if curcol == -1
return s:CleanUp(restore_options, a:mode, startline, startcol)
endif
let endcol = matchend(matchline, regexp)
let suf = strlen(matchline) - endcol
let prefix = (curcol ? '^.*\%' . (curcol + 1) . 'c\%(' : '^\%(')
let suffix = (suf ? '\)\%' . (endcol + 1) . 'c.*$' : '\)$')
endif
if exists("b:match_debug")
let b:match_match = matchstr(matchline, regexp)
let b:match_col = curcol+1
endif
" Third step: Find the group and single word that match, and the original
" (backref) versions of these. Then, resolve the backrefs.
" Set the following local variable:
" group = colon-separated list of patterns, one of which matches
" = ini:mid:fin or ini:fin
"
" Reconstruct the version with unresolved backrefs.
let patBR = substitute(match_words.',',
\ s:notslash.'\zs[,:]*,[,:]*', ',', 'g')
let patBR = substitute(patBR, s:notslash.'\zs:\{2,}', ':', 'g')
" Now, set group and groupBR to the matching group: 'if:endif' or
" 'while:endwhile' or whatever. A bit of a kluge: s:Choose() returns
" group . "," . groupBR, and we pick it apart.
let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
let i = matchend(group, s:notslash . ",")
let groupBR = strpart(group, i)
let group = strpart(group, 0, i-1)
" Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
if s:do_BR " Do the hard part: resolve those backrefs!
let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
endif
if exists("b:match_debug")
let b:match_wholeBR = groupBR
let i = matchend(groupBR, s:notslash . ":")
let b:match_iniBR = strpart(groupBR, 0, i-1)
endif
" Fourth step: Set the arguments for searchpair().
let i = matchend(group, s:notslash . ":")
let j = matchend(group, '.*' . s:notslash . ":")
let ini = strpart(group, 0, i-1)
let mid = substitute(strpart(group, i,j-i-1), s:notslash.'\zs:', '\\|', 'g')
let fin = strpart(group, j)
"Un-escape the remaining , and : characters.
let ini = substitute(ini, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
let mid = substitute(mid, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
let fin = substitute(fin, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
" searchpair() requires that these patterns avoid \(\) groups.
let ini = substitute(ini, s:notslash . '\zs\\(', '\\%(', 'g')
let mid = substitute(mid, s:notslash . '\zs\\(', '\\%(', 'g')
let fin = substitute(fin, s:notslash . '\zs\\(', '\\%(', 'g')
" Set mid. This is optimized for readability, not micro-efficiency!
if a:forward && matchline =~ prefix . fin . suffix
\ || !a:forward && matchline =~ prefix . ini . suffix
let mid = ""
endif
" Set flag. This is optimized for readability, not micro-efficiency!
if a:forward && matchline =~ prefix . fin . suffix
\ || !a:forward && matchline !~ prefix . ini . suffix
let flag = "bW"
else
let flag = "W"
endif
" Set skip.
if exists("b:match_skip")
let skip = b:match_skip
elseif exists("b:match_comment") " backwards compatibility and testing!
let skip = "r:" . b:match_comment
else
let skip = 's:comment\|string'
endif
let skip = s:ParseSkip(skip)
if exists("b:match_debug")
let b:match_ini = ini
let b:match_tail = (strlen(mid) ? mid.'\|' : '') . fin
endif
" Fifth step: actually start moving the cursor and call searchpair().
" Later, :execute restore_cursor to get to the original screen.
let restore_cursor = virtcol(".") . "|"
normal! g0
let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
normal! H
let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
execute restore_cursor
call cursor(0, curcol + 1)
" normal! 0
" if curcol
" execute "normal!" . curcol . "l"
" endif
if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
let skip = "0"
else
execute "if " . skip . "| let skip = '0' | endif"
endif
let sp_return = searchpair(ini, mid, fin, flag, skip)
let final_position = "call cursor(" . line(".") . "," . col(".") . ")"
" Restore cursor position and original screen.
execute restore_cursor
normal! m'
if sp_return > 0
execute final_position
endif
return s:CleanUp(restore_options, a:mode, startline, startcol, mid.'\|'.fin)
endfun
" Restore options and do some special handling for Operator-pending mode.
" The optional argument is the tail of the matching group.
fun! s:CleanUp(options, mode, startline, startcol, ...)
execute "set" a:options
" Open folds, if appropriate.
if a:mode != "o"
if &foldopen =~ "percent"
normal! zv
endif
" In Operator-pending mode, we want to include the whole match
" (for example, d%).
" This is only a problem if we end up moving in the forward direction.
elseif (a:startline < line(".")) ||
\ (a:startline == line(".") && a:startcol < col("."))
if a:0
" Check whether the match is a single character. If not, move to the
" end of the match.
let matchline = getline(".")
let currcol = col(".")
let regexp = s:Wholematch(matchline, a:1, currcol-1)
let endcol = matchend(matchline, regexp)
if endcol > currcol " This is NOT off by one!
execute "normal!" . (endcol - currcol) . "l"
endif
endif " a:0
endif " a:mode != "o" && etc.
return 0
endfun
" Example (simplified HTML patterns): if
" a:groupBR = '<\(\k\+\)>:</\1>'
" a:prefix = '^.\{3}\('
" a:group = '<\(\k\+\)>:</\(\k\+\)>'
" a:suffix = '\).\{2}$'
" a:matchline = "123<tag>12" or "123</tag>12"
" then extract "tag" from a:matchline and return "<tag>:</tag>" .
fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline)
if a:matchline !~ a:prefix .
\ substitute(a:group, s:notslash . '\zs:', '\\|', 'g') . a:suffix
return a:group
endif
let i = matchend(a:groupBR, s:notslash . ':')
let ini = strpart(a:groupBR, 0, i-1)
let tailBR = strpart(a:groupBR, i)
let word = s:Choose(a:group, a:matchline, ":", "", a:prefix, a:suffix,
\ a:groupBR)
let i = matchend(word, s:notslash . ":")
let wordBR = strpart(word, i)
let word = strpart(word, 0, i-1)
" Now, a:matchline =~ a:prefix . word . a:suffix
if wordBR != ini
let table = s:Resolve(ini, wordBR, "table")
else
" let table = "----------"
let table = ""
let d = 0
while d < 10
if tailBR =~ s:notslash . '\\' . d
" let table[d] = d
let table = table . d
else
let table = table . "-"
endif
let d = d + 1
endwhile
endif
let d = 9
while d
if table[d] != "-"
let backref = substitute(a:matchline, a:prefix.word.a:suffix,
\ '\'.table[d], "")
" Are there any other characters that should be escaped?
let backref = escape(backref, '*,:')
execute s:Ref(ini, d, "start", "len")
let ini = strpart(ini, 0, start) . backref . strpart(ini, start+len)
let tailBR = substitute(tailBR, s:notslash . '\zs\\' . d,
\ escape(backref, '\\'), 'g')
endif
let d = d-1
endwhile
if exists("b:match_debug")
if s:do_BR
let b:match_table = table
let b:match_word = word
else
let b:match_table = ""
let b:match_word = ""
endif
endif
return ini . ":" . tailBR
endfun
" Input a comma-separated list of groups with backrefs, such as
" a:groups = '\(foo\):end\1,\(bar\):end\1'
" and return a comma-separated list of groups with backrefs replaced:
" return '\(foo\):end\(foo\),\(bar\):end\(bar\)'
fun! s:ParseWords(groups)
let groups = substitute(a:groups.",", s:notslash.'\zs[,:]*,[,:]*', ',', 'g')
let groups = substitute(groups, s:notslash . '\zs:\{2,}', ':', 'g')
let parsed = ""
while groups =~ '[^,:]'
let i = matchend(groups, s:notslash . ':')
let j = matchend(groups, s:notslash . ',')
let ini = strpart(groups, 0, i-1)
let tail = strpart(groups, i, j-i-1) . ":"
let groups = strpart(groups, j)
let parsed = parsed . ini
let i = matchend(tail, s:notslash . ':')
while i != -1
" In 'if:else:endif', ini='if' and word='else' and then word='endif'.
let word = strpart(tail, 0, i-1)
let tail = strpart(tail, i)
let i = matchend(tail, s:notslash . ':')
let parsed = parsed . ":" . s:Resolve(ini, word, "word")
endwhile " Now, tail has been used up.
let parsed = parsed . ","
endwhile " groups =~ '[^,:]'
let parsed = substitute(parsed, ',$', '', '')
return parsed
endfun
" TODO I think this can be simplified and/or made more efficient.
" TODO What should I do if a:start is out of range?
" Return a regexp that matches all of a:string, such that
" matchstr(a:string, regexp) represents the match for a:pat that starts
" as close to a:start as possible, before being preferred to after, and
" ends after a:start .
" Usage:
" let regexp = s:Wholematch(getline("."), 'foo\|bar', col(".")-1)
" let i = match(getline("."), regexp)
" let j = matchend(getline("."), regexp)
" let match = matchstr(getline("."), regexp)
fun! s:Wholematch(string, pat, start)
let group = '\%(' . a:pat . '\)'
let prefix = (a:start ? '\(^.*\%<' . (a:start + 2) . 'c\)\zs' : '^')
let len = strlen(a:string)
let suffix = (a:start+1 < len ? '\(\%>'.(a:start+1).'c.*$\)\@=' : '$')
if a:string !~ prefix . group . suffix
let prefix = ''
endif
return prefix . group . suffix
endfun
" No extra arguments: s:Ref(string, d) will
" find the d'th occurrence of '\(' and return it, along with everything up
" to and including the matching '\)'.
" One argument: s:Ref(string, d, "start") returns the index of the start
" of the d'th '\(' and any other argument returns the length of the group.
" Two arguments: s:Ref(string, d, "foo", "bar") returns a string to be
" executed, having the effect of
" :let foo = s:Ref(string, d, "start")
" :let bar = s:Ref(string, d, "len")
fun! s:Ref(string, d, ...)
let len = strlen(a:string)
if a:d == 0
let start = 0
else
let cnt = a:d
let match = a:string
while cnt
let cnt = cnt - 1
let index = matchend(match, s:notslash . '\\(')
if index == -1
return ""
endif
let match = strpart(match, index)
endwhile
let start = len - strlen(match)
if a:0 == 1 && a:1 == "start"
return start - 2
endif
let cnt = 1
while cnt
let index = matchend(match, s:notslash . '\\(\|\\)') - 1
if index == -2
return ""
endif
" Increment if an open, decrement if a ')':
let cnt = cnt + (match[index]=="(" ? 1 : -1) " ')'
" let cnt = stridx('0(', match[index]) + cnt
let match = strpart(match, index+1)
endwhile
let start = start - 2
let len = len - start - strlen(match)
endif
if a:0 == 1
return len
elseif a:0 == 2
return "let " . a:1 . "=" . start . "| let " . a:2 . "=" . len
else
return strpart(a:string, start, len)
endif
endfun
" Count the number of disjoint copies of pattern in string.
" If the pattern is a literal string and contains no '0' or '1' characters
" then s:Count(string, pattern, '0', '1') should be faster than
" s:Count(string, pattern).
fun! s:Count(string, pattern, ...)
let pat = escape(a:pattern, '\\')
if a:0 > 1
let foo = substitute(a:string, '[^'.a:pattern.']', "a:1", "g")
let foo = substitute(a:string, pat, a:2, "g")
let foo = substitute(foo, '[^' . a:2 . ']', "", "g")
return strlen(foo)
endif
let result = 0
let foo = a:string
let index = matchend(foo, pat)
while index != -1
let result = result + 1
let foo = strpart(foo, index)
let index = matchend(foo, pat)
endwhile
return result
endfun
" s:Resolve('\(a\)\(b\)', '\(c\)\2\1\1\2') should return table.word, where
" word = '\(c\)\(b\)\(a\)\3\2' and table = '-32-------'. That is, the first
" '\1' in target is replaced by '\(a\)' in word, table[1] = 3, and this
" indicates that all other instances of '\1' in target are to be replaced
" by '\3'. The hard part is dealing with nesting...
" Note that ":" is an illegal character for source and target,
" unless it is preceded by "\".
fun! s:Resolve(source, target, output)
let word = a:target
let i = matchend(word, s:notslash . '\\\d') - 1
let table = "----------"
while i != -2 " There are back references to be replaced.
let d = word[i]
let backref = s:Ref(a:source, d)
" The idea is to replace '\d' with backref. Before we do this,
" replace any \(\) groups in backref with :1, :2, ... if they
" correspond to the first, second, ... group already inserted
" into backref. Later, replace :1 with \1 and so on. The group
" number w+b within backref corresponds to the group number
" s within a:source.
" w = number of '\(' in word before the current one
let w = s:Count(
\ substitute(strpart(word, 0, i-1), '\\\\', '', 'g'), '\(', '1')
let b = 1 " number of the current '\(' in backref
let s = d " number of the current '\(' in a:source
while b <= s:Count(substitute(backref, '\\\\', '', 'g'), '\(', '1')
\ && s < 10
if table[s] == "-"
if w + b < 10
" let table[s] = w + b
let table = strpart(table, 0, s) . (w+b) . strpart(table, s+1)
endif
let b = b + 1
let s = s + 1
else
execute s:Ref(backref, b, "start", "len")
let ref = strpart(backref, start, len)
let backref = strpart(backref, 0, start) . ":". table[s]
\ . strpart(backref, start+len)
let s = s + s:Count(substitute(ref, '\\\\', '', 'g'), '\(', '1')
endif
endwhile
let word = strpart(word, 0, i-1) . backref . strpart(word, i+1)
let i = matchend(word, s:notslash . '\\\d') - 1
endwhile
let word = substitute(word, s:notslash . '\zs:', '\\', 'g')
if a:output == "table"
return table
elseif a:output == "word"
return word
else
return table . word
endif
endfun
" Assume a:comma = ",". Then the format for a:patterns and a:1 is
" a:patterns = "<pat1>,<pat2>,..."
" a:1 = "<alt1>,<alt2>,..."
" If <patn> is the first pattern that matches a:string then return <patn>
" if no optional arguments are given; return <patn>,<altn> if a:1 is given.
fun! s:Choose(patterns, string, comma, branch, prefix, suffix, ...)
let tail = (a:patterns =~ a:comma."$" ? a:patterns : a:patterns . a:comma)
let i = matchend(tail, s:notslash . a:comma)
if a:0
let alttail = (a:1 =~ a:comma."$" ? a:1 : a:1 . a:comma)
let j = matchend(alttail, s:notslash . a:comma)
endif
let current = strpart(tail, 0, i-1)
if a:branch == ""
let currpat = current
else
let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g')
endif
while a:string !~ a:prefix . currpat . a:suffix
let tail = strpart(tail, i)
let i = matchend(tail, s:notslash . a:comma)
if i == -1
return -1
endif
let current = strpart(tail, 0, i-1)
if a:branch == ""
let currpat = current
else
let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g')
endif
if a:0
let alttail = strpart(alttail, j)
let j = matchend(alttail, s:notslash . a:comma)
endif
endwhile
if a:0
let current = current . a:comma . strpart(alttail, 0, j-1)
endif
return current
endfun
" Call this function to turn on debugging information. Every time the main
" script is run, buffer variables will be saved. These can be used directly
" or viewed using the menu items below.
if !exists(":MatchDebug")
command! -nargs=0 MatchDebug call s:Match_debug()
endif
fun! s:Match_debug()
let b:match_debug = 1 " Save debugging information.
" pat = all of b:match_words with backrefs parsed
amenu &Matchit.&pat :echo b:match_pat<CR>
" match = bit of text that is recognized as a match
amenu &Matchit.&match :echo b:match_match<CR>
" curcol = cursor column of the start of the matching text
amenu &Matchit.&curcol :echo b:match_col<CR>
" wholeBR = matching group, original version
amenu &Matchit.wh&oleBR :echo b:match_wholeBR<CR>
" iniBR = 'if' piece, original version
amenu &Matchit.ini&BR :echo b:match_iniBR<CR>
" ini = 'if' piece, with all backrefs resolved from match
amenu &Matchit.&ini :echo b:match_ini<CR>
" tail = 'else\|endif' piece, with all backrefs resolved from match
amenu &Matchit.&tail :echo b:match_tail<CR>
" fin = 'endif' piece, with all backrefs resolved from match
amenu &Matchit.&word :echo b:match_word<CR>
" '\'.d in ini refers to the same thing as '\'.table[d] in word.
amenu &Matchit.t&able :echo '0:' . b:match_table . ':9'<CR>
endfun
" Jump to the nearest unmatched "(" or "if" or "<tag>" if a:spflag == "bW"
" or the nearest unmatched "</tag>" or "endif" or ")" if a:spflag == "W".
" Return a "mark" for the original position, so that
" let m = MultiMatch("bW", "n") ... execute m
" will return to the original position. If there is a problem, do not
" move the cursor and return "", unless a count is given, in which case
" go up or down as many levels as possible and again return "".
" TODO This relies on the same patterns as % matching. It might be a good
" idea to give it its own matching patterns.
fun! s:MultiMatch(spflag, mode)
if !exists("b:match_words") || b:match_words == ""
return ""
end
let restore_options = (&ic ? "" : "no") . "ignorecase"
if exists("b:match_ignorecase")
let &ignorecase = b:match_ignorecase
endif
let startline = line(".")
let startcol = col(".")
" First step: if not already done, set the script variables
" s:do_BR flag for whether there are backrefs
" s:pat parsed version of b:match_words
" s:all regexp based on s:pat and the default groups
" This part is copied and slightly modified from s:Match_wrapper().
let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") .
\ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>'
" Allow b:match_words = "GetVimMatchWords()" .
if b:match_words =~ ":"
let match_words = b:match_words
else
execute "let match_words =" b:match_words
endif
if (match_words != s:last_words) || (&mps != s:last_mps) ||
\ exists("b:match_debug")
let s:last_words = match_words
let s:last_mps = &mps
if match_words !~ s:notslash . '\\\d'
let s:do_BR = 0
let s:pat = match_words
else
let s:do_BR = 1
let s:pat = s:ParseWords(match_words)
endif
let s:all = '\%(' . substitute(s:pat . (strlen(s:pat)?",":"") . default,
\ '[,:]\+','\\|','g') . '\)'
if exists("b:match_debug")
let b:match_pat = s:pat
endif
endif
" Second step: figure out the patterns for searchpair()
" and save the screen, cursor position, and 'ignorecase'.
" - TODO: A lot of this is copied from s:Match_wrapper().
" - maybe even more functionality should be split off
" - into separate functions!
let cdefault = (s:pat =~ '[^,]$' ? "," : "") . default
let open = substitute(s:pat . cdefault,
\ s:notslash . '\zs:.\{-}' . s:notslash . ',', '\\),\\(', 'g')
let open = '\(' . substitute(open, s:notslash . '\zs:.*$', '\\)', '')
let close = substitute(s:pat . cdefault,
\ s:notslash . '\zs,.\{-}' . s:notslash . ':', '\\),\\(', 'g')
let close = substitute(close, '^.\{-}' . s:notslash . ':', '\\(', '') . '\)'
if exists("b:match_skip")
let skip = b:match_skip
elseif exists("b:match_comment") " backwards compatibility and testing!
let skip = "r:" . b:match_comment
else
let skip = 's:comment\|string'
endif
let skip = s:ParseSkip(skip)
" let restore_cursor = line(".") . "G" . virtcol(".") . "|"
" normal! H
" let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
let restore_cursor = virtcol(".") . "|"
normal! g0
let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
normal! H
let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
execute restore_cursor
" Third step: call searchpair().
" Replace '\('--but not '\\('--with '\%(' and ',' with '\|'.
let openpat = substitute(open, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
let openpat = substitute(openpat, ',', '\\|', 'g')
let closepat = substitute(close, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
let closepat = substitute(closepat, ',', '\\|', 'g')
if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
let skip = '0'
else
execute "if " . skip . "| let skip = '0' | endif"
endif
mark '
let level = v:count1
while level
if searchpair(openpat, '', closepat, a:spflag, skip) < 1
call s:CleanUp(restore_options, a:mode, startline, startcol)
return ""
endif
let level = level - 1
endwhile
" Restore options and return a string to restore the original position.
call s:CleanUp(restore_options, a:mode, startline, startcol)
return restore_cursor
endfun
" Search backwards for "if" or "while" or "<tag>" or ...
" and return "endif" or "endwhile" or "</tag>" or ... .
" For now, this uses b:match_words and the same script variables
" as s:Match_wrapper() . Later, it may get its own patterns,
" either from a buffer variable or passed as arguments.
" fun! s:Autocomplete()
" echo "autocomplete not yet implemented :-("
" if !exists("b:match_words") || b:match_words == ""
" return ""
" end
" let startpos = s:MultiMatch("bW")
"
" if startpos == ""
" return ""
" endif
" " - TODO: figure out whether 'if' or '<tag>' matched, and construct
" " - the appropriate closing.
" let matchline = getline(".")
" let curcol = col(".") - 1
" " - TODO: Change the s:all argument if there is a new set of match pats.
" let regexp = s:Wholematch(matchline, s:all, curcol)
" let suf = strlen(matchline) - matchend(matchline, regexp)
" let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(')
" let suffix = (suf ? '\).\{' . suf . '}$' : '\)$')
" " Reconstruct the version with unresolved backrefs.
" let patBR = substitute(b:match_words.',', '[,:]*,[,:]*', ',', 'g')
" let patBR = substitute(patBR, ':\{2,}', ':', "g")
" " Now, set group and groupBR to the matching group: 'if:endif' or
" " 'while:endwhile' or whatever.
" let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
" let i = matchend(group, s:notslash . ",")
" let groupBR = strpart(group, i)
" let group = strpart(group, 0, i-1)
" " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
" if s:do_BR
" let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
" endif
" " let g:group = group
"
" " - TODO: Construct the closing from group.
" let fake = "end" . expand("<cword>")
" execute startpos
" return fake
" endfun
" Close all open structures. "Get the heck out of here!"
" fun! s:Gthhoh()
" let close = s:Autocomplete()
" while strlen(close)
" put=close
" let close = s:Autocomplete()
" endwhile
" endfun
" Parse special strings as typical skip arguments for searchpair():
" s:foo becomes (current syntax item) =~ foo
" S:foo becomes (current syntax item) !~ foo
" r:foo becomes (line before cursor) =~ foo
" R:foo becomes (line before cursor) !~ foo
fun! s:ParseSkip(str)
let skip = a:str
if skip[1] == ":"
if skip[0] == "s"
let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" .
\ strpart(skip,2) . "'"
elseif skip[0] == "S"
let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" .
\ strpart(skip,2) . "'"
elseif skip[0] == "r"
let skip = "strpart(getline('.'),0,col('.'))=~'" . strpart(skip,2). "'"
elseif skip[0] == "R"
let skip = "strpart(getline('.'),0,col('.'))!~'" . strpart(skip,2). "'"
endif
endif
return skip
endfun
let &cpo = s:save_cpo
" vim:sts=2:sw=2:

314
vim/plugin/rails.vim Normal file
View file

@ -0,0 +1,314 @@
" rails.vim - Detect a rails application
" Author: Tim Pope <vimNOSPAM@tpope.info>
" GetLatestVimScripts: 1567 1 :AutoInstall: rails.vim
" URL: http://rails.vim.tpope.net/
" Install this file as plugin/rails.vim. See doc/rails.txt for details. (Grab
" it from the URL above if you don't have it.) To access it from Vim, see
" :help add-local-help (hint: :helptags ~/.vim/doc) Afterwards, you should be
" able to do :help rails
" ============================================================================
" Exit quickly when:
" - this plugin was already loaded (or disabled)
" - when 'compatible' is set
if &cp || (exists("g:loaded_rails") && g:loaded_rails) && !(exists("g:rails_debug") && g:rails_debug)
finish
endif
let g:loaded_rails = 1
" Utility Functions {{{1
function! s:error(str)
echohl ErrorMsg
echomsg a:str
echohl None
let v:errmsg = a:str
endfunction
function! s:autoload(...)
if !exists("g:autoloaded_rails") && v:version >= 700
runtime! autoload/rails.vim
endif
if exists("g:autoloaded_rails")
if a:0
exe a:1
endif
return 1
endif
if !exists("g:rails_no_autoload_warning")
let g:rails_no_autoload_warning = 1
if v:version >= 700
call s:error("Disabling rails.vim: autoload/rails.vim is missing")
else
call s:error("Disabling rails.vim: Vim version 7 or higher required")
endif
endif
return ""
endfunction
" }}}1
" Configuration {{{
function! s:SetOptDefault(opt,val)
if !exists("g:".a:opt)
let g:{a:opt} = a:val
endif
endfunction
call s:SetOptDefault("rails_statusline",1)
call s:SetOptDefault("rails_syntax",1)
call s:SetOptDefault("rails_mappings",1)
call s:SetOptDefault("rails_abbreviations",1)
call s:SetOptDefault("rails_ctags_arguments","--exclude=\"*.js\"")
call s:SetOptDefault("rails_expensive",1)
call s:SetOptDefault("rails_dbext",g:rails_expensive)
call s:SetOptDefault("rails_default_file","README")
call s:SetOptDefault("rails_default_database","")
call s:SetOptDefault("rails_root_url",'http://localhost:3000/')
call s:SetOptDefault("rails_modelines",0)
call s:SetOptDefault("rails_menu",1)
call s:SetOptDefault("rails_gnu_screen",1)
call s:SetOptDefault("rails_history_size",5)
call s:SetOptDefault("rails_generators","controller\nintegration_test\nmailer\nmigration\nmodel\nobserver\nplugin\nresource\nscaffold\nsession_migration")
if g:rails_dbext
if exists("g:loaded_dbext") && executable("sqlite3") && ! executable("sqlite")
" Since dbext can't find it by itself
call s:SetOptDefault("dbext_default_SQLITE_bin","sqlite3")
endif
endif
" }}}1
" Detection {{{1
function! s:escvar(r)
let r = fnamemodify(a:r,':~')
let r = substitute(r,'\W','\="_".char2nr(submatch(0))."_"','g')
let r = substitute(r,'^\d','_&','')
return r
endfunction
function! s:Detect(filename)
let fn = substitute(fnamemodify(a:filename,":p"),'\c^file://','','')
let sep = matchstr(fn,'^[^\\/]\{3,\}\zs[\\/]')
if sep != ""
let fn = getcwd().sep.fn
endif
if fn =~ '[\/]config[\/]environment\.rb$'
return s:BufInit(strpart(fn,0,strlen(fn)-22))
endif
if isdirectory(fn)
let fn = fnamemodify(fn,':s?[\/]$??')
else
let fn = fnamemodify(fn,':s?\(.*\)[\/][^\/]*$?\1?')
endif
let ofn = ""
let nfn = fn
while nfn != ofn && nfn != ""
if exists("s:_".s:escvar(nfn))
return s:BufInit(nfn)
endif
let ofn = nfn
let nfn = fnamemodify(nfn,':h')
endwhile
let ofn = ""
while fn != ofn
if filereadable(fn . "/config/environment.rb")
return s:BufInit(fn)
endif
let ofn = fn
let fn = fnamemodify(ofn,':s?\(.*\)[\/]\(app\|config\|db\|doc\|features\|lib\|log\|public\|script\|spec\|stories\|test\|tmp\|vendor\)\($\|[\/].*$\)?\1?')
endwhile
return 0
endfunction
function! s:BufInit(path)
let s:_{s:escvar(a:path)} = 1
if s:autoload()
return RailsBufInit(a:path)
endif
endfunction
" }}}1
" Initialization {{{1
augroup railsPluginDetect
autocmd!
autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand("<afile>:p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif
augroup END
command! -bar -bang -nargs=* -complete=dir Rails :if s:autoload()|call rails#new_app_command(<bang>0,<f-args>)|endif
" }}}1
" Menus {{{1
if !(g:rails_menu && has("menu"))
finish
endif
function! s:sub(str,pat,rep)
return substitute(a:str,'\v\C'.a:pat,a:rep,'')
endfunction
function! s:gsub(str,pat,rep)
return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
endfunction
function! s:menucmd(priority)
return 'anoremenu <script> '.(exists("$CREAM") ? 87 : '').s:gsub(g:rails_installed_menu,'[^.]','').'.'.a:priority.' '
endfunction
function! s:CreateMenus() abort
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
exe "aunmenu ".s:gsub(g:rails_installed_menu,'\&','')
unlet g:rails_installed_menu
endif
if has("menu") && (exists("g:did_install_default_menus") || exists("$CREAM")) && g:rails_menu
if g:rails_menu > 1
let g:rails_installed_menu = '&Rails'
else
let g:rails_installed_menu = '&Plugin.&Rails'
endif
let dots = s:gsub(g:rails_installed_menu,'[^.]','')
let menucmd = s:menucmd(200)
if exists("$CREAM")
exe menucmd.g:rails_installed_menu.'.-PSep- :'
exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ Alt+] :R<CR>'
exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ Alt+[ :A<CR>'
exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ Ctrl+Enter :Rfind<CR>'
else
exe menucmd.g:rails_installed_menu.'.-PSep- :'
exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ ]f :R<CR>'
exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ [f :A<CR>'
exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ gf :Rfind<CR>'
endif
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Controller :find app/controllers/application.rb<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Helper :find app/helpers/application_helper.rb<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Javascript :find public/javascripts/application.js<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Layout :Rlayout application<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &README :find doc/README_FOR_APP<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Environment :find config/environment.rb<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Database\ Configuration :find config/database.yml<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.Database\ &Schema :Rmigration 0<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.R&outes :find config/routes.rb<CR>'
exe menucmd.g:rails_installed_menu.'.&Other\ files.&Test\ Helper :find test/test_helper.rb<CR>'
exe menucmd.g:rails_installed_menu.'.-FSep- :'
exe menucmd.g:rails_installed_menu.'.Ra&ke\ :Rake :Rake<CR>'
let menucmd = substitute(menucmd,'200 $','500 ','')
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Start\ :Rserver :Rserver<CR>'
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Force\ start\ :Rserver! :Rserver!<CR>'
exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Kill\ :Rserver!\ - :Rserver! -<CR>'
exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.&Evaluate\ Ruby\.\.\.\ :Rp :call <SID>menuprompt("Rp","Code to execute and output: ")<CR>'
exe menucmd.g:rails_installed_menu.'.&Console\ :Rscript :Rscript console<CR>'
exe menucmd.g:rails_installed_menu.'.&Preview\ :Rpreview :Rpreview<CR>'
exe menucmd.g:rails_installed_menu.'.&Log\ file\ :Rlog :Rlog<CR>'
exe substitute(s:sub(menucmd,'anoremenu','vnoremenu'),'<script>','<script> <silent>','').g:rails_installed_menu.'.E&xtract\ as\ partial\ :Rextract :call <SID>menuprompt("'."'".'<,'."'".'>Rextract","Partial name (e.g., template or /controller/template): ")<CR>'
exe menucmd.g:rails_installed_menu.'.&Migration\ writer\ :Rinvert :Rinvert<CR>'
exe menucmd.' '.g:rails_installed_menu.'.-HSep- :'
exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.&Help\ :help\ rails :if <SID>autoload()<Bar>exe RailsHelpCommand("")<Bar>endif<CR>'
exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.Abo&ut\ :if <SID>autoload()<Bar>exe RailsHelpCommand("about")<Bar>endif<CR>'
let g:rails_did_menus = 1
call s:ProjectMenu()
call s:menuBufLeave()
if exists("b:rails_root")
call s:menuBufEnter()
endif
endif
endfunction
function! s:ProjectMenu()
if exists("g:rails_did_menus") && g:rails_history_size > 0
if !exists("g:RAILS_HISTORY")
let g:RAILS_HISTORY = ""
endif
let history = g:RAILS_HISTORY
let menu = s:gsub(g:rails_installed_menu,'\&','')
silent! exe "aunmenu <script> ".menu.".Projects"
let dots = s:gsub(menu,'[^.]','')
exe 'anoremenu <script> <silent> '.(exists("$CREAM") ? '87' : '').dots.'.100 '.menu.'.Pro&jects.&New\.\.\.\ :Rails :call <SID>menuprompt("Rails","New application path and additional arguments: ")<CR>'
exe 'anoremenu <script> '.menu.'.Pro&jects.-FSep- :'
while history =~ '\n'
let proj = matchstr(history,'^.\{-\}\ze\n')
let history = s:sub(history,'^.{-}\n','')
exe 'anoremenu <script> '.menu.'.Pro&jects.'.s:gsub(proj,'[.\\ ]','\\&').' :e '.s:gsub(proj."/".g:rails_default_file,'[ !%#]','\\&')."<CR>"
endwhile
endif
endfunction
function! s:menuBufEnter()
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
let menu = s:gsub(g:rails_installed_menu,'\&','')
exe 'amenu enable '.menu.'.*'
if RailsFileType() !~ '^view\>'
exe 'vmenu disable '.menu.'.Extract\ as\ partial'
endif
if RailsFileType() !~ '^\%(db-\)\=migration$' || RailsFilePath() =~ '\<db/schema\.rb$'
exe 'amenu disable '.menu.'.Migration\ writer'
endif
call s:ProjectMenu()
silent! exe 'aunmenu '.menu.'.Rake\ tasks'
silent! exe 'aunmenu '.menu.'.Generate'
silent! exe 'aunmenu '.menu.'.Destroy'
if rails#app().cache.needs('rake_tasks') || empty(rails#app().rake_tasks())
exe substitute(s:menucmd(300),'<script>','<script> <silent>','').g:rails_installed_menu.'.Rake\ &tasks\ :Rake.Fill\ this\ menu :call rails#app().rake_tasks()<Bar>call <SID>menuBufLeave()<Bar>call <SID>menuBufEnter()<CR>'
else
let i = 0
while i < len(rails#app().rake_tasks())
let task = rails#app().rake_tasks()[i]
exe s:menucmd(300).g:rails_installed_menu.'.Rake\ &tasks\ :Rake.'.s:sub(task,':',':.').' :Rake '.task.'<CR>'
let i += 1
endwhile
endif
let i = 0
let menucmd = substitute(s:menucmd(400),'<script>','<script> <silent>','').g:rails_installed_menu
while i < len(rails#app().generators())
let generator = rails#app().generators()[i]
exe menucmd.'.&Generate\ :Rgen.'.s:gsub(generator,'_','\\ ').' :call <SID>menuprompt("Rgenerate '.generator.'","Arguments for script/generate '.generator.': ")<CR>'
exe menucmd.'.&Destroy\ :Rdestroy.'.s:gsub(generator,'_','\\ ').' :call <SID>menuprompt("Rdestroy '.generator.'","Arguments for script/destroy '.generator.': ")<CR>'
let i += 1
endwhile
endif
endfunction
function! s:menuBufLeave()
if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
let menu = s:gsub(g:rails_installed_menu,'\&','')
exe 'amenu disable '.menu.'.*'
exe 'amenu enable '.menu.'.Help\ '
exe 'amenu enable '.menu.'.About\ '
exe 'amenu enable '.menu.'.Projects'
silent! exe 'aunmenu '.menu.'.Rake\ tasks'
silent! exe 'aunmenu '.menu.'.Generate'
silent! exe 'aunmenu '.menu.'.Destroy'
exe s:menucmd(300).g:rails_installed_menu.'.Rake\ tasks\ :Rake.-TSep- :'
exe s:menucmd(400).g:rails_installed_menu.'.&Generate\ :Rgen.-GSep- :'
exe s:menucmd(400).g:rails_installed_menu.'.&Destroy\ :Rdestroy.-DSep- :'
endif
endfunction
function! s:menuprompt(vimcmd,prompt)
let res = inputdialog(a:prompt,'','!!!')
if res == '!!!'
return ""
endif
exe a:vimcmd." ".res
endfunction
call s:CreateMenus()
augroup railsPluginMenu
autocmd!
autocmd User BufEnterRails call s:menuBufEnter()
autocmd User BufLeaveRails call s:menuBufLeave()
" g:RAILS_HISTORY hasn't been set when s:InitPlugin() is called.
autocmd VimEnter * call s:ProjectMenu()
augroup END
" }}}1
" vim:set sw=2 sts=2:

628
vim/plugin/surround.vim Normal file
View file

@ -0,0 +1,628 @@
" surround.vim - Surroundings
" Author: Tim Pope <vimNOSPAM@tpope.info>
" GetLatestVimScripts: 1697 1 :AutoInstall: surround.vim
" $Id: surround.vim,v 1.34 2008-02-15 21:43:42 tpope Exp $
"
" See surround.txt for help. This can be accessed by doing
"
" :helptags ~/.vim/doc
" :help surround
"
" Licensed under the same terms as Vim itself.
" ============================================================================
" Exit quickly when:
" - this plugin was already loaded or disabled
" - when 'compatible' is set
if (exists("g:loaded_surround") && g:loaded_surround) || &cp
finish
endif
let g:loaded_surround = 1
let s:cpo_save = &cpo
set cpo&vim
" Input functions {{{1
function! s:getchar()
let c = getchar()
if c =~ '^\d\+$'
let c = nr2char(c)
endif
return c
endfunction
function! s:inputtarget()
let c = s:getchar()
while c =~ '^\d\+$'
let c = c . s:getchar()
endwhile
if c == " "
let c = c . s:getchar()
endif
if c =~ "\<Esc>\|\<C-C>\|\0"
return ""
else
return c
endif
endfunction
function! s:inputreplacement()
"echo '-- SURROUND --'
let c = s:getchar()
if c == " "
let c = c . s:getchar()
endif
if c =~ "\<Esc>" || c =~ "\<C-C>"
return ""
else
return c
endif
endfunction
function! s:beep()
exe "norm! \<Esc>"
return ""
endfunction
function! s:redraw()
redraw
return ""
endfunction
" }}}1
" Wrapping functions {{{1
function! s:extractbefore(str)
if a:str =~ '\r'
return matchstr(a:str,'.*\ze\r')
else
return matchstr(a:str,'.*\ze\n')
endif
endfunction
function! s:extractafter(str)
if a:str =~ '\r'
return matchstr(a:str,'\r\zs.*')
else
return matchstr(a:str,'\n\zs.*')
endif
endfunction
function! s:repeat(str,count)
let cnt = a:count
let str = ""
while cnt > 0
let str = str . a:str
let cnt = cnt - 1
endwhile
return str
endfunction
function! s:fixindent(str,spc)
let str = substitute(a:str,'\t',s:repeat(' ',&sw),'g')
let spc = substitute(a:spc,'\t',s:repeat(' ',&sw),'g')
let str = substitute(str,'\(\n\|\%^\).\@=','\1'.spc,'g')
if ! &et
let str = substitute(str,'\s\{'.&ts.'\}',"\t",'g')
endif
return str
endfunction
function! s:process(string)
let i = 0
while i < 7
let i = i + 1
let repl_{i} = ''
let m = matchstr(a:string,nr2char(i).'.\{-\}\ze'.nr2char(i))
if m != ''
let m = substitute(strpart(m,1),'\r.*','','')
let repl_{i} = input(substitute(m,':\s*$','','').': ')
endif
endwhile
let s = ""
let i = 0
while i < strlen(a:string)
let char = strpart(a:string,i,1)
if char2nr(char) < 8
let next = stridx(a:string,char,i+1)
if next == -1
let s = s . char
else
let insertion = repl_{char2nr(char)}
let subs = strpart(a:string,i+1,next-i-1)
let subs = matchstr(subs,'\r.*')
while subs =~ '^\r.*\r'
let sub = matchstr(subs,"^\r\\zs[^\r]*\r[^\r]*")
let subs = strpart(subs,strlen(sub)+1)
let r = stridx(sub,"\r")
let insertion = substitute(insertion,strpart(sub,0,r),strpart(sub,r+1),'')
endwhile
let s = s . insertion
let i = next
endif
else
let s = s . char
endif
let i = i + 1
endwhile
return s
endfunction
function! s:wrap(string,char,type,...)
let keeper = a:string
let newchar = a:char
let type = a:type
let linemode = type ==# 'V' ? 1 : 0
let special = a:0 ? a:1 : 0
let before = ""
let after = ""
if type == "V"
let initspaces = matchstr(keeper,'\%^\s*')
else
let initspaces = matchstr(getline('.'),'\%^\s*')
endif
" Duplicate b's are just placeholders (removed)
let pairs = "b()B{}r[]a<>"
let extraspace = ""
if newchar =~ '^ '
let newchar = strpart(newchar,1)
let extraspace = ' '
endif
let idx = stridx(pairs,newchar)
if newchar == ' '
let before = ''
let after = ''
elseif exists("b:surround_".char2nr(newchar))
let all = s:process(b:surround_{char2nr(newchar)})
let before = s:extractbefore(all)
let after = s:extractafter(all)
elseif exists("g:surround_".char2nr(newchar))
let all = s:process(g:surround_{char2nr(newchar)})
let before = s:extractbefore(all)
let after = s:extractafter(all)
elseif newchar ==# "p"
let before = "\n"
let after = "\n\n"
elseif newchar =~# "[tT\<C-T><,]"
let dounmapp = 0
let dounmapb = 0
if !maparg(">","c")
let dounmapb= 1
" Hide from AsNeeded
exe "cn"."oremap > <CR>"
exe "cn"."oremap % %<C-V>"
"cm ap > <C-R>=getcmdline() =~ '^[^%?].*[%?]$' ? "\026\076" : "\026\076\015"<CR>
endif
let default = ""
if !maparg("%","c")
" This is to help when typing things like
" <a href="/images/<%= @image.filename %>">
" The downside is it breaks backspace, so lets disable it for now
"let dounmapp= 1
"exe "cn"."oremap % %<C-V>"
endif
if newchar ==# "T"
if !exists("s:lastdel")
let s:lastdel = ""
endif
let default = matchstr(s:lastdel,'<\zs.\{-\}\ze>')
endif
let tag = input("<",default)
echo "<".substitute(tag,'>*$','>','')
"if dounmapr
"silent! cunmap <CR>
"endif
if dounmapb
silent! cunmap >
endif
if dounmapp
silent! cunmap %
endif
if tag != ""
let tag = substitute(tag,'>*$','','')
let before = '<'.tag.'>'
if tag =~ '/$'
let after = ''
else
let after = '</'.substitute(tag,' .*','','').'>'
endif
if newchar == "\<C-T>" || newchar == ","
if type ==# "v" || type ==# "V"
let before = before . "\n\t"
endif
if type ==# "v"
let after = "\n". after
endif
endif
endif
elseif newchar ==# 'l' || newchar == '\'
" LaTeX
let env = input('\begin{')
let env = '{' . env
let env = env . s:closematch(env)
echo '\begin'.env
if env != ""
let before = '\begin'.env
let after = '\end'.matchstr(env,'[^}]*').'}'
endif
"if type ==# 'v' || type ==# 'V'
"let before = before ."\n\t"
"endif
"if type ==# 'v'
"let after = "\n".initspaces.after
"endif
elseif newchar ==# 'f' || newchar ==# 'F'
let fnc = input('function: ')
if fnc != ""
let before = substitute(fnc,'($','','').'('
let after = ')'
if newchar ==# 'F'
let before = before . ' '
let after = ' ' . after
endif
endif
elseif idx >= 0
let spc = (idx % 3) == 1 ? " " : ""
let idx = idx / 3 * 3
let before = strpart(pairs,idx+1,1) . spc
let after = spc . strpart(pairs,idx+2,1)
elseif newchar == "\<C-[>" || newchar == "\<C-]>"
let before = "{\n\t"
let after = "\n}"
elseif newchar !~ '\a'
let before = newchar
let after = newchar
else
let before = ''
let after = ''
endif
"let before = substitute(before,'\n','\n'.initspaces,'g')
let after = substitute(after ,'\n','\n'.initspaces,'g')
"let after = substitute(after,"\n\\s*\<C-U>\\s*",'\n','g')
if type ==# 'V' || (special && type ==# "v")
let before = substitute(before,' \+$','','')
let after = substitute(after ,'^ \+','','')
if after !~ '^\n'
let after = initspaces.after
endif
if keeper !~ '\n$' && after !~ '^\n'
let keeper = keeper . "\n"
elseif keeper =~ '\n$' && after =~ '^\n'
let after = strpart(after,1)
endif
if before !~ '\n\s*$'
let before = before . "\n"
if special
let before = before . "\t"
endif
endif
endif
if type ==# 'V'
let before = initspaces.before
endif
if before =~ '\n\s*\%$'
if type ==# 'v'
let keeper = initspaces.keeper
endif
let padding = matchstr(before,'\n\zs\s\+\%$')
let before = substitute(before,'\n\s\+\%$','\n','')
let keeper = s:fixindent(keeper,padding)
endif
if type ==# 'V'
let keeper = before.keeper.after
elseif type =~ "^\<C-V>"
" Really we should be iterating over the buffer
let repl = substitute(before,'[\\~]','\\&','g').'\1'.substitute(after,'[\\~]','\\&','g')
let repl = substitute(repl,'\n',' ','g')
let keeper = substitute(keeper."\n",'\(.\{-\}\)\('.(special ? '\s\{-\}' : '').'\n\)',repl.'\n','g')
let keeper = substitute(keeper,'\n\%$','','')
else
let keeper = before.extraspace.keeper.extraspace.after
endif
return keeper
endfunction
function! s:wrapreg(reg,char,...)
let orig = getreg(a:reg)
let type = substitute(getregtype(a:reg),'\d\+$','','')
let special = a:0 ? a:1 : 0
let new = s:wrap(orig,a:char,type,special)
call setreg(a:reg,new,type)
endfunction
" }}}1
function! s:insert(...) " {{{1
" Optional argument causes the result to appear on 3 lines, not 1
"call inputsave()
let linemode = a:0 ? a:1 : 0
let char = s:inputreplacement()
while char == "\<CR>" || char == "\<C-S>"
" TODO: use total count for additional blank lines
let linemode = linemode + 1
let char = s:inputreplacement()
endwhile
"call inputrestore()
if char == ""
return ""
endif
"call inputsave()
let cb_save = &clipboard
let reg_save = @@
call setreg('"',"\r",'v')
call s:wrapreg('"',char,linemode)
" If line mode is used and the surrounding consists solely of a suffix,
" remove the initial newline. This fits a use case of mine but is a
" little inconsistent. Is there anyone that would prefer the simpler
" behavior of just inserting the newline?
if linemode && match(getreg('"'),'^\n\s*\zs.*') == 0
call setreg('"',matchstr(getreg('"'),'^\n\s*\zs.*'),getregtype('"'))
endif
" This can be used to append a placeholder to the end
if exists("g:surround_insert_tail")
call setreg('"',g:surround_insert_tail,"a".getregtype('"'))
endif
"if linemode
"call setreg('"',substitute(getreg('"'),'^\s\+','',''),'c')
"endif
if col('.') >= col('$')
norm! ""p
else
norm! ""P
endif
if linemode
call s:reindent()
endif
norm! `]
call search('\r','bW')
let @@ = reg_save
let &clipboard = cb_save
return "\<Del>"
endfunction " }}}1
function! s:reindent() " {{{1
if exists("b:surround_indent") ? b:surround_indent : (exists("g:surround_indent") && g:surround_indent)
silent norm! '[=']
endif
endfunction " }}}1
function! s:dosurround(...) " {{{1
let scount = v:count1
let char = (a:0 ? a:1 : s:inputtarget())
let spc = ""
if char =~ '^\d\+'
let scount = scount * matchstr(char,'^\d\+')
let char = substitute(char,'^\d\+','','')
endif
if char =~ '^ '
let char = strpart(char,1)
let spc = 1
endif
if char == 'a'
let char = '>'
endif
if char == 'r'
let char = ']'
endif
let newchar = ""
if a:0 > 1
let newchar = a:2
if newchar == "\<Esc>" || newchar == "\<C-C>" || newchar == ""
return s:beep()
endif
endif
let cb_save = &clipboard
set clipboard-=unnamed
let append = ""
let original = getreg('"')
let otype = getregtype('"')
call setreg('"',"")
let strcount = (scount == 1 ? "" : scount)
if char == '/'
exe 'norm '.strcount.'[/d'.strcount.']/'
else
exe 'norm d'.strcount.'i'.char
endif
let keeper = getreg('"')
let okeeper = keeper " for reindent below
if keeper == ""
call setreg('"',original,otype)
let &clipboard = cb_save
return ""
endif
let oldline = getline('.')
let oldlnum = line('.')
if char ==# "p"
call setreg('"','','V')
elseif char ==# "s" || char ==# "w" || char ==# "W"
" Do nothing
call setreg('"','')
elseif char =~ "[\"'`]"
exe "norm! i \<Esc>d2i".char
call setreg('"',substitute(getreg('"'),' ','',''))
elseif char == '/'
norm! "_x
call setreg('"','/**/',"c")
let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
else
" One character backwards
call search('.','bW')
exe "norm da".char
endif
let removed = getreg('"')
let rem2 = substitute(removed,'\n.*','','')
let oldhead = strpart(oldline,0,strlen(oldline)-strlen(rem2))
let oldtail = strpart(oldline, strlen(oldline)-strlen(rem2))
let regtype = getregtype('"')
if char =~# '[\[({<T]' || spc
let keeper = substitute(keeper,'^\s\+','','')
let keeper = substitute(keeper,'\s\+$','','')
endif
if col("']") == col("$") && col('.') + 1 == col('$')
if oldhead =~# '^\s*$' && a:0 < 2
let keeper = substitute(keeper,'\%^\n'.oldhead.'\(\s*.\{-\}\)\n\s*\%$','\1','')
endif
let pcmd = "p"
else
let pcmd = "P"
endif
if line('.') < oldlnum && regtype ==# "V"
let pcmd = "p"
endif
call setreg('"',keeper,regtype)
if newchar != ""
call s:wrapreg('"',newchar)
endif
silent exe 'norm! ""'.pcmd.'`['
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
call s:reindent()
endif
if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
silent norm! cc
endif
call setreg('"',removed,regtype)
let s:lastdel = removed
let &clipboard = cb_save
if newchar == ""
silent! call repeat#set("\<Plug>Dsurround".char,scount)
else
silent! call repeat#set("\<Plug>Csurround".char.newchar,scount)
endif
endfunction " }}}1
function! s:changesurround() " {{{1
let a = s:inputtarget()
if a == ""
return s:beep()
endif
let b = s:inputreplacement()
if b == ""
return s:beep()
endif
call s:dosurround(a,b)
endfunction " }}}1
function! s:opfunc(type,...) " {{{1
let char = s:inputreplacement()
if char == ""
return s:beep()
endif
let reg = '"'
let sel_save = &selection
let &selection = "inclusive"
let cb_save = &clipboard
set clipboard-=unnamed
let reg_save = getreg(reg)
let reg_type = getregtype(reg)
"call setreg(reg,"\n","c")
let type = a:type
if a:type == "char"
silent exe 'norm! v`[o`]"'.reg.'y'
let type = 'v'
elseif a:type == "line"
silent exe 'norm! `[V`]"'.reg.'y'
let type = 'V'
elseif a:type ==# "v" || a:type ==# "V" || a:type ==# "\<C-V>"
silent exe 'norm! gv"'.reg.'y'
elseif a:type =~ '^\d\+$'
let type = 'v'
silent exe 'norm! ^v'.a:type.'$h"'.reg.'y'
if mode() == 'v'
norm! v
return s:beep()
endif
else
let &selection = sel_save
let &clipboard = cb_save
return s:beep()
endif
let keeper = getreg(reg)
if type == "v" && a:type != "v"
let append = matchstr(keeper,'\_s\@<!\s*$')
let keeper = substitute(keeper,'\_s\@<!\s*$','','')
endif
call setreg(reg,keeper,type)
call s:wrapreg(reg,char,a:0)
if type == "v" && a:type != "v" && append != ""
call setreg(reg,append,"ac")
endif
silent exe 'norm! gv'.(reg == '"' ? '' : '"' . reg).'p`['
if type == 'V' || (getreg(reg) =~ '\n' && type == 'v')
call s:reindent()
endif
call setreg(reg,reg_save,reg_type)
let &selection = sel_save
let &clipboard = cb_save
if a:type =~ '^\d\+$'
silent! call repeat#set("\<Plug>Y".(a:0 ? "S" : "s")."surround".char,a:type)
endif
endfunction
function! s:opfunc2(arg)
call s:opfunc(a:arg,1)
endfunction " }}}1
function! s:closematch(str) " {{{1
" Close an open (, {, [, or < on the command line.
let tail = matchstr(a:str,'.[^\[\](){}<>]*$')
if tail =~ '^\[.\+'
return "]"
elseif tail =~ '^(.\+'
return ")"
elseif tail =~ '^{.\+'
return "}"
elseif tail =~ '^<.+'
return ">"
else
return ""
endif
endfunction " }}}1
nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR>
nnoremap <silent> <Plug>Yssurround :<C-U>call <SID>opfunc(v:count1)<CR>
nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR>
" <C-U> discards the numerical argument but there's not much we can do with it
nnoremap <silent> <Plug>Ysurround :<C-U>set opfunc=<SID>opfunc<CR>g@
nnoremap <silent> <Plug>YSurround :<C-U>set opfunc=<SID>opfunc2<CR>g@
vnoremap <silent> <Plug>Vsurround :<C-U>call <SID>opfunc(visualmode())<CR>
vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc2(visualmode())<CR>
inoremap <silent> <Plug>Isurround <C-R>=<SID>insert()<CR>
inoremap <silent> <Plug>ISurround <C-R>=<SID>insert(1)<CR>
if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
nmap ds <Plug>Dsurround
nmap cs <Plug>Csurround
nmap ys <Plug>Ysurround
nmap yS <Plug>YSurround
nmap yss <Plug>Yssurround
nmap ySs <Plug>YSsurround
nmap ySS <Plug>YSsurround
if !hasmapto("<Plug>Vsurround","v")
if exists(":xmap")
xmap s <Plug>Vsurround
else
vmap s <Plug>Vsurround
endif
endif
if !hasmapto("<Plug>VSurround","v")
if exists(":xmap")
xmap S <Plug>VSurround
else
vmap S <Plug>VSurround
endif
endif
if !hasmapto("<Plug>Isurround","i") && "" == mapcheck("<C-S>","i")
imap <C-S> <Plug>Isurround
endif
imap <C-G>s <Plug>Isurround
imap <C-G>S <Plug>ISurround
"Implemented internally instead
"imap <C-S><C-S> <Plug>ISurround
endif
let &cpo = s:cpo_save
" vim:set ft=vim sw=4 sts=4 et:

849
vim/plugin/tComment.vim Normal file
View file

@ -0,0 +1,849 @@
" tComment.vim -- An easily extensible & universal comment plugin
" @Author: Thomas Link (micathom AT gmail com)
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 27-Dez-2004.
" @Last Change: 2007-08-30.
" @Revision: 1.7.608
"
" vimscript #1173
if &cp || exists('loaded_tcomment')
finish
endif
let loaded_tcomment = 107
function! s:DefVar(name, val)
if !exists(a:name)
" exec "let ". a:name ."='". a:val ."'"
exec 'let '. a:name .'="'. escape(a:val, '"\') .'"'
endif
endf
" If true, comment blank lines too
call s:DefVar('g:tcommentBlankLines', 1)
call s:DefVar('g:tcommentMapLeader1', '<c-_>')
call s:DefVar('g:tcommentMapLeader2', '<Leader>_')
" call s:DefVar('g:tcommentMapLeaderOp1', '<Leader>-')
call s:DefVar('g:tcommentMapLeaderOp1', 'gc')
call s:DefVar('g:tcommentMapLeaderOp2', 'gC')
call s:DefVar('g:tcommentOpModeExtra', '')
" Guess the file type based on syntax names always or for some fileformat only
call s:DefVar('g:tcommentGuessFileType', 0)
" In php documents, the php part is usually marked as phpRegion. We thus
" assume that the buffers default comment style isn't php but html
call s:DefVar('g:tcommentGuessFileType_dsl', 'xml')
call s:DefVar('g:tcommentGuessFileType_php', 'html')
call s:DefVar('g:tcommentGuessFileType_html', 1)
call s:DefVar('g:tcommentGuessFileType_tskeleton', 1)
call s:DefVar('g:tcommentGuessFileType_vim', 1)
call s:DefVar('g:tcommentIgnoreTypes_php', 'sql')
if !exists('g:tcommentSyntaxMap') "{{{2
let g:tcommentSyntaxMap = {
\ 'vimMzSchemeRegion': 'scheme',
\ 'vimPerlRegion': 'perl',
\ 'vimPythonRegion': 'python',
\ 'vimRubyRegion': 'ruby',
\ 'vimTclRegion': 'tcl',
\ }
endif
" If you don't define these variables, TComment will use &commentstring
" instead. We override the default values here in order to have a blank after
" the comment marker. Block comments work only if we explicitly define the
" markup.
" The format for block comments is similar to normal commentstrings with the
" exception that the format strings for blocks can contain a second line that
" defines how "middle lines" (see :h format-comments) should be displayed.
" I personally find this style rather irritating but here is an alternative
" definition that does this left-handed bar thing
call s:DefVar('g:tcommentBlockC', "/*%s */\n * ")
call s:DefVar('g:tcommentBlockC2', "/**%s */\n * ")
" call s:DefVar('g:tcommentBlockC', "/*%s */\n ")
call s:DefVar('g:tcommentInlineC', "/* %s */")
call s:DefVar('g:tcommentBlockXML', "<!--%s-->\n ")
call s:DefVar('g:tcommentInlineXML', "<!-- %s -->")
" Currently this function just sets a variable
function! TCommentDefineType(name, commentstring)
call s:DefVar('g:tcomment_'. a:name, a:commentstring)
let s:tcommentFileTypesDirty = 1
endf
function! TCommentTypeExists(name)
return exists('g:tcomment_'. a:name)
endf
call TCommentDefineType('ada', '-- %s' )
call TCommentDefineType('apache', '# %s' )
call TCommentDefineType('autoit', '; %s' )
call TCommentDefineType('awk', '# %s' )
call TCommentDefineType('catalog', '-- %s --' )
call TCommentDefineType('catalog_block', '--%s--\n ' )
call TCommentDefineType('cpp', '// %s' )
call TCommentDefineType('cpp_inline', g:tcommentInlineC )
call TCommentDefineType('cpp_block', g:tcommentBlockC )
call TCommentDefineType('css', '/* %s */' )
call TCommentDefineType('css_inline', g:tcommentInlineC )
call TCommentDefineType('css_block', g:tcommentBlockC )
call TCommentDefineType('c', '/* %s */' )
call TCommentDefineType('c_inline', g:tcommentInlineC )
call TCommentDefineType('c_block', g:tcommentBlockC )
call TCommentDefineType('cfg', '# %s' )
call TCommentDefineType('conf', '# %s' )
call TCommentDefineType('desktop', '# %s' )
call TCommentDefineType('docbk', '<!-- %s -->' )
call TCommentDefineType('docbk_inline', g:tcommentInlineXML)
call TCommentDefineType('docbk_block', g:tcommentBlockXML )
call TCommentDefineType('dosbatch', 'rem %s' )
call TCommentDefineType('dosini', '; %s' )
call TCommentDefineType('dsl', '; %s' )
call TCommentDefineType('dylan', '// %s' )
call TCommentDefineType('eiffel', '-- %s' )
call TCommentDefineType('gtkrc', '# %s' )
call TCommentDefineType('haskell', '-- %s' )
call TCommentDefineType('haskell_block', '{-%s-}\n ' )
call TCommentDefineType('haskell_inline', '{- %s -}' )
call TCommentDefineType('html', '<!-- %s -->' )
call TCommentDefineType('html_inline', g:tcommentInlineXML)
call TCommentDefineType('html_block', g:tcommentBlockXML )
call TCommentDefineType('io', '// %s' )
call TCommentDefineType('javaScript', '// %s' )
call TCommentDefineType('javaScript_inline', g:tcommentInlineC )
call TCommentDefineType('javaScript_block', g:tcommentBlockC )
call TCommentDefineType('javascript', '// %s' )
call TCommentDefineType('javascript_inline', g:tcommentInlineC )
call TCommentDefineType('javascript_block', g:tcommentBlockC )
call TCommentDefineType('java', '/* %s */' )
call TCommentDefineType('java_inline', g:tcommentInlineC )
call TCommentDefineType('java_block', g:tcommentBlockC )
call TCommentDefineType('lisp', '; %s' )
call TCommentDefineType('m4', 'dnl %s' )
call TCommentDefineType('mail', '> %s' )
call TCommentDefineType('nroff', '.\\" %s' )
call TCommentDefineType('objc', '/* %s */' )
call TCommentDefineType('objc_inline', g:tcommentInlineC )
call TCommentDefineType('objc_block', g:tcommentBlockC )
call TCommentDefineType('ocaml', '(* %s *)' )
call TCommentDefineType('ocaml_inline', '(* %s *)' )
call TCommentDefineType('ocaml_block', '(*%s*)\n ' )
call TCommentDefineType('pascal', '(* %s *)' )
call TCommentDefineType('pascal_inline', '(* %s *)' )
call TCommentDefineType('pascal_block', '(*%s*)\n ' )
call TCommentDefineType('perl', '# %s' )
call TCommentDefineType('perl_block', '=cut%s=cut' )
call TCommentDefineType('php', '// %s' )
call TCommentDefineType('php_inline', g:tcommentInlineC )
call TCommentDefineType('php_block', g:tcommentBlockC )
call TCommentDefineType('php_2_block', g:tcommentBlockC2 )
call TCommentDefineType('po', '# %s' )
call TCommentDefineType('prolog', '%% %s' )
call TCommentDefineType('readline', '# %s' )
call TCommentDefineType('ruby', '# %s' )
call TCommentDefineType('ruby_3', '### %s' )
call TCommentDefineType('ruby_block', '=begin rdoc%s=end')
call TCommentDefineType('ruby_nodoc_block', '=begin%s=end' )
call TCommentDefineType('r', '# %s' )
call TCommentDefineType('sbs', "' %s" )
call TCommentDefineType('scheme', '; %s' )
call TCommentDefineType('sed', '# %s' )
call TCommentDefineType('sgml', '<!-- %s -->' )
call TCommentDefineType('sgml_inline', g:tcommentInlineXML)
call TCommentDefineType('sgml_block', g:tcommentBlockXML )
call TCommentDefineType('sh', '# %s' )
call TCommentDefineType('sql', '-- %s' )
call TCommentDefineType('spec', '# %s' )
call TCommentDefineType('sps', '* %s.' )
call TCommentDefineType('sps_block', '* %s.' )
call TCommentDefineType('tcl', '# %s' )
call TCommentDefineType('tex', '%% %s' )
call TCommentDefineType('tpl', '<!-- %s -->' )
call TCommentDefineType('viki', '%% %s' )
call TCommentDefineType('viki_3', '%%%%%% %s' )
call TCommentDefineType('viki_inline', '{cmt: %s}' )
call TCommentDefineType('vim', '" %s' )
call TCommentDefineType('vim_3', '""" %s' )
call TCommentDefineType('websec', '# %s' )
call TCommentDefineType('xml', '<!-- %s -->' )
call TCommentDefineType('xml_inline', g:tcommentInlineXML)
call TCommentDefineType('xml_block', g:tcommentBlockXML )
call TCommentDefineType('xslt', '<!-- %s -->' )
call TCommentDefineType('xslt_inline', g:tcommentInlineXML)
call TCommentDefineType('xslt_block', g:tcommentBlockXML )
call TCommentDefineType('yaml', '# %s' )
let s:tcommentFileTypesDirty = 1
function! s:DefaultValue(option)
exec 'let '. a:option .' = &'. a:option
exec 'set '. a:option .'&'
exec 'let default = &'. a:option
exec 'let &'. a:option .' = '. a:option
return default
endf
let s:defaultComments = s:DefaultValue('comments')
let s:defaultCommentString = s:DefaultValue('commentstring')
let s:nullCommentString = '%s'
" TComment(line1, line2, ?commentMode, ?commentAnyway, ?commentBegin, ?commentEnd)
" commentMode:
" G ... guess
" B ... block
" I ... inline
" R ... right
function! TComment(beg, end, ...)
" save the cursor position
let co = col('.')
let li = line('.')
let s:pos_end = getpos("'>")
let commentMode = a:0 >= 1 ? a:1 : 'G'
let commentAnyway = a:0 >= 2 ? (a:2 == '!') : 0
if commentMode =~# 'i'
let commentMode = substitute(commentMode, '\Ci', line("'<") == line("'>") ? 'I' : 'G', 'g')
endif
if commentMode =~# 'R' || commentMode =~# 'I'
let cstart = col("'<")
if cstart == 0
let cstart = col('.')
endif
if commentMode =~# 'R'
let commentMode = substitute(commentMode, '\CR', 'G', 'g')
let cend = 0
else
let cend = col("'>")
endif
else
let cstart = 0
let cend = 0
endif
" TLogVAR commentMode, cstart, cend
" get the correct commentstring
if a:0 >= 3 && a:3 != ''
let cms = s:EncodeCommentPart(a:3) .'%s'
if a:0 >= 4 && a:4 != ''
let cms = cms . s:EncodeCommentPart(a:4)
endif
else
let [cms, commentMode] = s:GetCommentString(a:beg, a:end, commentMode)
endif
let cms0 = s:BlockGetCommentString(cms)
let cms0 = escape(cms0, '\')
" make whitespace optional; this conflicts with comments that require some
" whitespace
let cmtCheck = substitute(cms0, '\([ ]\)', '\1\\?', 'g')
" turn commentstring into a search pattern
let cmtCheck = s:SPrintF(cmtCheck, '\(\_.\{-}\)')
" set commentMode and indentStr
let [indentStr, uncomment] = s:CommentDef(a:beg, a:end, cmtCheck, commentMode, cstart, cend)
" TLogVAR indentStr, uncomment
if commentAnyway
let uncomment = 0
endif
" go
if commentMode =~# 'B'
" We want a comment block
call s:CommentBlock(a:beg, a:end, uncomment, cmtCheck, cms, indentStr)
else
" We want commented lines
" final search pattern for uncommenting
let cmtCheck = escape('\V\^\(\s\{-}\)'. cmtCheck .'\$', '"/\')
" final pattern for commenting
let cmtReplace = escape(cms0, '"/')
silent exec a:beg .','. a:end .'s/\V'.
\ s:StartRx(cstart) . indentStr .'\zs\(\.\*\)'. s:EndRx(cend) .'/'.
\ '\=s:ProcessedLine('. uncomment .', submatch(0), "'. cmtCheck .'", "'. cmtReplace .'")/ge'
endif
" reposition cursor
" TLogVAR commentMode
if commentMode =~ '>'
call setpos('.', s:pos_end)
else
" TLogVAR li, co
call cursor(li, co)
endif
endf
" :line1,line2 TComment ?commentBegin ?commentEnd
command! -bang -range -nargs=* TComment keepjumps call TComment(<line1>, <line2>, 'G', "<bang>", <f-args>)
" :line1,line2 TCommentRight ?commentBegin ?commentEnd
command! -bang -range -nargs=* TCommentRight keepjumps call TComment(<line1>, <line2>, 'R', "<bang>", <f-args>)
" :line1,line2 TCommentBlock ?commentBegin ?commentEnd
command! -bang -range -nargs=* TCommentBlock keepjumps call TComment(<line1>, <line2>, 'B', "<bang>", <f-args>)
" :line1,line2 TCommentInline ?commentBegin ?commentEnd
command! -bang -range -nargs=* TCommentInline keepjumps call TComment(<line1>, <line2>, 'I', "<bang>", <f-args>)
" :line1,line2 TCommentMaybeInline ?commentBegin ?commentEnd
command! -bang -range -nargs=* TCommentMaybeInline keepjumps call TComment(<line1>, <line2>, 'i', "<bang>", <f-args>)
function! TCommentOperator(type, ...) "{{{3
let commentMode = a:0 >= 1 ? a:1 : ''
let bang = a:0 >= 2 ? a:2 : ''
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
" let pos = getpos('.')
" TLogVAR a:type
try
if a:type == 'line'
silent exe "normal! '[V']"
let commentMode1 = 'G'
elseif a:type == 'block'
silent exe "normal! `[\<C-V>`]"
let commentMode1 = 'I'
else
silent exe "normal! `[v`]"
let commentMode1 = 'i'
endif
if empty(commentMode)
let commentMode = commentMode1
endif
let beg = line("'[")
let end = line("']")
norm! 
let commentMode .= g:tcommentOpModeExtra
call TComment(beg, end, commentMode, bang)
finally
let &selection = sel_save
let @@ = reg_save
if g:tcommentOpModeExtra !~ '>'
" TLogVAR pos
" call setpos('.', pos)
call setpos('.', w:tcommentPos)
unlet! w:tcommentPos
endif
endtry
endf
function! TCommentOperatorLine(type) "{{{3
call TCommentOperator(a:type, 'G')
endf
function! TCommentOperatorAnyway(type) "{{{3
call TCommentOperator(a:type, '', '!')
endf
function! TCommentOperatorLineAnyway(type) "{{{3
call TCommentOperator(a:type, 'G', '!')
endf
" comment text as if it were of a specific filetype
function! TCommentAs(beg, end, commentAnyway, filetype, ...)
let ccount = a:0 >= 1 ? a:1 : 1
" TLogVAR ccount
if a:filetype =~ '_block$'
let commentMode = 'B'
let ft = substitute(a:filetype, '_block$', '', '')
elseif a:filetype =~ '_inline$'
let commentMode = 'I'
let ft = substitute(a:filetype, '_inline$', '', '')
else
let commentMode = 'G'
let ft = a:filetype
endif
let [cms, commentMode] = s:GetCommentString(a:beg, a:end, commentMode, ft)
let pre = substitute(cms, '%s.*$', '', '')
let pre = substitute(pre, '%%', '%', 'g')
let post = substitute(cms, '^.\{-}%s', '', '')
let post = substitute(post, '%%', '%', 'g')
if ccount > 1
let pre_l = matchlist(pre, '^\(\S\+\)\(.*\)$')
" TLogVAR pre_l
if !empty(get(pre_l, 1))
let pre = repeat(pre_l[1], ccount) . pre_l[2]
endif
let post_l = matchlist(post, '^\(\s*\)\(.\+\)$')
" TLogVAR post_l
if !empty(get(post_l, 2))
let post = post_l[1] . repeat(post_l[2], ccount)
endif
endif
keepjumps call TComment(a:beg, a:end, commentMode, a:commentAnyway, pre, post)
endf
" :line1,line2 TCommentAs commenttype
command! -bang -complete=custom,TCommentFileTypes -range -nargs=+ TCommentAs
\ call TCommentAs(<line1>, <line2>, "<bang>", <f-args>)
if (g:tcommentMapLeader1 != '')
exec 'noremap <silent> '. g:tcommentMapLeader1 .'<c-_> :TComment<cr>'
exec 'vnoremap <silent> '. g:tcommentMapLeader1 .'<c-_> :TCommentMaybeInline<cr>'
exec 'inoremap <silent> '. g:tcommentMapLeader1 .'<c-_> <c-o>:TComment<cr>'
exec 'noremap <silent> '. g:tcommentMapLeader1 .'p m`vip:TComment<cr>``'
exec 'inoremap <silent> '. g:tcommentMapLeader1 .'p <c-o>:norm! m`vip<cr>:TComment<cr><c-o>``'
exec 'noremap '. g:tcommentMapLeader1 .'<space> :TComment '
exec 'inoremap '. g:tcommentMapLeader1 .'<space> <c-o>:TComment '
exec 'inoremap <silent> '. g:tcommentMapLeader1 .'r <c-o>:TCommentRight<cr>'
exec 'noremap <silent> '. g:tcommentMapLeader1 .'r :TCommentRight<cr>'
exec 'vnoremap <silent> '. g:tcommentMapLeader1 .'i :TCommentInline<cr>'
exec 'vnoremap <silent> '. g:tcommentMapLeader1 .'r :TCommentRight<cr>'
exec 'noremap '. g:tcommentMapLeader1 .'b :TCommentBlock<cr>'
exec 'inoremap '. g:tcommentMapLeader1 .'b <c-o>:TCommentBlock<cr>'
exec 'noremap '. g:tcommentMapLeader1 .'a :TCommentAs '
exec 'inoremap '. g:tcommentMapLeader1 .'a <c-o>:TCommentAs '
exec 'noremap '. g:tcommentMapLeader1 .'n :TCommentAs <c-r>=&ft<cr> '
exec 'inoremap '. g:tcommentMapLeader1 .'n <c-o>:TCommentAs <c-r>=&ft<cr> '
exec 'noremap '. g:tcommentMapLeader1 .'s :TCommentAs <c-r>=&ft<cr>_'
exec 'inoremap '. g:tcommentMapLeader1 .'s <c-o>:TCommentAs <c-r>=&ft<cr>_'
endif
if (g:tcommentMapLeader2 != '')
exec 'noremap <silent> '. g:tcommentMapLeader2 .'_ :TComment<cr>'
exec 'vnoremap <silent> '. g:tcommentMapLeader2 .'_ :TCommentMaybeInline<cr>'
exec 'noremap <silent> '. g:tcommentMapLeader2 .'p vip:TComment<cr>'
exec 'noremap '. g:tcommentMapLeader2 .'<space> :TComment '
exec 'vnoremap <silent> '. g:tcommentMapLeader2 .'i :TCommentInline<cr>'
exec 'noremap <silent> '. g:tcommentMapLeader2 .'r :TCommentRight<cr>'
exec 'vnoremap <silent> '. g:tcommentMapLeader2 .'r :TCommentRight<cr>'
exec 'noremap '. g:tcommentMapLeader2 .'b :TCommentBlock<cr>'
exec 'noremap '. g:tcommentMapLeader2 .'a :TCommentAs '
exec 'noremap '. g:tcommentMapLeader2 .'n :TCommentAs <c-r>=&ft<cr> '
exec 'noremap '. g:tcommentMapLeader2 .'s :TCommentAs <c-r>=&ft<cr>_'
endif
if (g:tcommentMapLeaderOp1 != '')
exec 'noremap <silent> '. g:tcommentMapLeaderOp1 .' :let w:tcommentPos = getpos(".") \| set opfunc=TCommentOperator<cr>g@'
exec 'noremap <silent> '. g:tcommentMapLeaderOp1 .'c :let w:tcommentPos = getpos(".") \| set opfunc=TCommentOperatorLine<cr>g@$'
endif
if (g:tcommentMapLeaderOp2 != '')
exec 'noremap <silent> '. g:tcommentMapLeaderOp2 .' :let w:tcommentPos = getpos(".") \| set opfunc=TCommentOperatorAnyway<cr>g@'
exec 'noremap <silent> '. g:tcommentMapLeaderOp2 .'c :let w:tcommentPos = getpos(".") \| set opfunc=TCommentOperatorLineAnyway<cr>g@$'
endif
" ----------------------------------------------------------------
" collect all variables matching ^tcomment_
function! TCommentCollectFileTypes()
if s:tcommentFileTypesDirty
let t = @t
try
redir @t
silent let
redir END
let g:tcommentFileTypes = substitute("\n". @t ."\n", '\n\(tcomment_\(\w\+\)\|\w\+\).\{-}\ze\n', '\n\2', 'g')
let g:tcommentFileTypes = substitute(g:tcommentFileTypes, '\(\n\)\n\+', '\1', 'g')
let g:tcommentFileTypes = strpart(g:tcommentFileTypes, 1, strlen(g:tcommentFileTypes) - 2)
finally
let @t = t
endtry
let g:tcommentFileTypesRx = '\V\^\('. substitute(g:tcommentFileTypes, '\n', '\\|', 'g') .'\)\(\u\.\*\)\?\$'
let s:tcommentFileTypesDirty = 0
endif
endf
call TCommentCollectFileTypes()
" return a list of filetypes for which a tcomment_{&ft} is defined
function! TCommentFileTypes(ArgLead, CmdLine, CursorPos)
call TCommentCollectFileTypes()
if a:ArgLead == ''
return &filetype ."\n". g:tcommentFileTypes
else
return g:tcommentFileTypes
endif
endf
function! s:EncodeCommentPart(string)
return substitute(a:string, '%', '%%', 'g')
endf
" s:GetCommentString(beg, end, commentMode, ?filetype="")
function! s:GetCommentString(beg, end, commentMode, ...)
let ft = a:0 >= 1 ? a:1 : ''
if ft != ''
let [cms, commentMode] = s:GetCustomCommentString(ft, a:commentMode)
else
let cms = ''
let commentMode = a:commentMode
endif
if cms == ''
if exists('b:commentstring')
let cms = b:commentstring
return s:GetCustomCommentString(&filetype, a:commentMode, cms)
elseif exists('b:commentStart') && b:commentStart != ''
let cms = s:EncodeCommentPart(b:commentStart) .' %s'
if exists('b:commentEnd') && b:commentEnd != ''
let cms = cms .' '. s:EncodeCommentPart(b:commentEnd)
endif
return s:GetCustomCommentString(&filetype, a:commentMode, cms)
elseif g:tcommentGuessFileType || (exists('g:tcommentGuessFileType_'. &filetype)
\ && g:tcommentGuessFileType_{&filetype} =~ '[^0]')
if g:tcommentGuessFileType_{&filetype} == 1
let altFiletype = ''
else
let altFiletype = g:tcommentGuessFileType_{&filetype}
endif
return s:GuessFileType(a:beg, a:end, a:commentMode, &filetype, altFiletype)
else
return s:GetCustomCommentString(&filetype, a:commentMode, s:GuessCurrentCommentString(a:commentMode))
endif
endif
return [cms, commentMode]
endf
" s:SPrintF(formatstring, ?values ...)
" => string
function! s:SPrintF(string, ...)
let n = 1
let r = ''
let s = a:string
while 1
let i = match(s, '%\(.\)')
if i >= 0
let x = s[i + 1]
let r = r . strpart(s, 0, i)
let s = strpart(s, i + 2)
if x == '%'
let r = r.'%'
else
if a:0 >= n
exec 'let v = a:'. n
let n = n + 1
else
echoerr 'Malformed format string (too many arguments required): '. a:string
endif
if x ==# 's'
let r = r.v
elseif x ==# 'S'
let r = r.'"'.v.'"'
else
echoerr 'Malformed format string: '. a:string
endif
endif
else
return r.s
endif
endwh
endf
function! s:StartRx(pos)
if a:pos == 0
return '\^'
else
return '\%'. a:pos .'c'
endif
endf
function! s:EndRx(pos)
if a:pos == 0
return '\$'
else
return '\%'. a:pos .'c'
endif
endf
function! s:GetIndentString(line, start)
let start = a:start > 0 ? a:start - 1 : 0
return substitute(strpart(getline(a:line), start), '\V\^\s\*\zs\.\*\$', '', '')
endf
function! s:CommentDef(beg, end, checkRx, commentMode, cstart, cend)
let mdrx = '\V'. s:StartRx(a:cstart) .'\s\*'. a:checkRx .'\s\*'. s:EndRx(0)
let line = getline(a:beg)
if a:cstart != 0 && a:cend != 0
let line = strpart(line, 0, a:cend - 1)
endif
let uncomment = (line =~ mdrx)
let it = s:GetIndentString(a:beg, a:cstart)
let il = indent(a:beg)
let n = a:beg + 1
while n <= a:end
if getline(n) =~ '\S'
let jl = indent(n)
if jl < il
let it = s:GetIndentString(n, a:cstart)
let il = jl
endif
if a:commentMode =~# 'G'
if !(getline(n) =~ mdrx)
let uncomment = 0
endif
endif
endif
let n = n + 1
endwh
if a:commentMode =~# 'B'
let t = @t
try
silent exec 'norm! '. a:beg.'G1|v'.a:end.'G$"ty'
let uncomment = (@t =~ mdrx)
finally
let @t = t
endtry
endif
return [it, uncomment]
endf
function! s:ProcessedLine(uncomment, match, checkRx, replace)
if !(a:match =~ '\S' || g:tcommentBlankLines)
return a:match
endif
let ml = len(a:match)
if a:uncomment
let rv = substitute(a:match, a:checkRx, '\1\2', '')
else
let rv = s:SPrintF(a:replace, a:match)
endif
" let md = len(rv) - ml
let s:pos_end = getpos('.')
let s:pos_end[2] += len(rv)
" TLogVAR pe, md, a:match
let rv = escape(rv, '\ ')
let rv = substitute(rv, '\n', '\\\n', 'g')
return rv
endf
function! s:CommentBlock(beg, end, uncomment, checkRx, replace, indentStr)
let t = @t
try
silent exec 'norm! '. a:beg.'G1|v'.a:end.'G$"td'
let ms = s:BlockGetMiddleString(a:replace)
let mx = escape(ms, '\')
if a:uncomment
let @t = substitute(@t, '\V\^\s\*'. a:checkRx .'\$', '\1', '')
if ms != ''
let @t = substitute(@t, '\V\n'. a:indentStr . mx, '\n'. a:indentStr, 'g')
endif
let @t = substitute(@t, '^\n', '', '')
let @t = substitute(@t, '\n\s*$', '', '')
else
let cs = s:BlockGetCommentString(a:replace)
let cs = a:indentStr . substitute(cs, '%s', '%s'. a:indentStr, '')
if ms != ''
let ms = a:indentStr . ms
let mx = a:indentStr . mx
let @t = substitute(@t, '^'. a:indentStr, '', 'g')
let @t = ms . substitute(@t, '\n'. a:indentStr, '\n'. mx, 'g')
endif
let @t = s:SPrintF(cs, "\n". @t ."\n")
endif
silent norm! "tP
finally
let @t = t
endtry
endf
" inspired by Meikel Brandmeyer's EnhancedCommentify.vim
" this requires that a syntax names are prefixed by the filetype name
" s:GuessFileType(beg, end, commentMode, filetype, ?fallbackFiletype)
function! s:GuessFileType(beg, end, commentMode, filetype, ...)
if a:0 >= 1 && a:1 != ''
let [cms, commentMode] = s:GetCustomCommentString(a:1, a:commentMode)
if cms == ''
let cms = s:GuessCurrentCommentString(a:commentMode)
endif
else
let commentMode = s:CommentMode(a:commentMode, 'G')
let cms = s:GuessCurrentCommentString(0)
endif
let n = a:beg
while n <= a:end
let m = indent(n) + 1
let le = col('$')
while m < le
let syntaxName = synIDattr(synID(n, m, 1), 'name')
let ftypeMap = get(g:tcommentSyntaxMap, syntaxName)
if !empty(ftypeMap)
return s:GetCustomCommentString(ftypeMap, a:commentMode, cms)
elseif syntaxName =~ g:tcommentFileTypesRx
let ft = substitute(syntaxName, g:tcommentFileTypesRx, '\1', '')
if exists('g:tcommentIgnoreTypes_'. a:filetype) && g:tcommentIgnoreTypes_{a:filetype} =~ '\<'.ft.'\>'
let m = m + 1
else
return s:GetCustomCommentString(ft, a:commentMode, cms)
endif
elseif syntaxName == '' || syntaxName == 'None' || syntaxName =~ '^\u\+$' || syntaxName =~ '^\u\U*$'
let m = m + 1
else
break
endif
endwh
let n = n + 1
endwh
return [cms, commentMode]
endf
function! s:CommentMode(commentMode, newmode) "{{{3
return substitute(a:commentMode, '\w\+', a:newmode, 'g')
endf
function! s:GuessCurrentCommentString(commentMode)
let valid_cms = (stridx(&commentstring, '%s') != -1)
if &commentstring != s:defaultCommentString && valid_cms
" The &commentstring appears to have been set and to be valid
return &commentstring
endif
if &comments != s:defaultComments
" the commentstring is the default one, so we assume that it wasn't
" explicitly set; we then try to reconstruct &cms from &comments
let cms = s:ConstructFromComments(a:commentMode)
if cms != s:nullCommentString
return cms
endif
endif
if valid_cms
" Before &commentstring appeared not to be set. As we don't know
" better we return it anyway if it is valid
return &commentstring
else
" &commentstring is invalid. So we return the identity string.
return s:nullCommentString
endif
endf
function! s:ConstructFromComments(commentMode)
exec s:ExtractCommentsPart('')
if a:commentMode =~# 'G' && line != ''
return line .' %s'
endif
exec s:ExtractCommentsPart('s')
if s != ''
exec s:ExtractCommentsPart('e')
" if a:commentMode
" exec s:ExtractCommentsPart("m")
" if m != ""
" let m = "\n". m
" endif
" return s.'%s'.e.m
" else
return s.' %s '.e
" endif
endif
if line != ''
return line .' %s'
else
return s:nullCommentString
endif
endf
function! s:ExtractCommentsPart(key)
" let key = a:key != "" ? a:key .'[^:]*' : ""
let key = a:key . '[bnflrxO0-9-]*'
let val = substitute(&comments, '^\(.\{-},\)\{-}'. key .':\([^,]\+\).*$', '\2', '')
if val == &comments
let val = ''
else
let val = substitute(val, '%', '%%', 'g')
endif
let var = a:key == '' ? 'line' : a:key
return 'let '. var .'="'. escape(val, '"') .'"'
endf
" s:GetCustomCommentString(ft, commentMode, ?default="")
function! s:GetCustomCommentString(ft, commentMode, ...)
let commentMode = a:commentMode
let customComment = exists('g:tcomment_'. a:ft)
if commentMode =~# 'B' && exists('g:tcomment_'. a:ft .'_block')
let cms = g:tcomment_{a:ft}_block
elseif commentMode =~? 'I' && exists('g:tcomment_'. a:ft .'_inline')
let cms = g:tcomment_{a:ft}_inline
elseif customComment
let cms = g:tcomment_{a:ft}
let commentMode = s:CommentMode(commentMode, 'G')
elseif a:0 >= 1
let cms = a:1
let commentMode = s:CommentMode(commentMode, 'G')
else
let cms = ''
let commentMode = s:CommentMode(commentMode, 'G')
endif
return [cms, commentMode]
endf
function! s:BlockGetCommentString(cms)
return substitute(a:cms, '\n.*$', '', '')
endf
function! s:BlockGetMiddleString(cms)
let rv = substitute(a:cms, '^.\{-}\n\([^\n]*\)', '\1', '')
return rv == a:cms ? '' : rv
endf
finish
-----------------------------------------------------------------------
History
0.1
- Initial release
0.2
- Fixed uncommenting of non-aligned comments
- improved support for block comments (with middle lines and indentation)
- using TCommentBlock for file types that don't have block comments creates
single line comments
- removed the TCommentAsBlock command (TCommentAs provides its functionality)
- removed g:tcommentSetCMS
- the default key bindings have slightly changed
1.3
- slightly improved recognition of embedded syntax
- if no commentstring is defined in whatever way, reconstruct one from
&comments
- The TComment... commands now have bang variants that don't act as toggles
but always comment out the selected text
- fixed problem with commentstrings containing backslashes
- comment as visual block (allows commenting text to the right of the main
text, i.e., this command doesn't work on whole lines but on the text to the
right of the cursor)
- enable multimode for dsl, vim filetypes
- added explicit support for some other file types I ran into
1.4
- Fixed problem when &commentstring was invalid (e.g. lua)
- perl_block by Kyosuke Takayama.
- <c-_>s mapped to :TCommentAs <c-r>=&ft<cr>
1.5
- "Inline" visual comments (uses the &filetype_inline style if
available; doesn't check if the filetype actually supports this kind of
comments); tComment can't currently deduce inline comment styles from
&comments or &commentstring (I personally hardly ever use them); default
map: <c-_>i or <c-_>I
- In visual mode: if the selection spans several lines, normal mode is
selected; if the selection covers only a part of one line, inline mode
is selected
- Fixed problem with lines containing ^M or ^@ characters.
- It's no longer necessary to call TCommentCollectFileTypes() after
defining a new filetype via TCommentDefineType()
- Disabled single <c-_> mappings
- Renamed TCommentVisualBlock to TCommentRight
- FIX: Forgot 'x' in ExtractCommentsPart() (thanks to Fredrik Acosta)
1.6
- Ignore sql when guessing the comment string in php files; tComment
sometimes chooses the wrong comment string because the use of sql syntax
is used too loosely in php files; if you want to comment embedded sql
code you have to use TCommentAs
- Use keepjumps in commands.
- Map <c-_>p & <L>_p to vip:TComment<cr>
- Made key maps configurable via g:tcommentMapLeader1 and
g:tcommentMapLeader2
1.7
- gc{motion} (see g:tcommentMapLeaderOp1) functions as a comment toggle
operator (i.e., something like gcl... works, mostly); gC{motion} (see
g:tcommentMapLeaderOp2) will unconditionally comment the text.
- TCommentAs takes an optional second argument (the comment level)
- New "n" map: TCommentAs &filetype [COUNT]
- Defined mail comments/citations
- g:tcommentSyntaxMap: Map syntax names to filetypes for buffers with
mixed syntax groups that don't match the filetypeEmbeddedsyntax scheme (e.g.
'vimRubyRegion', which should be commented as ruby syntax, not as vim
syntax)
- FIX: Comments in vim*Region
- TComment: The use of the type argument has slightly changed (IG -> i,
new: >)

5
vim/plugin/textile.vim Normal file
View file

@ -0,0 +1,5 @@
" textile.vim
"
" Tim Harper (tim.theenchanter.com)
au BufRead,BufNewFile *.textile setf textile

126
vim/syntax/cucumber.vim Normal file
View file

@ -0,0 +1,126 @@
" Vim syntax file
" Language: Cucumber
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Filenames: *.feature
" Last Change: 2010 May 21
if exists("b:current_syntax")
finish
endif
syn case match
syn sync minlines=20
let g:cucumber_languages = {
\"en": {"and": "And\\>", "background": "Background\\>", "but": "But\\>", "examples": "Scenarios\\>\\|Examples\\>", "feature": "Feature\\>", "given": "Given\\>", "scenario": "Scenario\\>", "scenario_outline": "Scenario Outline\\>", "then": "Then\\>", "when": "When\\>"},
\"ar": {"and": "\\%u0648\\>", "background": "\\%u0627\\%u0644\\%u062e\\%u0644\\%u0641\\%u064a\\%u0629\\>", "but": "\\%u0644\\%u0643\\%u0646\\>", "examples": "\\%u0627\\%u0645\\%u062b\\%u0644\\%u0629\\>", "feature": "\\%u062e\\%u0627\\%u0635\\%u064a\\%u0629\\>", "given": "\\%u0628\\%u0641\\%u0631\\%u0636\\>", "scenario": "\\%u0633\\%u064a\\%u0646\\%u0627\\%u0631\\%u064a\\%u0648\\>", "scenario_outline": "\\%u0633\\%u064a\\%u0646\\%u0627\\%u0631\\%u064a\\%u0648 \\%u0645\\%u062e\\%u0637\\%u0637\\>", "then": "\\%u0627\\%u0630\\%u0627\\%u064b\\>\\|\\%u062b\\%u0645\\>", "when": "\\%u0639\\%u0646\\%u062f\\%u0645\\%u0627\\>\\|\\%u0645\\%u062a\\%u0649\\>"},
\"bg": {"and": "\\%u0418\\>", "background": "\\%u041f\\%u0440\\%u0435\\%u0434\\%u0438\\%u0441\\%u0442\\%u043e\\%u0440\\%u0438\\%u044f\\>", "but": "\\%u041d\\%u043e\\>", "examples": "\\%u041f\\%u0440\\%u0438\\%u043c\\%u0435\\%u0440\\%u0438\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\%u043d\\%u043e\\%u0441\\%u0442\\>", "given": "\\%u0414\\%u0430\\%u0434\\%u0435\\%u043d\\%u043e\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "scenario_outline": "\\%u0420\\%u0430\\%u043c\\%u043a\\%u0430 \\%u043d\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "then": "\\%u0422\\%u043e\\>", "when": "\\%u041a\\%u043e\\%u0433\\%u0430\\%u0442\\%u043e\\>"},
\"ca": {"and": "I\\>", "background": "Antecedents\\>\\|Rerefons\\>", "but": "Per\\%u00f2\\>", "examples": "Exemples\\>", "feature": "Caracter\\%u00edstica\\>\\|Funcionalitat\\>", "given": "At\\%u00e8s\\>\\|Donada\\>\\|Donat\\>\\|Atesa\\>", "scenario": "Escenari\\>", "scenario_outline": "Esquema de l'escenari\\>", "then": "Aleshores\\>\\|Cal\\>", "when": "Quan\\>"},
\"cs": {"and": "A tak\\%u00e9\\>\\|A\\>", "background": "Pozad\\%u00ed\\>\\|Kontext\\>", "but": "Ale\\>", "examples": "P\\%u0159\\%u00edklady\\>", "feature": "Po\\%u017eadavek\\>", "given": "Pokud\\>", "scenario": "Sc\\%u00e9n\\%u00e1\\%u0159\\>", "scenario_outline": "N\\%u00e1\\%u010drt Sc\\%u00e9n\\%u00e1\\%u0159e\\>\\|Osnova sc\\%u00e9n\\%u00e1\\%u0159e\\>", "then": "Pak\\>", "when": "Kdy\\%u017e\\>"},
\"cy-GB": {"and": "A\\>", "background": "Cefndir\\>", "but": "Ond\\>", "examples": "Enghreifftiau\\>", "feature": "Arwedd\\>", "given": "Anrhegedig a\\>", "scenario": "Scenario\\>", "scenario_outline": "Scenario Amlinellol\\>", "then": "Yna\\>", "when": "Pryd\\>"},
\"da": {"and": "Og\\>", "background": "Baggrund\\>", "but": "Men\\>", "examples": "Eksempler\\>", "feature": "Egenskab\\>", "given": "Givet\\>", "scenario": "Scenarie\\>", "scenario_outline": "Abstrakt Scenario\\>", "then": "S\\%u00e5\\>", "when": "N\\%u00e5r\\>"},
\"de": {"and": "Und\\>", "background": "Grundlage\\>", "but": "Aber\\>", "examples": "Beispiele\\>", "feature": "Funktionalit\\%u00e4t\\>", "given": "Gegeben sei\\>\\|Angenommen\\>", "scenario": "Szenario\\>", "scenario_outline": "Szenariogrundriss\\>", "then": "Dann\\>", "when": "Wenn\\>"},
\"en-Scouse": {"and": "An\\>", "background": "Dis is what went down\\>", "but": "Buh\\>", "examples": "Examples\\>", "feature": "Feature\\>", "given": "Youse know when youse got\\>\\|Givun\\>", "scenario": "The thing of it is\\>", "scenario_outline": "Wharrimean is\\>", "then": "Den youse gotta\\>\\|Dun\\>", "when": "Youse know like when\\>\\|Wun\\>"},
\"en-au": {"and": "N\\>", "background": "Background\\>", "but": "Cept\\>", "examples": "Cobber\\>", "feature": "Crikey\\>", "given": "Ya know how\\>", "scenario": "Mate\\>", "scenario_outline": "Blokes\\>", "then": "Ya gotta\\>", "when": "When\\>"},
\"en-lol": {"and": "AN\\>", "background": "B4\\>", "but": "BUT\\>", "examples": "EXAMPLZ\\>", "feature": "OH HAI\\>", "given": "I CAN HAZ\\>", "scenario": "MISHUN\\>", "scenario_outline": "MISHUN SRSLY\\>", "then": "DEN\\>", "when": "WEN\\>"},
\"en-tx": {"and": "And y'all\\>", "background": "Background\\>", "but": "But y'all\\>", "examples": "Examples\\>", "feature": "Feature\\>", "given": "Given y'all\\>", "scenario": "Scenario\\>", "scenario_outline": "All y'all\\>", "then": "Then y'all\\>", "when": "When y'all\\>"},
\"eo": {"and": "Kaj\\>", "background": "Fono\\>", "but": "Sed\\>", "examples": "Ekzemploj\\>", "feature": "Trajto\\>", "given": "Donita\\%u0135o\\>", "scenario": "Scenaro\\>", "scenario_outline": "Konturo de la scenaro\\>", "then": "Do\\>", "when": "Se\\>"},
\"es": {"and": "Y\\>", "background": "Antecedentes\\>", "but": "Pero\\>", "examples": "Ejemplos\\>", "feature": "Caracter\\%u00edstica\\>", "given": "Dado\\>", "scenario": "Escenario\\>", "scenario_outline": "Esquema del escenario\\>", "then": "Entonces\\>", "when": "Cuando\\>"},
\"et": {"and": "Ja\\>", "background": "Taust\\>", "but": "Kuid\\>", "examples": "Juhtumid\\>", "feature": "Omadus\\>", "given": "Eeldades\\>", "scenario": "Stsenaarium\\>", "scenario_outline": "Raamstsenaarium\\>", "then": "Siis\\>", "when": "Kui\\>"},
\"fi": {"and": "Ja\\>", "background": "Tausta\\>", "but": "Mutta\\>", "examples": "Tapaukset\\>", "feature": "Ominaisuus\\>", "given": "Oletetaan\\>", "scenario": "Tapaus\\>", "scenario_outline": "Tapausaihio\\>", "then": "Niin\\>", "when": "Kun\\>"},
\"fr": {"and": "Et\\>", "background": "Contexte\\>", "but": "Mais\\>", "examples": "Exemples\\>", "feature": "Fonctionnalit\\%u00e9\\>", "given": "Etant donn\\%u00e9\\>\\|Soit\\>", "scenario": "Sc\\%u00e9nario\\>", "scenario_outline": "Plan du sc\\%u00e9nario\\>\\|Plan du Sc\\%u00e9nario\\>", "then": "Alors\\>", "when": "Lorsqu'\\|Lorsque\\>\\|Quand\\>"},
\"he": {"and": "\\%u05d5\\%u05d2\\%u05dd\\>", "background": "\\%u05e8\\%u05e7\\%u05e2\\>", "but": "\\%u05d0\\%u05d1\\%u05dc\\>", "examples": "\\%u05d3\\%u05d5\\%u05d2\\%u05de\\%u05d0\\%u05d5\\%u05ea\\>", "feature": "\\%u05ea\\%u05db\\%u05d5\\%u05e0\\%u05d4\\>", "given": "\\%u05d1\\%u05d4\\%u05d9\\%u05e0\\%u05ea\\%u05df\\>", "scenario": "\\%u05ea\\%u05e8\\%u05d7\\%u05d9\\%u05e9\\>", "scenario_outline": "\\%u05ea\\%u05d1\\%u05e0\\%u05d9\\%u05ea \\%u05ea\\%u05e8\\%u05d7\\%u05d9\\%u05e9\\>", "then": "\\%u05d0\\%u05d6\\%u05d9\\>\\|\\%u05d0\\%u05d6\\>", "when": "\\%u05db\\%u05d0\\%u05e9\\%u05e8\\>"},
\"hr": {"and": "I\\>", "background": "Pozadina\\>", "but": "Ali\\>", "examples": "Scenariji\\>\\|Primjeri\\>", "feature": "Mogu\\%u0107nost\\>\\|Mogucnost\\>\\|Osobina\\>", "given": "Zadano\\>\\|Zadani\\>\\|Zadan\\>", "scenario": "Scenarij\\>", "scenario_outline": "Koncept\\>\\|Skica\\>", "then": "Onda\\>", "when": "Kada\\>\\|Kad\\>"},
\"hu": {"and": "\\%u00c9s\\>", "background": "H\\%u00e1tt\\%u00e9r\\>", "but": "De\\>", "examples": "P\\%u00e9ld\\%u00e1k\\>", "feature": "Jellemz\\%u0151\\>", "given": "Ha\\>", "scenario": "Forgat\\%u00f3k\\%u00f6nyv\\>", "scenario_outline": "Forgat\\%u00f3k\\%u00f6nyv v\\%u00e1zlat\\>", "then": "Akkor\\>", "when": "Majd\\>"},
\"id": {"and": "Dan\\>", "background": "Dasar\\>", "but": "Tapi\\>", "examples": "Contoh\\>", "feature": "Fitur\\>", "given": "Dengan\\>", "scenario": "Skenario\\>", "scenario_outline": "Skenario konsep\\>", "then": "Maka\\>", "when": "Ketika\\>"},
\"it": {"and": "E\\>", "background": "Contesto\\>", "but": "Ma\\>", "examples": "Esempi\\>", "feature": "Funzionalit\\%u00e0\\>", "given": "Dato\\>", "scenario": "Scenario\\>", "scenario_outline": "Schema dello scenario\\>", "then": "Allora\\>", "when": "Quando\\>"},
\"ja": {"and": "\\%u304b\\%u3064", "background": "\\%u80cc\\%u666f\\>", "but": "\\%u3057\\%u304b\\%u3057\\|\\%u305f\\%u3060\\%u3057\\|\\%u4f46\\%u3057", "examples": "\\%u30b5\\%u30f3\\%u30d7\\%u30eb\\>\\|\\%u4f8b\\>", "feature": "\\%u30d5\\%u30a3\\%u30fc\\%u30c1\\%u30e3\\>\\|\\%u6a5f\\%u80fd\\>", "given": "\\%u524d\\%u63d0", "scenario": "\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\>", "scenario_outline": "\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\%u30a2\\%u30a6\\%u30c8\\%u30e9\\%u30a4\\%u30f3\\>\\|\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\%u30c6\\%u30f3\\%u30d7\\%u30ec\\%u30fc\\%u30c8\\>\\|\\%u30b7\\%u30ca\\%u30ea\\%u30aa\\%u30c6\\%u30f3\\%u30d7\\%u30ec\\>\\|\\%u30c6\\%u30f3\\%u30d7\\%u30ec\\>", "then": "\\%u306a\\%u3089\\%u3070", "when": "\\%u3082\\%u3057"},
\"ko": {"and": "\\%uadf8\\%ub9ac\\%uace0", "background": "\\%ubc30\\%uacbd\\>", "but": "\\%ud558\\%uc9c0\\%ub9cc\\|\\%ub2e8", "examples": "\\%uc608\\>", "feature": "\\%uae30\\%ub2a5\\>", "given": "\\%uc870\\%uac74\\|\\%uba3c\\%uc800", "scenario": "\\%uc2dc\\%ub098\\%ub9ac\\%uc624\\>", "scenario_outline": "\\%uc2dc\\%ub098\\%ub9ac\\%uc624 \\%uac1c\\%uc694\\>", "then": "\\%uadf8\\%ub7ec\\%uba74", "when": "\\%ub9cc\\%uc77c\\|\\%ub9cc\\%uc57d"},
\"lt": {"and": "Ir\\>", "background": "Kontekstas\\>", "but": "Bet\\>", "examples": "Pavyzd\\%u017eiai\\>\\|Scenarijai\\>\\|Variantai\\>", "feature": "Savyb\\%u0117\\>", "given": "Duota\\>", "scenario": "Scenarijus\\>", "scenario_outline": "Scenarijaus \\%u0161ablonas\\>", "then": "Tada\\>", "when": "Kai\\>"},
\"lu": {"and": "an\\>\\|a\\>", "background": "Hannergrond\\>", "but": "m\\%u00e4\\>\\|awer\\>", "examples": "Beispiller\\>", "feature": "Funktionalit\\%u00e9it\\>", "given": "ugeholl\\>", "scenario": "Szenario\\>", "scenario_outline": "Plang vum Szenario\\>", "then": "dann\\>", "when": "wann\\>"},
\"lv": {"and": "Un\\>", "background": "Situ\\%u0101cija\\>\\|Konteksts\\>", "but": "Bet\\>", "examples": "Piem\\%u0113ri\\>\\|Paraugs\\>", "feature": "Funkcionalit\\%u0101te\\>\\|F\\%u012b\\%u010da\\>", "given": "Kad\\>", "scenario": "Scen\\%u0101rijs\\>", "scenario_outline": "Scen\\%u0101rijs p\\%u0113c parauga\\>", "then": "Tad\\>", "when": "Ja\\>"},
\"nl": {"and": "En\\>", "background": "Achtergrond\\>", "but": "Maar\\>", "examples": "Voorbeelden\\>", "feature": "Functionaliteit\\>", "given": "Gegeven\\>\\|Stel\\>", "scenario": "Scenario\\>", "scenario_outline": "Abstract Scenario\\>", "then": "Dan\\>", "when": "Als\\>"},
\"no": {"and": "Og\\>", "background": "Bakgrunn\\>", "but": "Men\\>", "examples": "Eksempler\\>", "feature": "Egenskap\\>", "given": "Gitt\\>", "scenario": "Scenario\\>", "scenario_outline": "Abstrakt Scenario\\>", "then": "S\\%u00e5\\>", "when": "N\\%u00e5r\\>"},
\"pl": {"and": "Oraz\\>", "background": "Za\\%u0142o\\%u017cenia\\>", "but": "Ale\\>", "examples": "Przyk\\%u0142ady\\>", "feature": "W\\%u0142a\\%u015bciwo\\%u015b\\%u0107\\>", "given": "Zak\\%u0142adaj\\%u0105c\\>", "scenario": "Scenariusz\\>", "scenario_outline": "Szablon scenariusza\\>", "then": "Wtedy\\>", "when": "Je\\%u017celi\\>"},
\"pt": {"and": "E\\>", "background": "Contexto\\>", "but": "Mas\\>", "examples": "Exemplos\\>", "feature": "Funcionalidade\\>", "given": "Dado\\>", "scenario": "Cen\\%u00e1rio\\>\\|Cenario\\>", "scenario_outline": "Esquema do Cen\\%u00e1rio\\>\\|Esquema do Cenario\\>", "then": "Ent\\%u00e3o\\>\\|Entao\\>", "when": "Quando\\>"},
\"ro": {"and": "Si\\>", "background": "Conditii\\>", "but": "Dar\\>", "examples": "Exemplele\\>", "feature": "Functionalitate\\>", "given": "Daca\\>", "scenario": "Scenariu\\>", "scenario_outline": "Scenariul de sablon\\>", "then": "Atunci\\>", "when": "Cand\\>"},
\"ro-RO": {"and": "\\%u0218i\\>", "background": "Condi\\%u0163ii\\>", "but": "Dar\\>", "examples": "Exemplele\\>", "feature": "Func\\%u021bionalitate\\>", "given": "Dac\\%u0103\\>", "scenario": "Scenariu\\>", "scenario_outline": "Scenariul de \\%u015fablon\\>", "then": "Atunci\\>", "when": "C\\%u00e2nd\\>"},
\"ru": {"and": "\\%u041a \\%u0442\\%u043e\\%u043c\\%u0443 \\%u0436\\%u0435\\>\\|\\%u0418\\>", "background": "\\%u041f\\%u0440\\%u0435\\%u0434\\%u044b\\%u0441\\%u0442\\%u043e\\%u0440\\%u0438\\%u044f\\>", "but": "\\%u041d\\%u043e\\>\\|\\%u0410\\>", "examples": "\\%u0417\\%u043d\\%u0430\\%u0447\\%u0435\\%u043d\\%u0438\\%u044f\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\>\\|\\%u0424\\%u0438\\%u0447\\%u0430\\>", "given": "\\%u0414\\%u043e\\%u043f\\%u0443\\%u0441\\%u0442\\%u0438\\%u043c\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "scenario_outline": "\\%u0421\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u044f\\>", "then": "\\%u0422\\%u043e\\>", "when": "\\%u0415\\%u0441\\%u043b\\%u0438\\>"},
\"sk": {"and": "A\\>", "background": "Pozadie\\>", "but": "Ale\\>", "examples": "Pr\\%u00edklady\\>", "feature": "Po\\%u017eiadavka\\>", "given": "Pokia\\%u013e\\>", "scenario": "Scen\\%u00e1r\\>", "scenario_outline": "N\\%u00e1\\%u010drt Scen\\%u00e1ru\\>", "then": "Tak\\>", "when": "Ke\\%u010f\\>"},
\"sr-Cyrl": {"and": "\\%u0418\\>", "background": "\\%u041a\\%u043e\\%u043d\\%u0442\\%u0435\\%u043a\\%u0441\\%u0442\\>\\|\\%u041f\\%u043e\\%u0437\\%u0430\\%u0434\\%u0438\\%u043d\\%u0430\\>\\|\\%u041e\\%u0441\\%u043d\\%u043e\\%u0432\\%u0430\\>", "but": "\\%u0410\\%u043b\\%u0438\\>", "examples": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0458\\%u0438\\>\\|\\%u041f\\%u0440\\%u0438\\%u043c\\%u0435\\%u0440\\%u0438\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\%u043d\\%u043e\\%u0441\\%u0442\\>\\|\\%u041c\\%u043e\\%u0433\\%u0443\\%u045b\\%u043d\\%u043e\\%u0441\\%u0442\\>\\|\\%u041e\\%u0441\\%u043e\\%u0431\\%u0438\\%u043d\\%u0430\\>", "given": "\\%u0417\\%u0430\\%u0434\\%u0430\\%u0442\\%u043e\\>\\|\\%u0417\\%u0430\\%u0434\\%u0430\\%u0442\\%u0435\\>\\|\\%u0417\\%u0430\\%u0434\\%u0430\\%u0442\\%u0438\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u043e\\>\\|\\%u041f\\%u0440\\%u0438\\%u043c\\%u0435\\%u0440\\>", "scenario_outline": "\\%u0421\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0458\\%u0430\\>\\|\\%u041a\\%u043e\\%u043d\\%u0446\\%u0435\\%u043f\\%u0442\\>\\|\\%u0421\\%u043a\\%u0438\\%u0446\\%u0430\\>", "then": "\\%u041e\\%u043d\\%u0434\\%u0430\\>", "when": "\\%u041a\\%u0430\\%u0434\\%u0430\\>\\|\\%u041a\\%u0430\\%u0434\\>"},
\"sr-Latn": {"and": "I\\>", "background": "Kontekst\\>\\|Pozadina\\>\\|Osnova\\>", "but": "Ali\\>", "examples": "Scenariji\\>\\|Primeri\\>", "feature": "Mogu\\%u0107nost\\>\\|Funkcionalnost\\>\\|Mogucnost\\>\\|Osobina\\>", "given": "Zadato\\>\\|Zadate\\>\\|Zatati\\>", "scenario": "Scenario\\>\\|Primer\\>", "scenario_outline": "Struktura scenarija\\>\\|Koncept\\>\\|Skica\\>", "then": "Onda\\>", "when": "Kada\\>\\|Kad\\>"},
\"sv": {"and": "Och\\>", "background": "Bakgrund\\>", "but": "Men\\>", "examples": "Exempel\\>", "feature": "Egenskap\\>", "given": "Givet\\>", "scenario": "Scenario\\>", "scenario_outline": "Abstrakt Scenario\\>", "then": "S\\%u00e5\\>", "when": "N\\%u00e4r\\>"},
\"tr": {"and": "Ve\\>", "background": "Ge\\%u00e7mi\\%u015f\\>", "but": "Fakat\\>\\|Ama\\>", "examples": "\\%u00d6rnekler\\>", "feature": "\\%u00d6zellik\\>", "given": "Diyelim ki\\>", "scenario": "Senaryo\\>", "scenario_outline": "Senaryo tasla\\%u011f\\%u0131\\>", "then": "O zaman\\>", "when": "E\\%u011fer ki\\>"},
\"uk": {"and": "\\%u0406\\>", "background": "\\%u041f\\%u0435\\%u0440\\%u0435\\%u0434\\%u0443\\%u043c\\%u043e\\%u0432\\%u0430\\>", "but": "\\%u0410\\%u043b\\%u0435\\>", "examples": "\\%u041f\\%u0440\\%u0438\\%u043a\\%u043b\\%u0430\\%u0434\\%u0438\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0456\\%u043e\\%u043d\\%u0430\\%u043b\\>", "given": "\\%u041f\\%u0440\\%u0438\\%u043f\\%u0443\\%u0441\\%u0442\\%u0438\\%u043c\\%u043e, \\%u0449\\%u043e\\>\\|\\%u041f\\%u0440\\%u0438\\%u043f\\%u0443\\%u0441\\%u0442\\%u0438\\%u043c\\%u043e\\>\\|\\%u041d\\%u0435\\%u0445\\%u0430\\%u0439\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0456\\%u0439\\>", "scenario_outline": "\\%u0421\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430 \\%u0441\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0456\\%u044e\\>", "then": "\\%u0422\\%u043e\\>", "when": "\\%u042f\\%u043a\\%u0449\\%u043e\\>"},
\"uz": {"and": "\\%u0412\\%u0430\\>", "background": "\\%u0422\\%u0430\\%u0440\\%u0438\\%u0445\\>", "but": "\\%u041b\\%u0435\\%u043a\\%u0438\\%u043d\\>\\|\\%u0411\\%u0438\\%u0440\\%u043e\\%u043a\\>\\|\\%u0410\\%u043c\\%u043c\\%u043e\\>", "examples": "\\%u041c\\%u0438\\%u0441\\%u043e\\%u043b\\%u043b\\%u0430\\%u0440\\>", "feature": "\\%u0424\\%u0443\\%u043d\\%u043a\\%u0446\\%u0438\\%u043e\\%u043d\\%u0430\\%u043b\\>", "given": "\\%u0410\\%u0433\\%u0430\\%u0440\\>", "scenario": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439\\>", "scenario_outline": "\\%u0421\\%u0446\\%u0435\\%u043d\\%u0430\\%u0440\\%u0438\\%u0439 \\%u0441\\%u0442\\%u0440\\%u0443\\%u043a\\%u0442\\%u0443\\%u0440\\%u0430\\%u0441\\%u0438\\>", "then": "\\%u0423\\%u043d\\%u0434\\%u0430\\>", "when": "\\%u0410\\%u0433\\%u0430\\%u0440\\>"},
\"vi": {"and": "V\\%u00e0\\>", "background": "B\\%u1ed1i c\\%u1ea3nh\\>", "but": "Nh\\%u01b0ng\\>", "examples": "D\\%u1eef li\\%u1ec7u\\>", "feature": "T\\%u00ednh n\\%u0103ng\\>", "given": "Bi\\%u1ebft\\>\\|Cho\\>", "scenario": "T\\%u00ecnh hu\\%u1ed1ng\\>\\|K\\%u1ecbch b\\%u1ea3n\\>", "scenario_outline": "Khung t\\%u00ecnh hu\\%u1ed1ng\\>\\|Khung k\\%u1ecbch b\\%u1ea3n\\>", "then": "Th\\%u00ec\\>", "when": "Khi\\>"},
\"zh-CN": {"and": "\\%u800c\\%u4e14", "background": "\\%u80cc\\%u666f\\>", "but": "\\%u4f46\\%u662f", "examples": "\\%u4f8b\\%u5b50\\>", "feature": "\\%u529f\\%u80fd\\>", "given": "\\%u5047\\%u5982", "scenario": "\\%u573a\\%u666f\\>", "scenario_outline": "\\%u573a\\%u666f\\%u5927\\%u7eb2\\>", "then": "\\%u90a3\\%u4e48", "when": "\\%u5f53"},
\"zh-TW": {"and": "\\%u800c\\%u4e14\\|\\%u4e26\\%u4e14", "background": "\\%u80cc\\%u666f\\>", "but": "\\%u4f46\\%u662f", "examples": "\\%u4f8b\\%u5b50\\>", "feature": "\\%u529f\\%u80fd\\>", "given": "\\%u5047\\%u8a2d", "scenario": "\\%u5834\\%u666f\\>\\|\\%u5287\\%u672c\\>", "scenario_outline": "\\%u5834\\%u666f\\%u5927\\%u7db1\\>\\|\\%u5287\\%u672c\\%u5927\\%u7db1\\>", "then": "\\%u90a3\\%u9ebc", "when": "\\%u7576"}}
function! s:pattern(key)
let language = matchstr(getline(1),'#\s*language:\s*\zs\S\+')
if &fileencoding == 'latin1' && language == ''
let language = 'en'
endif
if has_key(g:cucumber_languages, language)
let languages = [g:cucumber_languages[language]]
else
let languages = values(g:cucumber_languages)
end
return '\<\%('.join(map(languages,'get(v:val,a:key,"\\%(a\\&b\\)")'),'\|').'\)'
endfunction
function! s:Add(name)
let next = " skipempty skipwhite nextgroup=".join(map(["Region","AndRegion","ButRegion","Comment","Table"],'"cucumber".a:name.v:val'),",")
exe "syn region cucumber".a:name.'Region matchgroup=cucumber'.a:name.' start="\%(^\s*\)\@<=\%('.s:pattern(tolower(a:name)).'\)" end="$"'.next
exe 'syn region cucumber'.a:name.'AndRegion matchgroup=cucumber'.a:name.'And start="\%(^\s*\)\@<='.s:pattern('and').'" end="$" contained'.next
exe 'syn region cucumber'.a:name.'ButRegion matchgroup=cucumber'.a:name.'But start="\%(^\s*\)\@<='.s:pattern('but').'" end="$" contained'.next
exe 'syn match cucumber'.a:name.'Comment "\%(^\s*\)\@<=#.*" contained'.next
exe 'syn match cucumber'.a:name.'Table "\%(^\s*\)\@<=|.*" contained contains=cucumberDelimiter'.next
exe 'hi def link cucumber'.a:name.'Comment cucumberComment'
exe 'hi def link cucumber'.a:name.'But cucumber'.a:name.'And'
exe 'hi def link cucumber'.a:name.'And cucumber'.a:name
exe 'syn cluster cucumberStepRegions add=cucumber'.a:name.'Region,cucumber'.a:name.'AndRegion,cucumber'.a:name.'ButRegion'
endfunction
syn match cucumberComment "\%(^\s*\)\@<=#.*"
syn match cucumberComment "\%(\%^\s*\)\@<=#.*" contains=cucumberLanguage
syn match cucumberLanguage "\%(#\s*\)\@<=language:" contained
syn match cucumberUnparsed "\S.*" nextgroup=cucumberUnparsedComment,cucumberUnparsed,cucumberTags,cucumberBackground,cucumberScenario,cucumberScenarioOutline,cucumberExamples skipwhite skipempty contained
syn match cucumberUnparsedComment "#.*" nextgroup=cucumberUnparsedComment,cucumberUnparsed,cucumberTags,cucumberBackground,cucumberScenario,cucumberScenarioOutline,cucumberExamples skipwhite skipempty contained
exe 'syn match cucumberFeature "\%(^\s*\)\@<='.s:pattern('feature').':" nextgroup=cucumberUnparsedComment,cucumberUnparsed,cucumberBackground,cucumberScenario,cucumberScenarioOutline,cucumberExamples skipwhite skipempty'
exe 'syn match cucumberBackground "\%(^\s*\)\@<='.s:pattern('background').':"'
exe 'syn match cucumberScenario "\%(^\s*\)\@<='.s:pattern('scenario').':"'
exe 'syn match cucumberScenarioOutline "\%(^\s*\)\@<='.s:pattern('scenario_outline').':"'
exe 'syn match cucumberExamples "\%(^\s*\)\@<='.s:pattern('examples').':" nextgroup=cucumberExampleTable skipempty skipwhite'
syn match cucumberPlaceholder "<[^<>]*>" contained containedin=@cucumberStepRegions
syn match cucumberExampleTable "\%(^\s*\)\@<=|.*" contains=cucumberDelimiter
syn match cucumberDelimiter "|" contained
syn match cucumberTags "\%(^\s*\)\@<=\%(@[^@[:space:]]\+\s\+\)*@[^@[:space:]]\+\s*$"
syn region cucumberString start=+\%(^\s*\)\@<="""+ end=+"""+
call s:Add('Then')
call s:Add('When')
call s:Add('Given')
hi def link cucumberUnparsedComment cucumberComment
hi def link cucumberComment Comment
hi def link cucumberLanguage SpecialComment
hi def link cucumberFeature Macro
hi def link cucumberBackground Define
hi def link cucumberScenario Define
hi def link cucumberScenarioOutline Define
hi def link cucumberExamples Define
hi def link cucumberPlaceholder Constant
hi def link cucumberDelimiter Delimiter
hi def link cucumberTags Tag
hi def link cucumberString String
hi def link cucumberGiven Conditional
hi def link cucumberWhen Function
hi def link cucumberThen Type
let b:current_syntax = "cucumber"
" vim:set sts=2 sw=2:

109
vim/syntax/haml.vim Normal file
View file

@ -0,0 +1,109 @@
" Vim syntax file
" Language: Haml
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Filenames: *.haml
" Last Change: 2010 Aug 09
if exists("b:current_syntax")
finish
endif
if !exists("main_syntax")
let main_syntax = 'haml'
endif
let b:ruby_no_expensive = 1
runtime! syntax/html.vim
unlet! b:current_syntax
silent! syn include @hamlSassTop syntax/sass.vim
unlet! b:current_syntax
syn include @hamlRubyTop syntax/ruby.vim
syn case match
syn region rubyCurlyBlock start="{" end="}" contains=@hamlRubyTop contained
syn cluster hamlRubyTop add=rubyCurlyBlock
syn cluster hamlComponent contains=hamlAttributes,hamlAttributesHash,hamlClassChar,hamlIdChar,hamlObject,hamlDespacer,hamlSelfCloser,hamlRuby,hamlPlainChar,hamlInterpolatable
syn cluster hamlEmbeddedRuby contains=hamlAttributesHash,hamlObject,hamlRuby,hamlRubyFilter
syn cluster hamlTop contains=hamlBegin,hamlPlainFilter,hamlRubyFilter,hamlSassFilter,hamlComment,hamlHtmlComment
syn match hamlBegin "^\s*\%([<>]\|&[^=~ ]\)\@!" nextgroup=hamlTag,hamlClassChar,hamlIdChar,hamlRuby,hamlPlainChar,hamlInterpolatable
syn match hamlTag "%\w\+\%(:\w\+\)\=" contained contains=htmlTagName,htmlSpecialTagName nextgroup=@hamlComponent
syn region hamlAttributes matchgroup=hamlAttributesDelimiter start="(" end=")" contained contains=htmlArg,hamlAttributeString,hamlAttributeVariable,htmlEvent,htmlCssDefinition nextgroup=@hamlComponent
syn region hamlAttributesHash matchgroup=hamlAttributesDelimiter start="{" end="}" contained contains=@hamlRubyTop nextgroup=@hamlComponent
syn region hamlObject matchgroup=hamlObjectDelimiter start="\[" end="\]" contained contains=@hamlRubyTop nextgroup=@hamlComponent
syn match hamlDespacer "[<>]" contained nextgroup=hamlDespacer,hamlSelfCloser,hamlRuby,hamlPlainChar,hamlInterpolatable
syn match hamlSelfCloser "/" contained
syn match hamlClassChar "\." contained nextgroup=hamlClass
syn match hamlIdChar "#{\@!" contained nextgroup=hamlId
syn match hamlClass "\%(\w\|-\)\+" contained nextgroup=@hamlComponent
syn match hamlId "\%(\w\|-\)\+" contained nextgroup=@hamlComponent
syn region hamlDocType start="^\s*!!!" end="$"
syn region hamlRuby matchgroup=hamlRubyOutputChar start="[!&]\==\|\~" skip=",\s*$" end="$" contained contains=@hamlRubyTop keepend
syn region hamlRuby matchgroup=hamlRubyChar start="-" skip=",\s*$" end="$" contained contains=@hamlRubyTop keepend
syn match hamlPlainChar "\\" contained
syn region hamlInterpolatable matchgroup=hamlInterpolatableChar start="!\===\|!=\@!" end="$" keepend contained contains=hamlInterpolation,hamlInterpolationEscape,@hamlHtmlTop
syn region hamlInterpolatable matchgroup=hamlInterpolatableChar start="&==\|&=\@!" end="$" keepend contained contains=hamlInterpolation,hamlInterpolationEscape
syn region hamlInterpolation matchgroup=hamlInterpolationDelimiter start="#{" end="}" contains=@hamlRubyTop containedin=javascriptStringS,javascriptStringD
syn match hamlInterpolationEscape "\\\@<!\%(\\\\\)*\\\%(\\\ze#{\|#\ze{\)"
syn region hamlErbInterpolation matchgroup=hamlInterpolationDelimiter start="<%[=-]\=" end="-\=%>" contained contains=@hamlRubyTop
syn region hamlAttributeString start=+\%(=\s*\)\@<='+ skip=+\%(\\\\\)*\\'+ end=+'+ contains=hamlInterpolation,hamlInterpolationEscape
syn region hamlAttributeString start=+\%(=\s*\)\@<="+ skip=+\%(\\\\\)*\\"+ end=+"+ contains=hamlInterpolation,hamlInterpolationEscape
syn match hamlAttributeVariable "\%(=\s*\)\@<=\%(@@\=\|\$\)\=\w\+" contained
syn match hamlHelper "\<action_view?\|\<block_is_haml?\|\<is_haml?\|\.\@<!\<flatten" contained containedin=@hamlEmbeddedRuby,@hamlRubyTop
syn keyword hamlHelper capture_haml escape_once find_and_preserve haml_concat haml_indent haml_tag html_attrs html_esape init_haml_helpers list_of non_haml precede preserve succeed surround tab_down tab_up page_class contained containedin=@hamlEmbeddedRuby,@hamlRubyTop
syn cluster hamlHtmlTop contains=@htmlTop,htmlBold,htmlItalic,htmlUnderline
syn region hamlPlainFilter matchgroup=hamlFilter start="^\z(\s*\):\%(plain\|preserve\|redcloth\|textile\|markdown\|maruku\)\s*$" end="^\%(\z1 \| *$\)\@!" contains=@hamlHtmlTop,hamlInterpolation
syn region hamlEscapedFilter matchgroup=hamlFilter start="^\z(\s*\):\%(escaped\|cdata\)\s*$" end="^\%(\z1 \| *$\)\@!" contains=hamlInterpolation
syn region hamlErbFilter matchgroup=hamlFilter start="^\z(\s*\):erb\s*$" end="^\%(\z1 \| *$\)\@!" contains=@hamlHtmlTop,hamlErbInterpolation
syn region hamlRubyFilter matchgroup=hamlFilter start="^\z(\s*\):ruby\s*$" end="^\%(\z1 \| *$\)\@!" contains=@hamlRubyTop
syn region hamlJavascriptFilter matchgroup=hamlFilter start="^\z(\s*\):javascript\s*$" end="^\%(\z1 \| *$\)\@!" contains=@htmlJavaScript,hamlInterpolation keepend
syn region hamlCSSFilter matchgroup=hamlFilter start="^\z(\s*\):css\s*$" end="^\%(\z1 \| *$\)\@!" contains=@htmlCss,hamlInterpolation keepend
syn region hamlSassFilter matchgroup=hamlFilter start="^\z(\s*\):sass\s*$" end="^\%(\z1 \| *$\)\@!" contains=@hamlSassTop
syn region hamlJavascriptBlock start="^\z(\s*\)%script" nextgroup=@hamlComponent,hamlError end="^\%(\z1 \| *$\)\@!" contains=@hamlTop,@htmlJavaScript keepend
syn region hamlCssBlock start="^\z(\s*\)%style" nextgroup=@hamlComponent,hamlError end="^\%(\z1 \| *$\)\@!" contains=@hamlTop,@htmlCss keepend
syn match hamlError "\$" contained
syn region hamlComment start="^\z(\s*\)-#" end="^\%(\z1 \| *$\)\@!" contains=rubyTodo
syn region hamlHtmlComment start="^\z(\s*\)/" end="^\%(\z1 \| *$\)\@!" contains=@hamlTop,rubyTodo
syn match hamlIEConditional "\%(^\s*/\)\@<=\[if\>[^]]*]" contained containedin=hamlHtmlComment
hi def link hamlSelfCloser Special
hi def link hamlDespacer Special
hi def link hamlClassChar Special
hi def link hamlIdChar Special
hi def link hamlTag Special
hi def link hamlClass Type
hi def link hamlId Identifier
hi def link hamlPlainChar Special
hi def link hamlInterpolatableChar hamlRubyChar
hi def link hamlRubyOutputChar hamlRubyChar
hi def link hamlRubyChar Special
hi def link hamlInterpolationDelimiter Delimiter
hi def link hamlInterpolationEscape Special
hi def link hamlAttributeString String
hi def link hamlAttributeVariable Identifier
hi def link hamlDocType PreProc
hi def link hamlFilter PreProc
hi def link hamlAttributesDelimiter Delimiter
hi def link hamlObjectDelimiter Delimiter
hi def link hamlHelper Function
hi def link hamlHtmlComment hamlComment
hi def link hamlComment Comment
hi def link hamlIEConditional SpecialComment
hi def link hamlError Error
let b:current_syntax = "haml"
if main_syntax == "haml"
unlet main_syntax
endif
" vim:set sw=2:

104
vim/syntax/mkd.vim Normal file
View file

@ -0,0 +1,104 @@
" Vim syntax file
" Language: Markdown
" Maintainer: Ben Williams <benw@plasticboy.com>
" URL: http://plasticboy.com/markdown-vim-mode/
" Version: 9
" Last Change: 2009 May 18
" Remark: Uses HTML syntax file
" Remark: I don't do anything with angle brackets (<>) because that would too easily
" easily conflict with HTML syntax
" TODO: Handle stuff contained within stuff (e.g. headings within blockquotes)
" Read the HTML syntax to start with
if version < 600
so <sfile>:p:h/html.vim
else
runtime! syntax/html.vim
unlet b:current_syntax
endif
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
" don't use standard HiLink, it will not work with included syntax files
if version < 508
command! -nargs=+ HtmlHiLink hi link <args>
else
command! -nargs=+ HtmlHiLink hi def link <args>
endif
syn spell toplevel
syn case ignore
syn sync linebreaks=1
"additions to HTML groups
syn region htmlBold start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!/ end=/\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/ contains=@Spell,htmlItalic
syn region htmlItalic start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!/ end=/\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/ contains=htmlBold,@Spell
syn region htmlBold start=/\\\@<!\(^\|\A\)\@=_\@<!___\@!/ end=/\\\@<!_\@<!___\@!\($\|\A\)\@=/ contains=htmlItalic,@Spell
syn region htmlItalic start=/\\\@<!\(^\|\A\)\@=_\@<!__\@!/ end=/\\\@<!_\@<!__\@!\($\|\A\)\@=/ contains=htmlBold,@Spell
" [link](URL) | [link][id] | [link][]
syn region mkdLink matchgroup=mkdDelimiter start="\!\?\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained
syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained
" Link definitions: [id]: URL (Optional Title)
" TODO handle automatic links without colliding with htmlTag (<URL>)
syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
"define Markdown groups
syn match mkdLineContinue ".$" contained
syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
syn match mkdRule /^\s*-\{3,}$/
syn match mkdRule /^\s*\*\{3,5}$/
syn match mkdListItem "^\s*[-*+]\s\+"
syn match mkdListItem "^\s*\d\+\.\s\+"
syn match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
syn match mkdLineBreak / \+$/
syn region mkdCode start=/\\\@<!`/ end=/\\\@<!`/
syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
syn region mkdCode start="<pre[^>]*>" end="</pre>"
syn region mkdCode start="<code[^>]*>" end="</code>"
"HTML headings
syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
"highlighting for Markdown groups
HtmlHiLink mkdString String
HtmlHiLink mkdCode String
HtmlHiLink mkdBlockquote Comment
HtmlHiLink mkdLineContinue Comment
HtmlHiLink mkdListItem Identifier
HtmlHiLink mkdRule Identifier
HtmlHiLink mkdLineBreak Todo
HtmlHiLink mkdLink htmlLink
HtmlHiLink mkdURL htmlString
HtmlHiLink mkdID Identifier
HtmlHiLink mkdLinkDef mkdID
HtmlHiLink mkdLinkDefTarget mkdURL
HtmlHiLink mkdLinkTitle htmlString
HtmlHiLink mkdDelimiter Delimiter
let b:current_syntax = "mkd"
delcommand HtmlHiLink
" vim: ts=8

90
vim/syntax/sass.vim Normal file
View file

@ -0,0 +1,90 @@
" Vim syntax file
" Language: Sass
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Filenames: *.sass
" Last Change: 2010 Aug 09
if exists("b:current_syntax")
finish
endif
runtime! syntax/css.vim
syn case ignore
syn cluster sassCssProperties contains=cssFontProp,cssFontDescriptorProp,cssColorProp,cssTextProp,cssBoxProp,cssGeneratedContentProp,cssPagingProp,cssUIProp,cssRenderProp,cssAuralProp,cssTableProp
syn cluster sassCssAttributes contains=css.*Attr,scssComment,cssValue.*,cssColor,cssURL,sassDefault,cssImportant,cssError,cssStringQ,cssStringQQ,cssFunction,cssUnicodeEscape,cssRenderProp
syn region sassDefinition matchgroup=cssBraces start="{" end="}" contains=TOP
syn match sassProperty "\%([{};]\s*\|^\)\@<=\%([[:alnum:]-]\|#{[^{}]*}\)\+:" contains=css.*Prop skipwhite nextgroup=sassCssAttribute contained containedin=sassDefinition
syn match sassProperty "^\s*\zs\s\%(\%([[:alnum:]-]\|#{[^{}]*}\)\+:\|:[[:alnum:]-]\+\)"hs=s+1 contains=css.*Prop skipwhite nextgroup=sassCssAttribute
syn match sassProperty "^\s*\zs\s\%(:\=[[:alnum:]-]\+\s*=\)"hs=s+1 contains=css.*Prop skipwhite nextgroup=sassCssAttribute
syn match sassCssAttribute +\%("\%([^"]\|\\"\)*"\|'\%([^']\|\\'\)*'\|#{[^{}]*}\|[^{};]\)*+ contained contains=@sassCssAttributes,sassVariable,sassFunction,sassInterpolation
syn match sassDefault "!default\>" contained
syn match sassVariable "!\%(important\>\|default\>\)\@![[:alnum:]_-]\+"
syn match sassVariable "$[[:alnum:]_-]\+"
syn match sassVariableAssignment "\%([!$][[:alnum:]_-]\+\s*\)\@<=\%(||\)\==" nextgroup=sassCssAttribute skipwhite
syn match sassVariableAssignment "\%([!$][[:alnum:]_-]\+\s*\)\@<=:" nextgroup=sassCssAttribute skipwhite
syn match sassFunction "\<\%(rgb\|rgba\|red\|green\|blue\|mix\)\>(\@=" contained
syn match sassFunction "\<\%(hsl\|hsla\|hue\|saturation\|lightness\|adjust-hue\|lighten\|darken\|saturate\|desaturate\|grayscale\|complement\)\>(\@=" contained
syn match sassFunction "\<\%(alpha\|opacity\|rgba\|opacify\|fade-in\|transparentize\|fade-out\)\>(\@=" contained
syn match sassFunction "\<\%(unquote\|quote\)\>(\@=" contained
syn match sassFunction "\<\%(percentage\|round\|ceil\|floor\|abs\)\>(\@=" contained
syn match sassFunction "\<\%(type-of\|unit\|unitless\|comparable\)\>(\@=" contained
syn region sassInterpolation matchgroup=sassInterpolationDelimiter start="#{" end="}" contains=@sassCssAttributes,sassVariable,sassFunction containedin=cssStringQ,cssStringQQ,sassProperty
syn match sassMixinName "[[:alnum:]_-]\+" contained nextgroup=sassCssAttribute
syn match sassMixin "^=" nextgroup=sassMixinName
syn match sassMixin "\%([{};]\s*\|^\s*\)\@<=@mixin" nextgroup=sassMixinName skipwhite
syn match sassMixing "^\s\+\zs+" nextgroup=sassMixinName
syn match sassMixing "\%([{};]\s*\|^\s*\)\@<=@include" nextgroup=sassMixinName skipwhite
syn match sassExtend "\%([{};]\s*\|^\s*\)\@<=@extend"
syn match sassEscape "^\s*\zs\\"
syn match sassIdChar "#[[:alnum:]_-]\@=" nextgroup=sassId
syn match sassId "[[:alnum:]_-]\+" contained
syn match sassClassChar "\.[[:alnum:]_-]\@=" nextgroup=sassClass
syn match sassClass "[[:alnum:]_-]\+" contained
syn match sassAmpersand "&"
" TODO: Attribute namespaces
" TODO: Arithmetic (including strings and concatenation)
syn region sassInclude start="@import" end=";\|$" contains=scssComment,cssURL,cssUnicodeEscape,cssMediaType
syn region sassDebugLine end=";\|$" matchgroup=sassDebug start="@debug\>" contains=@sassCssAttributes,sassVariable,sassFunction
syn region sassWarnLine end=";\|$" matchgroup=sassWarn start="@warn\>" contains=@sassCssAttributes,sassVariable,sassFunction
syn region sassControlLine matchgroup=sassControl start="@\%(if\|else\%(\s\+if\)\=\|while\|for\)\>" end="[{};]\@=\|$" contains=sassFor,@sassCssAttributes,sassVariable,sassFunction
syn keyword sassFor from to through contained
syn keyword sassTodo FIXME NOTE TODO OPTIMIZE XXX contained
syn region sassComment start="^\z(\s*\)//" end="^\%(\z1 \)\@!" contains=sassTodo,@Spell
syn region sassCssComment start="^\z(\s*\)/\*" end="^\%(\z1 \)\@!" contains=sassTodo,@Spell
hi def link sassCssComment sassComment
hi def link sassComment Comment
hi def link sassDefault cssImportant
hi def link sassVariable Identifier
hi def link sassFunction Function
hi def link sassMixing PreProc
hi def link sassMixin PreProc
hi def link sassExtend PreProc
hi def link sassTodo Todo
hi def link sassInclude Include
hi def link sassDebug sassControl
hi def link sassWarn sassControl
hi def link sassControl PreProc
hi def link sassFor PreProc
hi def link sassEscape Special
hi def link sassIdChar Special
hi def link sassClassChar Special
hi def link sassInterpolationDelimiter Delimiter
hi def link sassAmpersand Character
hi def link sassId Identifier
hi def link sassClass Type
let b:current_syntax = "sass"
" vim:set sw=2:

20
vim/syntax/scss.vim Normal file
View file

@ -0,0 +1,20 @@
" Vim syntax file
" Language: SCSS
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" Filenames: *.scss
" Last Change: 2010 Jul 26
if exists("b:current_syntax")
finish
endif
runtime! syntax/sass.vim
syn match scssComment "//.*" contains=sassTodo,@Spell
syn region scssComment start="/\*" end="\*/" contains=sassTodo,@Spell
hi def link scssComment sassComment
let b:current_syntax = "scss"
" vim:set sw=2:

87
vim/syntax/textile.vim Normal file
View file

@ -0,0 +1,87 @@
"
" You will have to restart vim for this to take effect. In any case
" it is a good idea to read ":he new-filetype" so that you know what
" is going on, and why the above lines work.
"
" Written originally by Dominic Mitchell, Jan 2006.
" happygiraffe.net
"
" Modified by Aaron Bieber, May 2007.
" blog.aaronbieber.com
"
" Modified by Tim Harper, July 2008 - current
" tim.theenchanter.com
" @(#) $Id$
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
" Textile commands like "h1" are case sensitive, AFAIK.
syn case match
" Textile syntax: <http://textism.com/tools/textile/>
" Inline elements.
syn match txtEmphasis /_[^_]\+_/
syn match txtBold /\*[^*]\+\*/
syn match txtCite /??.\+??/
syn match txtDeleted /-[^-]\+-/
syn match txtInserted /+[^+]\++/
syn match txtSuper /\^[^^]\+\^/
syn match txtSub /\~[^~]\+\~/
syn match txtSpan /%[^%]\+%/
syn match txtFootnoteRef /\[[0-9]\+]/
syn match txtCode /@[^@]\+@/
" Block elements.
syn match txtHeader /^h1\. .\+/
syn match txtHeader2 /^h2\. .\+/
syn match txtHeader3 /^h[3-6]\..\+/
syn match txtBlockquote /^bq\./
syn match txtFootnoteDef /^fn[0-9]\+\./
syn match txtListBullet /\v^\*+ /
syn match txtListBullet2 /\v^(\*\*)+ /
syn match txtListNumber /\v^#+ /
syn match txtListNumber2 /\v^(##)+ /
syn cluster txtBlockElement contains=txtHeader,txtBlockElement,txtFootnoteDef,txtListBullet,txtListNumber
" Everything after the first colon is from RFC 2396, with extra
" backslashes to keep vim happy... Original:
" ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
"
" Revised the pattern to exclude spaces from the URL portion of the
" pattern. Aaron Bieber, 2007.
syn match txtLink /"[^"]\+":\(\([^:\/?# ]\+\):\)\?\(\/\/\([^\/?# ]*\)\)\?\([^?# ]*\)\(?\([^# ]*\)\)\?\(#\([^ ]*\)\)\?/
syn cluster txtInlineElement contains=txtEmphasis,txtBold,txtCite,txtDeleted,txtInserted,txtSuper,txtSub,txtSpan
if version >= 508 || !exists("did_txt_syn_inits")
if version < 508
let did_txt_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink txtHeader Title
HiLink txtHeader2 Question
HiLink txtHeader3 Statement
HiLink txtBlockquote Comment
HiLink txtListBullet Operator
HiLink txtListBullet2 Constant
HiLink txtListNumber Operator
HiLink txtListNumber2 Constant
HiLink txtLink String
HiLink txtCode Identifier
hi def txtEmphasis term=underline cterm=underline gui=italic
hi def txtBold term=bold cterm=bold gui=bold
delcommand HiLink
endif
" vim: set ai et sw=4 :

35
vim/syntax/treetop.vim Normal file
View file

@ -0,0 +1,35 @@
" treetop.vim
" syntax file for treetop.
" Author: NANKI Haruo.
let b:ruby_no_expensive=1
syntax match ttOperators /[&~!*+?\/]/
syntax keyword ttDefine end
syntax keyword ttKeywords include super
syntax match ttComment /#.*$/
syntax match ttName /\w\+/ contained
syntax match ttDefine "\<\(module\|grammar\|rule\)\>" nextgroup=ttName skipwhite skipnl
syntax match ttTag /\w\+\%(:\)/
syntax include @Ruby syntax/ruby.vim
syntax region BlockRuby matchgroup=ttQuote start=/{/ end=/^\s*}$/ transparent contains=@Ruby
syntax region ttPattern matchgroup=ttQuote start=/\[/ end=/\]/
syntax region ttString matchgroup=ttQuote start=/'/ end=/'/
syntax region ttString matchgroup=ttQuote start=/"/ end=/"/
syntax region ttClass matchgroup=ttQuote start=/</ end=/>/
highlight link ttQuote Delimiter
highlight link ttString String
highlight link ttPattern String
highlight link ttDefine Define
highlight link ttKeywords Statement
highlight link ttName Identifier
highlight link ttClass Constant
highlight link ttOperators Operator
highlight link ttComment Comment
highlight link ttTag Type

185
vim/vimrc Normal file
View file

@ -0,0 +1,185 @@
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" don't allow backspacing over everything in insert mode
set backspace=
set nobackup
set nowritebackup
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Don't use Ex mode, use Q for formatting
map Q gq
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
set nohlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" if has("folding")
" set foldenable
" set foldmethod=syntax
" set foldlevel=1
" set foldnestmax=2
" set foldtext=strpart(getline(v:foldstart),0,50).'\ ...\ '.substitute(getline(v:foldend),'^[\ #]*','','g').'\ '
" endif
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
" Always display the status line
set laststatus=2
" <Space> is the leader character
let mapleader = " "
" Edit the README_FOR_APP (makes :R commands work)
map <Leader>R :e doc/README_FOR_APP<CR>
" Hide search highlighting
map <Leader>l :set invhls <CR>
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
map <Leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
map <Leader>te :tabe <C-R>=expand("%:p:h") . "/" <CR>
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
" Maps autocomplete to tab
imap <Tab> <C-P>
" Duplicate a selection
" Visual mode: D
vmap D y'>p
" No Help, please
nmap <F1> <Esc>
" Press Shift+P while in visual mode to replace the selection without
" overwriting the default register
vmap P p :call setreg('"', getreg('0')) <CR>
" Display extra whitespace
set list listchars=tab:»·,trail
" Edit routes
command! Rroutes :e config/routes.rb
command! RTroutes :tabe config/routes.rb
" Local config
if filereadable(".vimrc.local")
source .vimrc.local
endif
" Use Ack instead of Grep when available
if executable("ack")
set grepprg=ack\ -H\ --nogroup\ --nocolor
endif
" Color scheme
colorscheme vividchalk
highlight NonText guibg=#060606
highlight Folded guibg=#0A0A0A guifg=#9090D0
" Numbers
set number
set numberwidth=5
" Snippets are activated by Shift+Tab
let g:snippetsEmu_key = "<S-Tab>"
" Tab completion options
set wildmode=list:longest,list:full
set complete=.,w,t
" Tags
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'"
" Window navigation
nmap <C-J> <C-W><C-J>
nmap <C-K> <C-W><C-K>
" Rails configuration
autocmd User Rails Rnavcommand step features/step_definitions -glob=**/* -suffix=_steps.rb
autocmd User Rails Rnavcommand config config -glob=**/* -suffix=.rb -default=routes
nmap <Leader>p :Rstep
nmap <Leader>sp :RSstep
nmap <Leader>tp :RTstep
nmap <Leader>m :Rmodel
nmap <Leader>c :Rcontroller
nmap <Leader>v :Rview
nmap <Leader>u :Runittest
nmap <Leader>f :Rfunctionaltest
nmap <Leader>i :Rintegrationtest
nmap <Leader>h :Rhelper
nmap <Leader>tm :RTmodel
nmap <Leader>tc :RTcontroller
nmap <Leader>tv :RTview
nmap <Leader>tu :RTunittest
nmap <Leader>tf :RTfunctionaltest
nmap <Leader>ti :RTintegrationtest
nmap <Leader>sm :RSmodel
nmap <Leader>sc :RScontroller
nmap <Leader>sv :RSview
nmap <Leader>su :RSunittest
nmap <Leader>sf :RSfunctionaltest
nmap <Leader>si :RSintegrationtest
nmap <Leader>g :Rconfig
nmap <Leader>sg :RSconfig
nmap <Leader>tg :RTconfig
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>

83
vimrc Normal file
View file

@ -0,0 +1,83 @@
set nocompatible " Use Vim settings, rather then Vi settings
set backspace= " don't allow backspacing over everything in insert mode
set nobackup
set nowritebackup
set history=50
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set laststatus=2 " Always display the status line
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if (&t_Co > 2 || has("gui_running")) && !exists("syntax_on")
syntax on
endif
filetype plugin indent on
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
" Display extra whitespace
set list listchars=tab:»·,trail
" Local config
if filereadable(".vimrc.local")
source .vimrc.local
endif
" Use Ack instead of Grep when available
if executable("ack")
set grepprg=ack\ -H\ --nogroup\ --nocolor
endif
" Color scheme
colorscheme vividchalk
highlight NonText guibg=#060606
highlight Folded guibg=#0A0A0A guifg=#9090D0
" Numbers
set number
set numberwidth=5
" Snippets are activated by Shift+Tab
let g:snippetsEmu_key = "<S-Tab>"
" Tab completion options
set wildmode=list:longest,list:full
set complete=.,w,t
" Tags
let g:Tlist_Ctags_Cmd="ctags --exclude='*.js'"
" Cucumber navigation commands
autocmd User Rails Rnavcommand step features/step_definitions -glob=**/* -suffix=_steps.rb
autocmd User Rails Rnavcommand config config -glob=**/* -suffix=.rb -default=routes
" Get off my lawn
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>
" Treat <li> and <p> tags like the block tags they are
let g:html_indent_tags = 'li\|p'