Luc Hermitte's VIM Macros | Monday 22nd November 2004 |
As my mappings are some how a bit more complex than similar ones you could found elsewhere, I tried to explain them as much as I could. First you will find some notes about my general configuration for my environments. BTW, there are some notes on how to emulate the (ft)plugins mechanism with VIM 5.x. Then, I present my plugins (general scripts) and my ftplugins.
Some scripts are still compatible with versions 5.x and 6.x of Vim.
Regarding the files, in the following, two versions of each file are provided : a nice and colored one and a plain text one. If you want to use my macros, you will have to download the later ones. Indeed, the graphically enhanced version of the files loose every escape sequences, and some script still have some. Note that my scripts often rely on other ones. You will have to check the dependencies when downloading them. However, you will find in ressources/ some thematic (C&C++, e-mail, LaTeX, template-expander, etc.) tarball-archives already prepared. You can also check file by file what is present is this directory. BTW, this site can sometimes be particulary slow and difficult to contact. So be patient and try again. Last thing, many macros could be improved. If you have any idea, suggestion, please feel free to send me an e-mail. even to criticize my English. |
|
Enfin, dernier truc. Vu que j'ai beaucoup de choses à décrire et à proposer -- et qu'il n'est déjà pas évident d'être à jour --, cette page ne sera maintenue qu'en anglais uniquement.
My Installation and configuration
I have been using VIM on different types of architectures : under Sun/Solaris/*sh, under a PC/WindowsNT/zsh, under a PC/WindowsMillenium/ + Cygwin, under a PC/WindowsXP/ + Cygwin, and under a GNU/Linux Debian box.
Instead of managing a .vimrc
and a _vimrc
file,
they both are very short and source a common file :
vimrc_core.vim
On my hard drives, I have VIM 6.3, and I used to have VIM 5.7. Hence I have
isolated some stuff really common to both versions in my
$VIM/
, move VIM 5.7 stuff to $VIM/vim57/
and put
VIM 6.x specific stuff into $HOME/vimfiles/
(or what stands for it ; check
«:h 'runtimepath'
»).
This looks like this :
$VIM/ +--> plugin/ # plugins common to both versions of VIM +--> macros/ # macros common to both versions of VIM +--> vim57/ # initial $VIMRUNTIME for VIM 5.7 | +--> ftplugin/ # used to be my settings/ folder | +--> ... # default installation +--> vim63/ # initial $VIMRUNTIME for VIM 6.3 | +--> ... # default installation +--> vimrc_core.vim # I reckon it has nothing to do here +--> _vimrc_nix/win # special initialisations for *NIX / Ms-Windows +--> _gvimrc $HOME/vimfiles/ # personnal stuff for VIM 6.x +--> ... # default hierarchy, filled with my scripts
_vimrc <raw file> |
Example of a very succinct .vimrc file. |
|
vimrc_core.vim <raw file> help on : <S-F1>
|
The main file that contains all the mappings. It relies on two plugins : runtime.vim :
required!, and
help.vim : facultative.
|
|
_vimrc_nix <raw file> |
Some customizations for *NIX environments ; mainly keycodes remappings for my putty terminal. | |
_vimrc_win <raw file> |
Some customizations for Ms-Windows environments. | |
_gvimrc <raw file> |
Some stuff to load only when GUI is enabled. | |
myfiletypes.vim <raw file> |
Some custom filetypes. | |
cyg-wrapper.sh | This shell script combined, with the alias:
alias gvim='cyg-wrapper.sh "C:/Progra~1/Edition/vim/vim63/gvim.exe" -c', wraps VIM calls when the current *NIX environement is cygwin -- and the VIM version: a plain win32 executable like the default release for windows systems, or the one available on Cream web site. Indeed, cygwin is strictly unable to send correct (i.e. PC-ish) path names to VIM. If you have ever tried to type "gvim /etc/profile" or "gvim file-that-is-a-sym-link" from cygwin/bash, then I'm sure you see what I mean and why you definitively need this shell script. |
Some more explanations
vimrc_core.vim
vimrc_core.vim
corresponds to my .vimrc
. I gave it
another name in order to keep my .vimrc
and
_vimrc
short and always uptodate.
It sources _vimrc_nix
or _vimrc_win
regarding the
current environnement.
I will not detail every mapping or abbreviation defined, they are very
classical. Actually many are not mine at all and come from the
Sven Guckes's .vimrc
. If you want a short description of the
definitions, source the file and then hit <S-F1>
(if you have installed
help.vim
).
But it also contains many initialisations used for different (ft)plugins I use :
:runtime
extended to VIM 5.x) &
runtimepath
personal configuration.
File Type plugins with VIM v5.x
This paragraph only concerns those who want to emulate the file type plugins mechanism with version of VIM prior to the version 6.
In a few words, what I've understood of this new feature is that it enables
to easily load (source) VIM files -- containing functions, mappings and
other customizations -- and associate its definitions to a buffer regarding
the filetype of what is edited within the buffer.
Thus, it enables to define completely redundant mappings and associate them
to different filetypes. For instance, the mapping of if
could
be expanded to if<cr>endif
when editing VIM script files,
to if () {<cr>}
when editing C/C++/Java files, and not
defined at all when editing HTML files.
There is no further need to define everything within the .vimrc
file -- note also that writing all the autocommands within the
.vimrc
file obfuscates it and causes (me) headaches while it
increases the complexity the maintenance of the whole stuff.
The filetypes plugins mechanism is thus very useful but it was not present in VIM until the version 6. Follows a way to emulate this feature with the previous versions of our favorite editor. What I propose seems to work since the version 5.6 and may be the previous ones -- don't remember.
The first smart thing to do is to split all the definitions regarding the
filetype of the edited buffers ; it is a matter of clarity. Then quickly,
several files emerge. One for LaTeX editing, one for HTML editing, one for C
editing, and so on.
As the .vim
extension is already used by the syntax
files, I gave another extension to these files in order not to mess
things up when managing completely different files. Years ago, I chose
.set
that stands for setting files. It is not perfect
but at least I can't mix them up.
The second not so smart thing not to do is to load these files from
syntax files : when VIM is upgraded from ver 5.x to 5.x+1,
the syntax files are overloaded and all the modifications are lost.
A far more better solution is to add corresponding autocommands to the
.vimrc
. But, it is not said that filetypes defined within
filetype.vim
and myfiletype.vim
are consistent
with the autocommands present within .vimrc
.
I opted for a solution directly inspired from the one adopted with syntax
files. I copied and adapted syntaxfile.vim
into
mysettingfile.vim
.
At first, it defines a command SetAuQuick
that will ease the
writing of all the autocommands.
command -nargs=1 SetAuQuick au Syntax <args> so $VIMRUNTIME/settings/<args>.setThen, for each filetype we have a dedicated macros file, the only thing to do is to call the command for the specific filetype. For instance, for e-mails composition, the line is :
SetAuQuick mailNo more need to know exactly the definition of the filetype pattern.
Of course, this new file has to be called. I am not sure is it the better
place, but I chose to source it just after the syntax activation command :
syntax
on
from my .vimrc
(actually it is vimrc_core.vim
in my configuration).
Unfortunately my trick is not activated when the syntax colorization is
off. If you have any idea in order to enhance this, please let me know !
At this point, every thing is nice until different types of buffers are loaded within the same VIM session. It becomes very annoying when VIM complains about redundant or inconsistent mappings. I observed this behavior a lot of times mainly when I want to update my set of abbreviations and mistyping corrections from the same session than my LaTeX one, or when I generate HTML files corresponding to different kind of source files (with 2HTML).
In order to correct this, the mapping abbreviations and other stuffs must
become buffer relative. I found the solution to this issue thanks to the
wonderful scripts buffoption.vim
from Michael Geddes.
Using my scripts, the command to use in order to issue buffer relative
loading of pseuso-ftplugins is SetAu
. After a caching
operation, the command issue a call to ReadFileTypeMap()
. If
you look closely at my mysettingfile.vim
, you will notice that
I load my e-mails composing plugins with SetAuQuick
; I
consider that it is very unlikely to mix e-mail with any other kind of
files.
Regarding buffoption.vim
, you will be able to found the latest
version on sourceforge. I
understood that it enable to use the new form of mapping (with the
<buffer>
tag) and thus
load real ftplugins files with VIM v5.x ; I haven't tested it until now.
Nevertheless, I proposed a little patch
over an older version of the script. The patch focuses on several issues :
noremap
, noreab
and
noremenu
commands,
FileType__ExeLine(...)
,
Last note : there are some drawbacks either inherent to the technique used or because I miss things (I guess that I missed something regarding syntax on or off). The points are :
common_brackets.vim
do not work properly when switching
buffers. From my point of view, this incompatibility with
Triggers.vim
is a real issue.
<buffer>
tags). In
order to do so, I will have to merge the latest
buffoptions.vim
from Michael Geddes with my patch. But
well ... I lack time and by then I think that I will have definitively
moved to the version 6.
mysettingfile.vim <raw file> Warning: filemtime() [function.filemtime]: Stat failed for ../vim/ressources/dollar_VIM/mysettingfile.vim (errno=2 - No such file or directory) in /mnt/133/sdb/f/b/hermitte/vim/dateOfScript.php on line 3 1st January 1970 |
file in charge of the loading of the right script file according to the filetype of the buffer to be edited |
buffoptions2.vim <raw file> Warning: filemtime() [function.filemtime]: Stat failed for ../vim/ressources/dollar_VIM/vim57/macros/buffoptions2.vim (errno=2 - No such file or directory) in /mnt/133/sdb/f/b/hermitte/vim/dateOfScript.php on line 3 1st January 1970 buffoptions_mac2.vim <raw file> Warning: filemtime() [function.filemtime]: Stat failed for ../vim/ressources/dollar_VIM/vim57/macros/buffoptions_mac2.vim (errno=2 - No such file or directory) in /mnt/133/sdb/f/b/hermitte/vim/dateOfScript.php on line 3 1st January 1970 |
files that enable to operate buffer relative loading of scripts |
vimrc_core.vim |
the root file (.vimrc ) in charge of loading
mysettingfile.vim |
Plugins: General purpose macros
Here are several script files that I've put in $VIM/plugin/
. They can be used with both
versions of VIM.
help.vim <raw file> |
This little file helps to prepare help messages and to map
them to a sequence of keys. I use it to comment my mappings.
Then, I hit <S-F1> for example
and see all the mappings that I have defined in
vimrc_core.vim .
|
|
fileuptodate.vim <raw file> |
Tool for plugins programmers This file defines a little function that helps to determine if a file exists and is more recent than an other file. Needed by my patch for buffoptions.vim and for Triggers.vim .
|
|
ensure_path.vim <raw file> |
Tool for plugins programmers Defines the function EnsurePath({path})
that checks if its parameter points to a valid directory. If it
points to a file, an error is raised ; if it points to nothing,
the directory is created.
system_utils.vim .
|
|
fix_d_name.vim <raw file> |
Tool for plugins programmers Defines the function FixDname({path}) that returns a corrected
pathname respecting the value of the 'shellslash' option.
The objective is to propose a portable help to access
files or directories.
It has been tested so far on the following configurations PC/WinMe+command.com, PC/WinME+Cygwin_bash, PC/WinNT+cmd32, PC/WinNT+unixtools_zsh, Sun/Solaris/tcsh.
system_utils.vim .
|
|
words_tools.vim <raw file> |
Tool for plugins programmers This file defines the four alternative functions to use instead of expand("<cword>")
|
|
Triggers.vim <raw file> Archive with required files: triggers.tar.gz |
Plugin that can toggle almost anything This big file helps to toggle definitions -- these definitions corresponding to either mappings, settings or abbreviations. The very simple application is to map (/ unmap) a macro when we hit (/re-hit) the trigger. A much more useful application is to map all the definitions from a function when hitting the trigger and unload them on a second hit and reload on a third, etc.. You can find an application of this with my shortcut file: fr-abbrv.vim present in the tarball archive.For the moment, I have still a little incompatibility problem with buffoptions2.vim Do not forget to customize Trigger_FileName({funcname}) in
regards of your installation.
Requires: system_utils.vim and
fileuptodate.vim .
|
|
misc_map.vim <raw file> |
Tool for plugins programmers This file defines the function MapNoContext({key},
{seq}) . This is required by several
other ftplugins of mine, like vim_set.vim , in
order to define smart mappings. The aim is for example to map
if to if<CR>endif only out of
comment zones and strings. It also define a function that ease
the definition of visual mappings.This plugin is shipped with lh-map-tools.tar.gz.
|
|
let-modeline.vim <raw file> let-modeline.vim <raw file> |
Extended Modelines. This file defines the function FirstModeLine() .
It extends VIM's modeline feature (restricted to options
settings) to affectations of variables --
let <variable> = <value>This is only required by my LaTeX ftplugins but could be very useful to any other file edited.
|
|
block-indent.vim <raw file> |
Quick reindentation This plugin redefines some keys in order in re-indent different things.
|
And here are my plugins that will only work with VIM 6.0, they go into
$HOME/vimfiles/plugin/
vim-spell.tar.gz
Vim help file: VS_help.txt |
Spell checker plugin for VIM. It wraps external tools like Ispell or Aspell and offers many interesting features. Requires: system_utils.vim .
|
|
searchInRuntime.vim <raw file> Vim help file: searchInRuntime.txt Archive with help: searchInRuntime.tar.gz |
This plugin defines three commands that search for files in
a list of directories like $PATH or 'runtimepath' , and execute a
command on them.
|
|
system_utils.vim <raw file> Vim help file: system_utils.txt Archive with help: system_utils.tar.gz |
Tool for plugins programmers The objective is to propose a portable set of functions: - to handle files and directories, - and to change the shell used on MsWindows boxes. 99% of this plugin can be seen as an API meant to help us writing portable VimL scripts. The script defines the functions:
|
|
menu-map.vim <raw file> |
Tool for plugins programmers This plugin defines functions to build mappings and menus at the same time ; the key-binding of the mappings being recalled within the menu. My ftplugins expect this file to be into the {rtp}/macros/
directory.
|
|
homeLikeVC++.vim <raw file> |
Smart <Home> key This plugin redefines <Home> to behave like it does
with Ms-VisualC++: Hitting <Home> once moves the cursor
to the first non blank character of the line ; twice: to the
first column of the line.I.e.: the position of the cursor is toggled between the first column and the first non blank character of the line. |
|
local_vimrc.vim <raw file> |
This plugin recursively sources files named
_vimrc_local.vim from $HOME to the current directory.
Note: the name of the files sourced can be overriden thanks to: g:local_vimrc .
|
|
compiler/
cygwin.vim <raw file> Perl filter: cygwin.pl Archive: compiler-cygwin.tar.gz |
Compiler plugin for Cygwin. This compiler-plugin translates the paths from error messages expressed in *nix form into MsWindows form. It is meant to make the cohabition between Cygwin's make and the win32 native version of Vim
painless.Reason: the filenames (for whom GCC reports errors) are expressed in the UNIX form, and Vim is unable to open them from the quickfix window. Hence the filtering used to replace / (root) by $(cygpath -m /) ,
/cygdrive/{drive}/ by
{drive}:/ , and to follow symbolic links.
In order to correctly recognize Cygwin, $TERM or $OSTYPE should value "cygwin". The plugin comes in two parts: the main VimL script and an external Perl filter. However, if you do not have Perl installed on your box, you will find within the main script a tricky method you should be able to use: comment the part of the code that configure the tool to use the Perl filter, and comment the calls to :finish .
|
The functions defined in this file serve a very simple purpose: to
associate to an identifier a set of line describing any thing one wants to.
The best example of one application could be found in
vimrc_core.vim
.
At first, an identifier must be reserved with
ClearHelp({id})
. [Internals: the global variable
g:{id}_help
is reset and will be used in the
following steps]
Then, all the help lines can be added thanks to
BuildHelp({id},{line})
.
Finally, all the lines can be echoed with
ShowHelp({id})
. Personally, for vimrc
I
use the mapping:
noremap <S-F1>:call ShowHelp("vimrc")<cr>
This file defines the function:
IfFileUpToDate({f1},{f2})
. Its raison
d'être is to test dependencies between files: it checks whether
{f2} is more recent than {f1} which is useful when
{f2} depends on {f1}.
The function returns:
Proposes a command and a function that make sure a directory exists. If the directory didn't exist before the call, it is created. If the parent directories of the required directory do not exist, they are created in the way.
Tested on:
mkdir
here), be sure to have your
$PATH correctly set.
The function FixDname({path})
will correct the
{path}
passed in parameter so that
it will be usable will external tools. Under Win32 boxes, it will build the
new path according to the value of 'shellslash'
, under other boxes, the new
path will be exclusively composed of forward slashes. NB: I suppose that
'shellslash'
is defined
accordingly to the current shell used (bash, command.com, cmd32, tcsh,
etc.).
For instance, "c:\Program
Files/longpathname/some\ spaces/foo"
will be corrected
into:
"c:\Program
Files\longpathname\some spaces\foo
under win32 systems
when 'shellslash'
equals 1,
or into:
"c:/Program\
Files/longpathname/some\ spaces/foo
otherwise.
Until now, I have use this function in two ways:
exe ":!cp
" .escape(FixDname('very odd/path/file.ext'), '\'). "
destination"
call system( a_command . '
' . FixDname(somepath))
Unfortunately, the new path constructed:
filereadable()
as this function expects a
path expressed with forward slashes only ;
If you try to expand "<cword>"
in order to get the word
just before the cursor, you won't success: you will instead get the word
after the cursor. It is very problematic when we try to define
completion-oriented macros.
So, this file defines the functions: GetPreviousWord()
,
GetCurrentWord()
, GetNearestWord()
,
GetCurrentKeyword()
, GetNearestKeyword()
, and
GetLikeCTRL_W()
to be used instead of expand("<cword>")
. These functions cover
different needs:
GetPreviousWord()
returns the first characters from
the word located before the cursor ; actually, the word is either
truncated at the cursor's position or completed by as many spaces
as needed to reach this position. I call «word» a sequence of
keyword characters: "\k"
, see :h
isk
.function! Parent() let w = GetPreviousWord() if w =~ '^if\s*$' return "\<esc>bcwif () {\<cr>}\<esc>O" eleif w =~ '^for\s*$' return "\<esc>bcwfor (;;) {\<cr>}\<esc>O" else return "" endif endfunction inoremap ( <c-r>=Parent()<cr>But, it is IMHO more interesting to use it to correct frequent misspellings. May be, it could be interesting to skip all the ending spaces in future versions ; this way, it will be very easy to implement an automatic completion behaving like
<tab>
in many
environments like bash or VIM.
GetCurrentWord()
returns the complete word just
before the cursor, without any bonus space. If a white space
precedes the current cursor's position, an empty string is
returned. This time, a word is defined as sequence of
non-white-space characters: "\S"
;
GetCurrentKeyword()
works of keyword characters.
It comes handy to implement automatic completion like the one
of Zsh. Actually, I use this function in
Mail_mutt_alias_set.vim
to expand regular expressions into e-mail addresses.
GetNearestWord()
returns the complete word (sequence
of "\S"
; GetNearestKeyword()
works on
"\k"
) near the cursor's position: i.e.
just after, just before or around the cursor's position.
GetLikeCTRL_W()
returns the string that would have
been deleted by i_CTRL_W
.
In order to have a better idea of what is returned by these functions, here
is a little table that shows the results from the different functions
regarding the position of the cursor.
Let's use ^
, $
and |
as possible
cursor's positions in INSERT-mode, ×
to represent a
white-space ; while WORD1
and WORD2
are two
already typed words. The table is filled with the evaluations of the
functions on this line.
×^W|o|r|d|1$×^W|o|r|d|2$×|×|×|×...
1st^ |
1st| |
2nd| |
3th| |
4th| |
1st$ |
2nd^ |
5th| |
6th| |
7th| |
8th| |
2nd$ |
nth| |
|
expand("<cword>") |
«Word1» | «Word1» | «Word1» | «Word1» | «Word1» | «Word2» | «Word2» | «Word2» | «Word2» | «Word2» | «Word2» | Ø | Ø |
GetPreviousWord() |
Ø | «W» | «Wo» | «Wor» | «Word» | «Word1» | «Word1×» | «W» | «Wo» | «Wor» | «Word» | «Word2» | «Word2×××» |
GetCurrentWord() |
Ø | «Word1» | «Word1» | «Word1» | «Word1» | «Word1» | Ø | «Word2» | «Word2» | «Word2» | «Word2» | «Word2» | Ø |
GetNearestWord() |
«Word1» | «Word1» | «Word1» | «Word1» | «Word1» | «Word1» | «Word2» | «Word2» | «Word2» | «Word2» | «Word2» | «Word2» | Ø |
These functions are just examples of want could be done on this topic. They
just fulfill some specific needs I had. There are several ways to
define/customize such kind of functions regarding if we want the word
preceding or following the cursor, if we want it in its entirety, if a
word is defined by "\k*"
or "\S*"
, and so on.
Triggers.vim
Here is a big piece of cake. The purpose of Triggers.vim
is
very simple: to ease the association of a key to the activation and
deactivation of a set of macros. Some of you already knows what
inoremap <F7>:set ai!<cr>:set ai?<cr>does: hitting
<F7>
toggles
the activation state of the autoindent
option and echoes it.
Triggers.vim
provides a set of functions that extends such
behavior to mappings, abbreviations and non boolean VIM-options.
Here are some examples of its applications:
call Trigger_Define('<F7>', 'set
ai')
does exactly the
same thing than the previous example.
call Trigger_Define('<F4>', 'set
tw=120 sw^=2')
records the current values of textwidth
and
shiftwidth
, then defines <F4>
as the trigger key that will
turn after turn set textwidth
and
shiftwidth
to their new values then restore them to
the initial ones.
call Trigger_Define('<F4>', 'set
tw+=80')
works
slightly differently: it does not record the initial value but
apply set tw-=80
as
the inverse operation. Thus, :set tw=100<cr><F4><F4>:echo &tw<cr>
will always echo 100.
call Trigger_Define('<F9>', 'inoremap
{ {}<Left>')
is very useful to me:
when I want to insert a block, I make sure that the open
curly-bracket also insert its counterpart ; and when I only want the
open curly-bracket, I deactivate the mapping thanks to <F9>
and re-activate it
afterward.
call Trigger_Define('<F3>', 'iab
LU Last Update:')
is
also supported and could be useful when doing Linear Algebra... Ok!
Ok! This is not a very good example, but I'm sure you see what I
mean.
source myAbbrevAndMap.vim
call Trigger_Function('<F3>', 'MyAbbrevs', 'myAbbrevAndMap.vim')
is may be the more
useful application of the plugin. Let's say you have a file
named myAbbrevAndMap.vim
which defines the
parameter-less function MyAbbrevs()
.
Trigger_Function(...)
is designed to activate and
deactivate every mapping, abbreviation and option setting
contained in the specified function. Actually, it defines the
inverse function (that will be written in the folder
$VIMRUNTIME/.triggers
; so
make sure it exists !) and hitting the trigger key will call turn
after turn either MyAbbrevs()
or its inverse.
Incidentally, all other VIM code is ignore and copied as it is in
the inverse operation. Take a look at
common_brackets.vim
exe 'noremap foo1
foo2'
. And thus, the mappings (from
misc_map.vim
) on
<
and >
are not necessarily
deactivable when defined with b:cb_ltFn
and
b:cb_gtFn
.
TRIGGER "echo 'foo ON'", "echo 'foo OFF'"
: this new command is
designed to be used within functions to be inversed with
Trigger_Function(...)
. Its opposite is itself, but
with the order of its two parameters inversed. Quite useful
for echoing. Beware, the double quotes must be around the single
ones in the case of echo
.
call
Trigger_DoSwitch('<M-F9>', 'let b:usemarks=1', 'let b:usemarks=0')
: can be useful for
mappings that have nothing to do with options-settings, mappings or
abbreviations.
If you are interested in more precise information like syntax variations,
report to the comments within the plugin.
misc_map.vim
This plugin defines several functions and commands to be used when you want to program mappings and abbreviations:
"inoremap if<space> <C-R>=MapNoContext( 'if ', Inoreabbr if <C-R>=MapNoContext( 'if ', \ '\<c-f\>if () {\<cr\>}\<esc\>?)\<cr\>i')<CR>If you are interested in other applications, take a look at my ftplugins.
Regarding the difference between the two functions, if you are up to
use variables like tarif
, you actually need to use the
second form of the function. Indeed, if the character before the cursor
is a keyword character, the key is returned instead of the
interpreted {sequence} ; cf.
:h 'iskeyword'
for more
information about keyword characters.
Reserve the first form of the function to "keyword-less" keys like
{
for instance.
Regarding the format of the {sequence} to
interpret, every special character must see its greater-than
and lesser-than symbols escaped with backslash. Thus
<esc>
becomes for
instance \<esc\>
.
{begin}
is added before the
selection while {end}
is added
just after. The function accepts two options that indicates whether the
mapping should be line wise and whether the selected text should be
indented.
At this time, it is only used in tex_set.vim
in order to define things like:
vnoremap ]ec :call MapAroundVisualLines('\begin{center}', \ '\end{center}',1,1)<cr>It also fits perfectly to define the C&co. dedicated visual mapping:
vnoremap ,else :call MapAroundVisualLines('else {', '}',1,1)<cr>
Rem.: there still are problems with the indenting and more precisely
when a text is smartindented under VIM 5.xx ; it seems to work fine
with VIM 6.0.
BTW, never use stuff that could be expanded as an abbreviation within
{begin}
or {end}
. Unless you like oddities.
¡.*!
and build a string that can be used as second
parameter by the MapNoContext()
functions. The expanded
mappings are considered to be dedicated to the INSERT mode. bracketing.base.vim
) within context-dependant macros.
For the moment, it is only used from c_set.vim. For instance, I mapped the C structure, for
, to:
"inoremap for<space> <C-R>=Def_Map( Inoreabbr for <C-R>=Def_Map( \ 'for', \ '\<c-f\>for (;;) {\<cr\>}\<esc\>?(\<cr\>a', \ '\<c-f\>for (;¡mark!;¡mark!) {\<cr\>¡mark!\<cr\>}¡mark!\<esc\>?(\<CR\>a')<cr> function! Def_Map(key,expr1,expr2) if exists('b:usemarks') && b:usemarks return "\<c-r>=MapNoContext2('".a:key."',BuildMapSeq(\"".a:expr2."\"))\<cr>" else return "\<c-r>=MapNoContext2('".a:key."', \"".a:expr1."\")\<cr>" endif endfunctionAnd so, within normal context, when
b:usemarks
is set,
for
is expanded to: for (;«»;«») { «» }«»and the cursor placed just after the opening parenthesis.
If you have always dreamed of abbreviations that do not insert the <space>
you typed to make it (the
abbrev.) expand, this function is for you !
Let's suppose you want to map "if<space>
" to "if ()<left>
". Doing this is quite easy thanks to
imap
. But it does not
display the characters as you type them, unless you use
iabbr
. Unfortunately, this
time when you type "if<space>
", a space will be added between
the parenthesis.
The function proposed here, and the two commands Iabbr
and
Inoreabbr
address this problem. Define your abbreviations
thanks to these commands, and spaces won't show up.
N.B.: I am not the original author of this tip. You have to thank Bram Moolenar, Benji Fisher and some other people on the VIM mailing list for this. The version I propose in my file does not support multi-byte characters for the moment.
This file defines the function: FirstModeLine()
that extends
the VIM modeline feature to variables. In VIM, it is possible to set
options in the first and last lines. -- cf. :h
modeline
. The function proposed extends it to variables
affectations.
let {variable} = {value}The VIM-options
'modeline'
and 'modelines'
are taken
into account to determine which lines must be parsed, if any.
g:TeXfile
. Hence
it knows that latex should be called on this main file ;
aux2tags.vim
could also be told to compute the associated .aux file.
g:TeXfile
each time is really boring. It bored me so much that I programmed a first
version of this plugin. In every file of one of my projects I added the
line: % VIM: let g:TeXfile=main.tex[
main.tex
is the name of the main file of the project]
Thus, I can very simply call LaTeX from within VIM without having to
wonder which file is the main one nor having to specify
g:TeXfile
each time.
Actually, in order to affect g:TeXfile,
I have to call another
function. Hence, I define a callback function (in my (La)TeX ftplugin)
that checks whether I want to set g:TeXfile
. In that case, the
callback function calls the right function and return true. Otherwise, it
returns false. The name of the callback function should be specified in
ftplugins with the buffer relative variable:
b:ModeLine_CallBack
. Here is as an example this callback
function:
let b:ModeLine_CallBack = "TeXModeLine_CallBack" function! TeXModeLine_CallBack(var,val) if match(a:var, "g:TeXfile") != -1 " No quotes around the file name ! call TKSetTeXfileName( 2, a:val ) return 1 else return 0 endif endfunction
{line} | ::= | [text]{white}VIM:[white]let{affectations} |
{affectations} | ::= | {sgl_affect.} |
{affectations} | ::= | {sgl_affect.}{white}{affectations} |
{sgl_affect.} | ::= | {variable}[white]=[white]{value} |
{variable} | ::= | cf. vim variables format ; beware simple variables (other than global-, buffer-, window-, or environment- (v1.6) -variables) are not exported. |
{value} | ::= | string or numeral value: no function call allowed. |
'[', ']'
) is optional, and something
in curly-brackets ('{', '}'
) is required. Others are required
text constants.
let g:foo="abc".DEF()
' are
recognized and forbidden. So, do not accept (as the maintainer of your
installation) a callback function that parses its parameters and calls a
function named after them.
I define four mappings:
<C-F>
and
<tab>
in VISUAL mode
re-indent the current selection ;
<tab>
in NORMAL mode
re-indents the current line ;
<C-tab>
in NORMAL
mode re-indents the current paragraph.
:SearchInRuntime
), by this plugin,
extends what the :runtime
command does with :source
:
i.e. searching for files within the directories specified by the
'runtimepath'
option, and
then sourcing them.
:SearchInRuntime
also searches for files within 'runtimepath'
, but enables to call any
command after that. If no file is found, nothing is done. And as with
:runtime
, the bang
(!
) parameter will ask for an extensive search that will not
stop after the first file found.
Typical use of the :SearchInRuntime
pass only one
argument to {command}
: the
path to the file found. To provide other arguments to {command}
, we must add them after the
list of {file_pattern}
and a separation pipe ('|
'). Note: spaces are expected
before and after the pipe.
For instance:
:command -nargs=+ Echo
echo "<args>"
:SearchInRuntime! Echo *.vim ftplugin/*_set.vim
'runtimepath'
.
:SearchInRuntime! Echo *.vim ftplugin/*_set.vim | found!
will echo the same files followed by the string "found!", on the same
line.
:command -nargs=+ ExeThis
exe "!<args> ".bufname('%')
:SearchInRuntime! ExeThis tools/vimlatex
vimlatex
is, and execute
it with bufname('%')
as a parameter.
:SearchInRuntime! source ftplugin/c.vim ftplugin/c_*.vim
ftplugin/c/*.vim
:runtime!
with the same pattern.
:Runtime
, defined in
runtime.vim
, in order to propose
an implementation of :runtime
to VIM 5.x, is a simplified
version of :SearchInRuntime
.
:SearchInRuntime sp plugin/searchInRuntime.vim
searchInRuntime.vim
. [the full path can be very long and
not always the same]
:exe ":SearchInRuntime 0r
template/template.".&ft
template/template.<filetype>
that should be
somewhere in the 'runtimepath'
.
:SearchInVAR
will search within a list of directories
specified by a variable: buffer, global, script or environment variable
like $PATH.
:SearchInPATH
is equivalent to :SearchInVAR
$PATH
and :SearchInRuntime
is equivalent to :SearchInVAR &runtimepath
.
<SID>
and s:
stuff.
'verbose'
option is
supported: :runtime
,
the search accepts absolute paths ; for instance: :runtime! /usr/local/share/vim/foo*.vim
macros/foo*.vim
:SearchInRuntime! source /usr/local/share/vim/foo*.vim
macros/foo*.vim
:SearchInVAR
used to be :SearchInENV
.
The purpose of this plugin is to propose different functions that will ease the definition of menus and mappings.
The usual way for this is to call :*menu
AND :*map
for every mode (INSERT, VISUAL, NORMAL,
COMMAND) you wish the mapping to be defined. Thus, the (ft)plugins you write
becomes very long are more difficult to maintain.
Here comes menu-map.vim
. It is a generic extension over an
idea I've found in Benji Fisher's TeX ftplugin.
It can build a menu plus the mappings for different modes at once and
recall the key-binding of the mapping within the menu.
This plugin doesn't require anything, while it is required by several ftplugins of mine.
Two functions are defined.
First example: the following call will add the menu "LaTeX.Run LaTeX
once <C-L><C-O>", with the
priority (placement) 50.305, for the INSERT, NORMAL and COMMAND modes. The
action associated first saves all the changed buffers and then invokes
LaTeX.
The same action is also binded to <C-L><C-O>
for the same modes, with
the nuance that the maps will be local to the buffer ; I haven't tried yet
to integrate Michael Geddes's Buffer-menus plugin.
call MenuMake("nic", '50.305', '&LaTeX.Run LaTeX &once', "<C-L><C-O>", \ '<buffer>', ":wa<CR>:call TKMakeDVIfile(1)<CR>")
The second example demonstrates an hidden, but useful, behavior:
if the mode is the visual one, then the register v
is filled with the text of the visual area.
This text can then be used in the function called. Here, it will be
proposed as a default name for the section to insert:
function! TKinsertSec() " ... if (strlen(@v) != 0) && (visualmode() == 'v') let SecName = input("name of ".SecType.": ", @v) else let SecName = input("name of ".SecType.": ") endif " ... endfunction call MenuMake("nic", '50.360.100', '&LaTeX.&Insert.&Section', "<C-L><C-S>", \ '<buffer>', ":call TKinsertSec()<CR>")We have to be cautious to one little thing: there is a side effect: the visual mode vanishes when we enter the function. If you don't want this to happen, use the non-existant command:
:VCall
...
Third: if it is known that a function will be called only
under VISUAL-mode, and that we don't want of the previous behavior, we can
explicitly invoke the function with :VCall
-- command that
doesn't have to exist. Check s:MapMenu4Env
for such an
example.
Fourth thing: actually, MenuMake()
is not restricted
to commands. The action can be anything that could come at the right hand
side of any :map
or
:menu
action. But this time,
you have to be cautious with the modes you dedicate your map to. I won't
give any related example ; this is the underlying approach in
IVN_MenuMake()
.
IVN_MenuMake()
accepts three different actions for the three
modes: INSERT, VISUAL and NORMAL. The mappings defined will be relative to
the current buffer -- this function is addressed to ftplugins writers.
The last arguments specify the inner mappings and abbreviations embedded
within the actions should be expanded or not ; i.e. are we
defining «noremaps/menus» ?
You could find very simple examples of what could be done at the end of
menu-map.vim
. Instead, I'll show here an extract of my TeX
ftplugin: it defines complex functions that will help to define very
simply the different mappings I use. You could find another variation on
this theme in html_set.vim.
:MapMenu 50.370.300 &LaTeX.&Fonts.&Emphasize ]em emph call <SID>MapMenu4Env("50.370.200", '&LaTeX.&Environments.&itemize', \ ']ei', 'itemize', '\item ')
The first command binds ]em
to \emph{}
for the
three different modes. In INSERT mode, the cursor is positioned between the
curly brackets, and a marker is added after the closing bracket --
cf. my bracketing system.
In VISUAL mode, the curly brackets are added around the visual area. In
NORMAL mode, the area is considered to be the current word.
The second call binds for the three modes: ]ei
to:
\begin{itemize} \item \end{itemize}
The definition of the different functions and commands involved just follows.
command -nargs=1 -buffer MapMenu :call <SID>MapMenu(<f-args>) function! s:MapMenu(code,text,binding, tex_cmd, ...) let _2visual = (a:0 > 0) ? a:1 : "viw" " If the tex_cmd starts with an alphabetic character, then suppose the " command must begin with a '\'. let texc = ((a:tex_cmd[0] =~ '\a') ? '\' : "") . a:tex_cmd call IVN_MenuMake(a:code, a:text.' -- ' . texc .'{}', a:binding, \ texc.'{', \ '<ESC>`>a}<ESC>`<i' . texc . '{<ESC>%l', \ ( (_2visual=='0') ? "" : _2visual.a:binding), \ 0, 1, 0) endfunction " a function and its map to close a "}", and that works whatever the " activation states of the brackets and marking features are. function! s:Close() if strlen(maparg('{')) == 0 | exe "normal a} \<esc>" elseif exists("b:usemarks") && (b:usemarks==1) | exe "normal ¡jump! " else | exe "normal a " endif endfunction imap <buffer> ¡close! <c-o>:call <SID>Close()<cr> function! s:MapMenu4Env(code,text,binding, tex_env, middle, ...) let _2visual = (a:0 > 0) ? a:1 : "vip" let b = "'" . '\begin{' . a:tex_env . '}' . "'" let e = "'" . '\end{' . a:tex_env . '}' . "'" call IVN_MenuMake(a:code, a:text, a:binding, \ '\begin{'.a:tex_env.'¡close!<CR>'.a:middle.' <CR>\end{'.a:tex_env.'}<C-F><esc>ks', \ ':VCall MapAroundVisualLines('.b. ',' .e.',1,1)', \ _2visual.a:binding, \ 0, 1, 0) endfunction endif
Here is the main section of my VIM pages : the one exposing my ftplugins.
You don't know what ftplugins are, you can ask VIM for what they
are : :h ftplugin
.
In short : they are VIM scripts that are loaded (sourced by VIM) only when
we edit a file of a specific (file)type. So, C++ special settings won't
get loaded when editing a LaTeX file, and vice versa.
To my opinion, they are one of the major new feature in the version 6 of
VIM. They enable us to have a clean and as complete configuration as we
wish for. They are the welcomed death of unmaintanale .vimrc
s
-- no more autocommands used to detect filetypes and define mappings,
settings, load files, etc. in consequence. It become transparent.
I don't known where to start ... Let's say that when you insert a parenthesis, a bracket, a quote or anything like that, you may wish you have not to worry about the corresponding closing character. The two following files are dedicated to the management of this problem.
Note: As they are plugins, they are meant to be placed into one of your
{runtimepath}/plugin/
directories.
bracketing.base.vim <raw file> |
A first solution has been proposed by Stephen Riehm. You could
find the whole package with an important documentation and
other remarks on Benji
Fisher's homepage.
Stephen Riehm introduces several language-independant mappings
to manage brackets-like characters. He also introduces two
interesting global mappings : !mark! and
!jump! . They are used to mark (with text markers)
positions within the file edited and jump to them.
As I do not expect the same things from a bracketing system
when I am developing in C++ or writing LaTeX documents, I have
conducted a little modification on the original system. I
added the possibility to dynamically change the text
markers used -- I have also added some other features :
BTW, I map imap <C-J> <Plug>MarkersJumpF map <C-J> <Plug>MarkersJumpF imap <C-K> <Plug>MarkersJumpB map <C-K> <Plug>MarkersJumpB imap <C-<> <Plug>MarkersMark vmap <C-<> <Plug>MarkersMark
Requires : VIM 6.0+, and
|
|||||||||||||||||||
common_brackets.vim <raw file> |
This file eases the insertion of brackets pairs.
It is used by quite all my consequent ftplugins.
Through a set of (boolean) buffer-relative options -- cf. the implementation and the different other language ftplugins -- , it enables and configures bracketing mappings. The bracket-like pairs supported are :
b:cb_ are set
to 1. These options are not meant to be changed dynamically,
but to be set once within ftplugins.
Some behaviors can be tuned much more finely with callback
functions :
How it worksWhen we hit (in insert mode) the starting character of a pair, the second one is automatically inserted. In visual (resp. normal) mode the opening character can be hit once -- except for quotes and dollars that have to be hit twice -- in order to insert the pair around the visual area (resp. current word).
Pressing the second character from the pair puts the cursor
just after the next occurrence of this character (and in insert
mode). But you'd better use
Dynamic (de-)activationWhenTriggers.vim is
installed, the macros defined here can be activated and
deactivated as a whole by pressing <F9> .
In insert-mode, two operating modes are provided : one very
classic and one that takes advantage of my variation of Stephen
Riehm's markers when the buffer relative option AccessibilityFor personal and technical (the meta-mappings do not suit to the layout of my French keyboard) reasons, I prefer to use the opening character of a bracket-like structure in order to insert the whole structure.
In insert and normal modes, it is also possible to hit
Brackets Manipulations
I have stolen some functions from
<M-b> ) that makes VIM enter a
brackets manipulation mode (much like <CTRL-X> ). From there, you
can hit 'x ', '<delete> ', '( ',
'[ ', '{ ', or '<F1> ' that will behave like
exposed earlier, or display a little help message.
If you don't want of this brackets manipulation mode, in your
Again, if you don't like the default keybinding, with vim 6.0+
you can change them into your noremap <silent> <C-L>b :call BracketsManipMode("\<C-L>b")<cr>if g:cb_want_mode is
left to 1, otherwise define : map <C-L>bx <Plug>DeleteBrackets map <C-L>b<del> <Plug>DeleteBrackets map <C-L>b( <Plug>ChangeToRoundBrackets map <C-L>b[ <Plug>ChangeToSquareBrackets map <C-L>b{ <Plug>ChangeToCurlyBrackets map <C-L>b\ <Plug>ToggleBackslash DependenciesRequires VIM 6.0+bracketing.base.vim ,
misc_map.vim , and
Triggers.vim (facultative).
Prefer to download them with bracketing.base.vim and
their documentation as a single tarball archive:
lh-map-tools.tar.gz and
|
|||||||||||||||||||
lh-map-tools.tar.gz
|
The two previous scripts archived with
misc_map.vim and
their documentation.
|
|||||||||||||||||||
lh-map-tools.txt | The VIM documentation associated to the tarball archive. |
vim_set.vim <raw file> help on : <C-F1> |
Some macros useful for editing .vimrc and other
VIM files. Beware, several are contextual. Requires VIM 6.0+, help.vim (facultative),
misc_map.vim , and
menu-map.vim .
|
asx_set.vim <raw file> |
Two little mappings to create .asx files.
Suppose that you have several movies named foo* in
your current folder. To create an ASX file, invokes gvim
foo.asx , and within VIM, enter
=dir and then =fin . Delete the
undesired entries, save and exit.
|
ftplugins for composing e-messages
The ftplugins that follow are dedicated to the composition of electronic
messages (ie. e-mails and usenet posts) ; they propose several
settings, automatic commands and mappings. They have been strongly inspired by
Sven
Guckes's .vimrc
. While some of them have been extended, I
haven't ever customized others.
In order to install them, as usual, drop them in the appropriate folder that is
: $HOME/vimfiles/ftplugin/mail
(on
Ms-Windows® systems) or $HOME/.vim/ftplugin/mail
(on *NIX systems) ; for
others OSes, check «:help 'runtimepath'
».
mail_set.vim <raw file> help on : <C-F1> |
This file gathers general mappings and settings. It directly come from Sven Guckes's file. |
Mail_Re_set.vim <raw file> |
May be, you have already noticed and used the two macros :
,re that merges all the "[Rr][Ee]:"
in the subject in only one "Re:" and
,Re that merges "[Rr][Re]: Re[n]" in
"Re[n+1]" . This ftplugin combines the features from both macros without any visual bell or incrementation of the first number in the subject. It is executed automatically from mail_set.vim and
thus corrects the subject header without any intervention. The script can now be configurated regarding :
|
Mail_mutt_alias_set.vim <raw file> |
This ftplugin will ease the insertion of MUTT e-mail aliases
from within VIM.
In order to use it, you will have to specify the path to your
mutt_aliases file. Feel free to extend this ftplugin to support other the aliases formats from other MUAs.
The script remaps You could also be interested in the script from Brian Medley that supports calls to Abook and Mutt, or Todd Boland's simplified version of my script ; both on sourceforge. |
Mail_Sig_set.vim <raw file> |
I define in this ftplugin an alternative to the macro map ,kqs G?^> *-- $<CR>dGIt comes as a command. This time, VIM won't complains about not found ^> *-- $ pattern. BTW, I also delete all
the empty lines (quoted or not) just above the signature to
delete.Lately, I've integrated Yann Kerhervé's improvement over my function in order to keep your automatically inserted (by mutt) signature -- I guess his page is in French. Moreover, if you reply to a mailing list that inserts another signature (introduced by dashes), the ftplugin will delete up to two possible dashes-delimited signatures. It also support different quote characters thanks to the variables g:my_indent_char and
g:quote_chars .N.B., Brian Medley's e-mail FTplugin also extends the quote characters recognized and proposes other interresting features.
This ftplugin also proposes an 'operator-pending' mapping :
|
Mail_Moderation_set.vim <raw file> |
This file is designed to ease the moderation of
modappbot-moderated newsgroups. More precisely, it defines a
mapping (,mod ) that enables to correctly set the
headers of custom responses to problematic posts. Suppose that modappbot sends an article for your approval and you want to write an appropriate and customized denial. Instead of forwarding the message to a copy-pasted address, changing the subject, and so on, reply to the message modappbot sent to you, hit ,mod from VIM and then write.You may have to customize the script in several places in order to define the newsgroups you moderate, the address of the server associated moderators' mailing lists, the tags of the subject, your signature and so on. Note that this version is an ugly mix between two generations of VIM scripting. You may also be interested by my other moderation stuff for modappbot ... pages still to be writen... |
Mail_cc_set.vim <raw file> |
Bothered of receiving a copy of all your messages when you
reply to a group of people ? Well, this file is for you ! All you have to do is to change my e-mail address to yours. Works fine with mutt and elm ; I haven't tested any other MUA. BTW, Mutt already handle this problem. |
ML_set.vim <raw file> |
I plan to define in this file a set of different custom
mappings for handling ML files -- understand XML,
SGML, HTML, etc.. So, it is needed by
html.set . Actually, only one function is
working ; CloseTag() is not yet ready.
To be used in conjunction with common_brackets.vim .
|
html_set.vim <raw file> help on : <C-F1> |
This file defines a set of macros quite useful to edit HTML
files. Actually, an important number of the macros come from
other well known script files. I do not propose an extensive
tour of all the HTML tags. But, I handle well normal
and visual mode -- the corresponding macros write the HTML tags
around the current word or the selected text. As a bonus, many
macros are mapped on the same keys than those defined in
tex.set . See for instance html 2 from Jano's VIM Macro Page for other interesting stuff regarding HTML editing. Require help.vim and
misc_map.vim .
|
php_set.vim <raw file> |
A few more customizations for PHP coding. |
My ftplugins for LaTeX editing
All the files that follow are for VIM version 6.0+ only. Instead of having one big file, I have collected several mappings, functions and ideas from different sources, arranged them to fit my needs and my taste, and split them into several thematic files.
This way, it becomes easier to maintain the whole stuff : ones can download the LaTeX tools ftplugin and bind the different functionalities to his favorite keystrokes ; without having to rebind everything every time a new version of the ftplugin is out. On the other hand, the number of files can gives an justified impression of complexity. It may be annoying to install the whole stuff the first time, but on the long run it's worth the price.
You could also only download lh-tex.tar.gz [27th January 2004] that contains all the files presented on this page plus the plugins they required and some other bonuses you could find elsewhere like on sourceforge.
tex-set.vim <raw file> help on : <C-F1> |
This file is required by different other TeX ftplugins : it
defines some commands that ease the definition of menus and
mappings in one function call (acts as a wrapper to menu-map.vim ).It also defines different settings (VIM's options) plus mappings and menus that ease the insertion of different LaTeX commands (mainly font attributes) and environments. Like html_set.vim , the macros defined are also
available in both normal and visual mode. Moreover, they are
quite the same. And this time again, the set of mappings is not
exhaustive.Requires help.vim (facultative), menu-map.vim , common_brackets.vim ,
compiler/tex.vim ,
vim-tex.sh (recommended), and
misc_map.vim .
|
|
tex-macros.vim <raw file> |
This file is a compilation of functions dedicated to the
insertion of different environments and sections. Initially
these functions have been writen by Ralf Arens and Tomer
Kol. I have slightly patched them to :
tex-macros.vim can be found in
tex-maps.vim .
|
|
tex-maps.vim <raw file> help on : <C-L><F1> |
This file defines several mappings plus the menus and the help
messages associated. The mappings : - call the different tools
(from tex-tools.vim ), insert environments
(tex-macros.vim ), and ease the navigation through
LaTeX errors. A callback function for the extended modeline functionality is also defined : it permits to define the name of the main file for the current document. Built on top of : tx_macros.vim and
TKLaTeX.vim .
|
texmenus.vim <raw file> |
The texmenus file defined and maintained by other people, but with specific alterations to fit my taste and my keyboard. I still have future plans for this file. |
tex-smart_chars.vim <raw file> |
This file is a compilation of other well known smart mappings
for LaTeX. You will found in this file :
... ,
but \etc instead. Smart-underscore can take advantage of common_brackets.vim , and misc_map.vim if
installed.
|
tex-tools.vim <raw file> |
Here is a big piece of ftplugin.
It defines commands that will compile LaTeX files, transform
them and view the results. Well quite common, isn't it ?
Except that it checks dependencies (tex->dvi->ps &
other combinaisons involving pdf) ; re-run latex if references
have changed (number of pages, labels, etc) ; run
bibtex if there are bibliographic entries ; run makeindex if
needed. May be not every possible case is taken into account,
but a lot are.
This version has been tested under a PC under WindowsNT with
Zsh and cmd32 -- I had some troubles with my installation of
cygwin-bash to run ps2pdf. I strongly recommend you use vim-tex.sh (my little patch for e/=\(pdf\)\=\(la\)\=tex over Srinath Avadhanula shell script) to filter error messages -- facultative nevetheless. And you have to use "my" version of compiler/tex.vim -- or at least a version that defines the command TeXSetEFM in order to assign the errorformat option of vim.
|
|
tex.vim <raw file> |
This is the tex compiler file defined by Artem Chuprina and
then customized by Srinath Avadhanula. My contribution is to
define a command (TeXSetEFM ) that could be invoked
without needing to re-source the file. Why ? because latex
needs one errorformat, while bibtex, makeindex, dvips and
ps2pdf need other particular values for this VIM setting.
|
|
vim-tex.sh <raw file> |
This shell script pre-parses latex errors before VIM parses
them again. This is just a little patch over Srinath
Avadhanula's version in order to be able to execute other
programs than latex (like pdftex, etex, etc.).
I also tried to find a way to return the shell error from latex
(/the first compilation tool executed).
Don't forget to correct the first line of the script to match the location of your bourne-shell interpreter. |
Some settings
Commands for other tex ftplugin (help & menu+map)
Command for customizing the character delimiter used by
\verb
Loads my spellchecker plugin
Generic menu & maps (+ help messages) to insert different LaTeX
commands and environments ; they work in the three modes (insert, visual
and normal) and an exhaustive list can be obtained by hitting
<C-F1>
-- help.vim
required.
In the future, different things may fusion with texmenus.vim
Some features en vrac...
s:TKSetDefaultProgNames()
, to be sure your environment
matches the default programs I propose.
<{main-file-name}.latexmain>
; - or by setting the
global variable : g:TeXfile
(my let-modeline plugin can be
of a great help with this approach).
Can support Benji Fisher's aux2tags.vim
ftplugin if found on
the system ; i.e. provide a keybinding to directly invoke the
parser command.
Can support Michael Geddes's bufferoption.vim
plugin if found
on the system and if desired (g:want_buffer_menu_for_tex ==
1
).
Provides two new commands used by itself and texmenus.vim
to
ease the definition of buffer-relative mappings and menus.
VIM ftplugins for editing C & C++ files
I propose/present here a set of VIM ftplugins designed for editing C++ files and C files.
You will found all the links for downloading the described files at the end of this part.
The script that follows is meant to be placed into one of your {rtp}/ftplugin/c/
directories.
Note: {rtp}
refers to
'runtimepath'.
c_set.vim
defines many things that I found useful when programming
in C. They could be used for C++ and Java programming as well.
Features and Originalities
if
,
else
, elif
(I know it is not a C keyword, but else
if
are), for
, while
, switch
and main
. if
in insert mode, it will automatically expand into ...
if () { }... in respect of the context. I.e.: within comments or strings (delimited by single or double quotes)
if
is
not expanded. If keyword characters precede the typing,
if
is not expanded as well. Thus variables like
tarif
can be used without getting any headache.,if
wraps the selection within the curly
brackets and inserts if
()
just before. In normal mode ,if
does the same
thing under the consideration that the selection is considered to be
the current line under the cursor. Actually, it is not ,if
but <LocalLeader>if
,
with maplocalleader
assigned by
default to ,
.
More precisely, regarding the value of the buffer relative option
b:usemarks
(cf. common_brackets.vim
),
if
could be expanded into:
if () { «» }«»
I do not present more precisely the other mappings alike. There are twin mappings !
misc_map.vim
defines two functions used in every mapping and abbreviation of the
language keywords ; it enables to define context dependent macros.
common_bracket.vim
defines a set of mappings that ease the management of brackets, quotes,
parenthesis, etc.. These mappings are customized for C &
C++ programming.
a.vim
very nice when we want to swap between .h, .inl and
.c and .cpp files. Could be found of sourceforge
-- not critical regarding the mappings defined.
LoadHeaderFile.vim
very nice in order to go to included
files. Could be found of sourceforge
-- not critical regarding the mappings defined.
The script that follows is meant to be placed into one of your {rtp}/ftplugin/cpp/
directories.
Classical features:
cpp_set.vim
cpp_set.vim
:
c_set.vim
,
try
& catch
;
public:
,
protected:
,
private:
,
template<>
,
virtual
and
std::
;
/*<space>
that expands into:/** */«»
/**
that expands into:
/** */«»
<c-x>be
that expands
algo(container_expr§)
into
algo(container_expr.begin(), container_expr.end()§)
,
where §
represents the current cursor position.
cpp_options.vim
that
is the ideal place for custom C++ preferences.
cpp_BuildTemplates.vim
defines my own
template preferences regarding the format of comments and classes
-- many headers plus some doxygen constructs.
cpp_FindContextClass.vim
extracts the name
of the class the cursor is within.
cpp_InsertAccessors.vim
defines certainly
one of the two most useful features: an easy way to add (to a
class) new attributes and their accessors and mutators (get and set
methods).
cpp_GotoFunctionImpl.vim
defines the second
most useful feature: a way to jump from the prototype to the
implementation of a function, and if the implementation has not
beeing defined yet, an empty implementation is inserted in the
.cpp
file.
All the scripts that follow are meant to be placed into one of your
{rtp}/ftplugin/cpp/
directories.
cpp_options-commands.vim
&
cpp_options.vim
cpp_options.vim
is the ideal place for custom C++ preferences
like the prefix and postfix notations used for member data and their
accessors, the file where inlines should go, if accessors must be inlined,
etc. ; this file is used to configure
cpp_BuildTemplates.vim
, cpp_InsertAccessors.vim
and cpp_GotoFunctionImpl.vim
.
Drop it into your {rtp}/ftplugin/cpp/
directory ; it
will be shared by all your projects. And if for a particular project other
rules are required, copy and specialize this file into every directory
containing the C++ source files.
cpp_options-commands.vim
only defines the command
:CheckOptions
that is used by the other scripts to load the
correct options (i.e. cpp_options.vim
).
cpp_BuildTemplates.vim
This file defines my own template preferences regarding the format of comments and classes -- many "rulers" plus some doxygen constructs. You may not be directly interested in this file ; moreover, it will evolve to take advantage of Gergely Kontra's mu-template. The commands are:
;HE <main class name>
which produces
a template for the header file dedicated to the specified class name.
;CL <main class name>
which produces a
class template for specified class name.
;BL <title>
which produces three lines
of '='
around the title -- BigLines.
;GR <group title>
which inserts a
Doc++/Doxygen group -- GRoup.
;MGR <group title>
which inserts a
Doc++/Doxygen group plus a comment line -- MegaGRoup.
;RI <class name>
which moves the cursor to
the desired (regarding cpp_options.vim::g:inlinesPlace
) location for the
implementation of the inlines of the current class --
ReachInlines. The functions that the command calls are quite
complex and heavily rely on the Big Line format. So if you
want to change the format, you will have to adapt the function
Cpp_search4line()
and some other script variables. All the
underlying functions used by this command are very important for the
cpp_InsertAccessors.vim::AddAccessor
command. So, be very
careful in your customizations.
cpp_BuildTemplates.vim
needs an old version of a.vim
.
cpp_FindContextClass.vim
Given a line number, the function (in this ftplugin) extracts the name of the most embedded class around the specified line.
A this time, the template are not managed.
For something like:
1: 2: class A 3: { 4: // ... 5: class B { 6: // ... 7: }; 8: // ... 9: class C { 10: // ... 11: }; 12: }; 13:The possible retrieved class names are: "" [1, 13], "A" [2-4,8,12], "A::B" [5-7] and "A::C" [9-11].
This script is required by cpp_InsertAccessors.vim
and
cpp_GotoFunctionImpl.vim
.
cpp_InsertAccessors.vim
This file defines an easy way to add new attributes, their accessors (get
methods) and their mutators (set methods) to a class.
I may use "accessor" to also designate the "mutator".
The built accessors are moreover const and ref. correct in the
sense of the item 43 of Herb Sutter's Exceptional C++. BTW, if you
extend (with typedefs) the list of base types, you will have to extend the
function Cpp_IsBaseType()
.
To use this feature, place the cursor where you want your attributes
(internal data members) to be written to, then press ;AA
. Then
first, you will be asked for the type of the new attribute and its name.
And then, you will be asked whether you want:
Regarding the customization facilities, through
cpp_options.vim
you can:
m_Foo
(Microsoft's one),
Foo_
(Herb Sutter's one),
_Foo
(the one you should forget about),
Foo
(the very lazy one), etc..
Foo
could be
"GetFoo()
", or
"getFoo()
", or
"get_Foo()
" and so on. And the same for the
set and the reference accessors.
Here is a little example of header file and the corresponding inline file generated for:
g:implPlace=1
--
implemented as inlines ;
g:inlinesPlace=1
--
inlines in a separate file ;
int
attribute
named AnInteger
for which I asked for a get, a set and
a reference accessor.
CComplexThing
attribute named
AComplexThing
for which I asked for a proxy-get (of
type CT_Proxy
), a set and a reference accessor ;
Note: the inline and the definition files don't need to exist. They are generated automatically.
cpp_GotoFunctionImpl.vim
This file defines an easy way to jump from a function-prototype to its implementation ; if the implementation does exist yet, a default one is generated on the fly.
This ftplugin has been first inspired by Leif Wickland's VIM TIP#335 (on sourceforge) and Robert Kelly IV's improvments. Then I added what I've been waiting to do for a longtime: a way to jump the implementation of a function.
Some other features:
mu-template
: i.e. it won't
complains or do any weird and undesired thing.
cpp_options.vim
and can be overriden
when invoking the command.
The ftplugin defines:
:GIMPL
(GOTO_IMPL
)
that will provoke the jump ; The cursor must be placed between the
line of the function's name and the corresponding closing
parenthesis.
<C-X>i
;
;GI
and <C-W>i
.
imap <buffer> whateverIWant <Plug>GotoImpl nmap <buffer> whateverIWant <Plug>GotoImpl
Several options are available (ideas from Robert Kelly IV):
ShowVirtual
(0/1): determines whether we want the
virtuality of the member function to be reminded along with
the implementation ;
ShowStatic
(0/1): determines whether we want the
staticity of the function to be reminded ;
ShowDefaultParam
(0/1/2): determines whether we want the
default value of the parameters to be remininded to us.
cpp_options.vim
that can define the variables: g:cpp_ShowVirtual
,
g:cpp_ShowStatic
and
g:cpp_ShowDefaultParams
. :GIMPL
, we can specify the
values for these different options on the fly. The format beeing:
<name_of_the_option>(\d\+\|on\|off)
. For
instance: :GIMPL ShowVirtualoff ShowDefaultParams2
.
lh-cpp.tar.gz |
This tarball contains all the following files and a
copy of all the files they rely on. So, if you plan to have a complete and easy installation of my C & C++ ftplugins, unpack this tarball archive into one directory from your 'runtimepath' .
|
||
c_set.vim <raw file> |
The main C ftplugin. It defines several settings plus a lot
of mappings for C keywords.
|
Requires:
misc_map.vim ,
common_bracket.vim . Wants a.vim and
LoadHeaderFile.vim .
|
|
cpp_set.vim <raw file> |
The main C++ ftplugin. It defines some new mappings for C++
keywords, enhanced the comments management and loads all the
other C++ plugins.
|
Requires:
c_set.vim , and every following
cpp_.*.vim .
|
|
cpp_options-commands.vim <raw file> |
Script in charge of the management of the options. I.e. it loads the appropriate options-file.
|
Needed by: cpp_BuildTemplates.vim ,
cpp_GotoFunctionImpl.vim and
cpp_InsertAccessors.vim .
|
|
cpp_options.vim <raw file> |
The options-file, designated place for customizing the
policies of the following files. It is meant to be overriden
into your current working directory.
|
Needed by: cpp_BuildTemplates.vim ,
cpp_GotoFunctionImpl.vim and
cpp_InsertAccessors.vim .
|
|
cpp_BuildTemplates.vim <raw file> |
Defines some template preference for the formats of comments
and classes.
|
Requires: a.vim |
|
parse-class.sed <raw file> |
Multi-line extraction of class names. | Depreciated ; Used to be required by cpp_FindContextClass.vim |
|
cpp_FindContextClass.vim <raw file> |
Extracts name of classes.
|
|
|
cpp_InsertAccessors.vim <raw file> |
Enables to easily add attributes and their accessors.
|
Requires: cpp_options.vim ,
cpp_BuildTemplates.vim ,
cpp_FindContextClass.vim , a.vim .
|
|
cpp_GotoFunctionImpl.vim <raw file> |
Defines a command and some mappings to jump from a function
prototype to its implementation ; if the implementation does
exist yet, a default one is generated on the fly.
|
Requires: cpp_options.vim ,
cpp_FindContextClass.vim , a.vim .
|
|
lh-cpp-readme.txt | The VIM documentation for all these scripts. | Written as a part of the tarball archive. | |
a.vim | Commands to switch between source files and header files. | Maintained on sourceforce. | |
LoadHeaderFile.vim | Loads a file from a #include line.
|
Maintained on sourceforce. | |
mu-template.vim Local copy: mu-template.vim <raw file> Archive with some templates: mu-template.tar.gz Help file: mu-template.html |
Gergely Kontra's script. It permits to (automatically) insert
template files. Little to little, I will use this plugin to
replace some of my cpp_BuildTemplates.vim 's
functions. The version I propose here has been enhanced to support many other things and to be compatible with my other scripts. | .
Initial version maintained on sourceforce; Can takes advantage of searchInRuntime.vim
|
Here is a little excerpt from my bookmarks regarding VIM and other relative topics:
Back to the Home Page | hermitte at free.fr |