Peng Yu (2008-10-19 14:42 -0700):
> I don't know how the syntax highlight work. What I should use to
> replace 'name of the syntax item here', 'whatever' and
> 'somethingelse'?
OK, here's more detailed explanation. Put the following code to some
file. If you mean to use this feature always with filetype "tex" put the
code to the standard location of user's personal filetype plugins. It
can be ~/.vim/after/ftplugin/tex.vim . Then it is loaded automatically
when you start editing a file of that type.
Here's the code:
" ----------( Begins here )----------
augroup MyDetectContextGroup
autocmd! * <buffer>
autocmd! CursorMoved,CursorMovedI <buffer> call s:DetectContext()
augroup END
function! s:DetectContext()
let syntax_name = synIDattr(synID(line('.'),col('.'),1),'name')
if syntax_name == 'name of the syntax item here'
setlocal iskeyword+=_
else
setlocal iskeyword-=_
endif
" When finding appropriate syntax item name(s) it's
" useful to print the name in the echo area.
" After that the following line can be removed:
echo syntax_name
endfunction
" ----------( Ends here )----------
It doesn't work correctly yet but we need to run it anyway to find out
the name of the syntax item. So, load the file that you have those
"\input{one_another}" things. Source the file which contains the above
code (:source). If you put it previously to the standard filetype plugin
directory it may have already been sourced automatically by Vim.
Now move the cursor in the buffer. Try moving it on parts which are
highlighted differently, with different colors. On the bottom line of
Vim's window you should see the name of the current syntax highlight
item. It changes when you move the cursor to differently highlighted
items.
Now move the cursor to the area where you want different settings for
'iskeyword' option; I think it's the "one_another" part of the
"\input{}", at least in your example. Copy the syntax item name you see
at the bottom of the window to clipboard or somewhere and paste it
between the single quotations marks of this line in the code:
if syntax_name == 'name of the syntax item here'
Save the file, source it again and now it should run "setlocal
iskeyword+=_" when cursor is on that syntax item and "setlocal
iskeyword-=_" when it's anywhere else. If I got those two commands the
wrong way you can swap them in the if-else-endif structure. When the
code is working you can remove the line "echo syntax_name"; no need to
print syntax item names anymore.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---