Tip #627: Customizing ftplugin, syntax etc. (eg for TeX)
tip karma |
Rating 2/3, Viewed by 1273
|
created: |
|
December 24, 2003 17:06 |
|
complexity: |
|
basic |
author: |
|
Suresh Govindachar |
|
as of Vim: |
|
6.0 |
It is possible to customize the default environment that vim
provides (based on filetype). In older versions of vim (5.x),
this was done with a "myfiletypefile" file. In newer versions,
one customizes by adding files to the appropriate subdirectory
under the vimfiles directory.
For example, to customize the default TeX environment (of 6.1),
I added the following ftplugin and syntax files:
"--------------------------
" vimfiles/ftplugin/tex.vim
"--------------------------
if exists("b:did_myftplugin")
finish
endif
let b:did_myftplugin = 1
" Set 'formatoptions' to break comment lines but not other lines,
" and insert the comment leader when hitting <CR> or using "o".
setlocal fo-=t fo+=croql
" Allow "[d" to be used to find a macro definition:
" Recognize plain TeX \def, \gdef, \let and \font
setlocal define=\\\\def\\\\|\\\\gdef\\\\|\\\\let\\\\|\\\\font\\\\|\\\\\\(re\\)\\=newcommand{
"---*---*---*---*---*---
"--------------------------
" vimfiles/syntax/tex.vim
"--------------------------
if exists("b:did_mysyntax")
finish
endif
let b:did_mysyntax = 1
"hilight 1 true in, 1truein, 1 truein, 1true in, 1in, 1 in, 1.1 truein, etc.
syn match texTrueLength "\<\d\+\(\.\d\+\)\=\(\ *true\ *\|\ *\)\
\(\ *pt\|\
\ *he\|\
\ *bp\|\
\ *cc\|\
\ *cm\|\
\ *dd\|\
\ *em\|\
\ *ex\|\
\ *in\|\
\ *mm\|\
\ *pc\|\
\ *pt\|\
\ *sp\)\>"
if version >= 508 || !exists("did_c_syn_inits")
if version < 508
let did_c_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink texTrueLength Number
delcommand HiLink
endif
"---*---*---*---*---*---
<< open vimrc file |
Execut "things" in Win98 from within VIM >>
Additional Notes
Suresh Govindachar,
December 24, 2003 18:04
|
The first four lines in each file should _NOT_ be present:
if exists("b:did_my...")
finish
endif
let b:did_my... = 1
When these lines are present, they prevent the loading
of the customization when, for example, the user
does ":e!".
|
[email protected],
December 30, 2003 13:25
|
Unless you add
let b:did_ftplugin
to the ftplugin, the default ftplugin/tex.vim will still be read, and it will clobber your customizations. Similar remarks apply to the other customization files. See
:help ftplugin-overrule
for more details.
This can be useful as an example, but before you decide not to use the default settings, have a look at what you are losing. Because of a typo, the default ftplugin/tex.vim does not recognize \gdef, but it does recognize \def, \let, \font, \newcommand, and \renewcommand, as well as \futurelet, \newcount, and several other variants. If you care about \gdef, the best thing to do is to alert the maintainer (in this case, c'est moi).
|
|
|