Luc Hermitte (talk | contribs) (Added to VimL category) |
m (Deleted useless comments) |
||
Line 65: | Line 65: | ||
== Comments == |
== Comments == |
||
− | this is supposed to be a tip section. |
||
− | so submit a TIP not a PhD thesis |
||
− | |||
− | billG--AT--megasoft.com |
||
− | , February 15, 2002 10:55 |
||
---- |
---- |
||
<!-- parsed by vimtips.py in 0.445060 seconds--> |
<!-- parsed by vimtips.py in 0.445060 seconds--> |
Revision as of 09:59, 16 September 2007
Tip: #215 - Edit configuration files for a filetype
Created: February 14, 2002 8:02 Complexity: intermediate Author: Mark A. Hillebrand Version: 6.0 Karma: 6/8 Imported from: Tip#215
When you open a file, vim may load several scripts to customize itself for editing the file type the file is associated with (for example a file "test.c" is associated with the filetype "c").
Such configurations include the setting of syntax highlighting colors (:help syntax) and support for indentation (:help filetype-indent-on).
When you start to override these files for yourself, it can sometimes be confusing, which file sets a specific option.
The following function can be used, to edit the configuration files which are associated with a specific filename. It opens a buffer for all files which get loaded.
If I invoke it with ':call Edit_ft_conf("test.c")', for example, I end up with the following buffers / windows:
- a "[No File]" line 1
- a "test.c" line 1
- a= "/usr/local/share/vim/vim60/syntax/c.vim" line 1
- a "~/.vim/after/syntax/c.vim" line 1
- #a= "/usr/local/share/vim/vim60/indent/c.vim" line 1
- %a= "/usr/local/share/vim/vim60/ftplugin/c.vim" line 1
Here comes the function:
" Edit filetype configuration files " Usage: ':call Edit_ft_conf("file")' " Purpose: open all scripts which get loaded implicitly by opening "file" " (syntax highlighting, indentation, filetype plugins, ..) " The order of windows reflects the order of script loading (but "file" is " the topmost window) fun! Edit_ft_conf(name) " we may not do this with a loaded file, since this won't trigger the " configuration file loading as desired. " try calling with 'call Edit_ft_conf("nonexistingfile.<EXT>")' if this " gives you troubles if bufexists(a:name) && bufloaded(a:name) echo "!Attention: buffer for " . a:name . " is loaded, unload first." return endif " split-open the file with verbose set, grab the output into a register " (without clobbering) let safereg = @u redir @u " redirect command output to register @u exec "silent 2verbose split " . a:name " verbose level 2 suffices to catch all scripts which get opened redir END " Parse register @u, looking for smth like: 'sourcing"/usr/local/share/vim/vim60/syntax/c.vim"' let pos = 0 let regexp = 'sourcing "[^"]\+"' while match(@u,regexp,pos) >= 0 let file = matchstr(@u,regexp,pos) let pos = matchend (@u,regexp,pos) let file = strpart(file,10,strlen(file)-11) exec "silent below split " . file endwhile " restore the register let @u = safereg endfun