Hello, On Sat, Jan 25, 2014 at 11:11 PM, Peter Nguyen <[email protected]>wrote:
> Den lördagen den 25:e januari 2014 kl. 22:37:22 UTC+1 skrev Niklas > Lindström: > > Hi Peter, > > > > On Sat, Jan 25, 2014 at 5:13 AM, Peter Nguyen <[email protected]> > wrote: > > > > Hi, > > > > I have a twig (PHP HTML template) file with several non ascii characters > at different places. I can do a search with: > > > > /[\x7f-\xff]/ > > > > and it will match them. But when I try to add these commands to my > .vimrc file for highlighting them, it does not work: > > > > " Find non ASCII chars and highlight them > > > > syn match nonascii "[\x7f-\xff]" > > > > hi nonascii guibg=Red ctermbg=2 > > > > Anyone who knows what I'm doing wrong? > > > > Declaring syntax rules in the .vimrc will not work, since the syntax > will be cleared during vim startup (or something to that effect). > > > > For your case, you can either add something like this to your .vimrc: > > > > match ErrorMsg "[\x7f-\xff]" > > > > Or add your original commands to a file called > ~/.vim/after/syntax/php.vim in your home directory (create it and any > needed parent directories if they don't already exist). The "after" folder > is a nice way to customize things locally according to your needs. That > file specifically will extend the php syntax for you. > > > > See also e.g. <http://vim.wikia.com/wiki/Highlight_unwanted_spaces>. > > > > H.T.H. > > Cheers, > > Niklas > > > > -- > > > > -- > > > > You received this message from the "vim_mac" maillist. > > > > Do not top-post! Type your reply below the text you are replying to. > > > > For more information, visit http://www.vim.org/maillist.php > > > > --- > > > > You received this message because you are subscribed to the Google > Groups "vim_mac" group. > > > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > > > For more options, visit https://groups.google.com/groups/opt_out. > > Hi Niklas, > > thanks for your answer. The match ErrorMsg "[\x7f-\xff]" works but only on > the current file (.vimrc) after I source it. If I check the other file > (twig) it didn't highlight the non-ascii characters. I haven't tried your > suggestion with the "after" folder yet because I would want that non-ascii > characters to be highlighted in all files, not just for php syntax. Is it > possible? > Oh, right. It seems you need to trigger this for each window, so you can do either: au BufWinEnter * match ErrorMsg "[\x7f-\xff]" Or perhaps better (to play nicer with other things adding matches): au BufWinEnter * let w:matchnonascii=matchadd('ErrorMsg', "[\x7f-\xff]", -1) See e.g. <http://vim.wikia.com/wiki/VimTip810> for details. (Or :help :match / :help matchadd()) Cheers, Niklas > > -- > -- > You received this message from the "vim_mac" maillist. > Do not top-post! Type your reply below the text you are replying to. > For more information, visit http://www.vim.org/maillist.php > > --- > You received this message because you are subscribed to the Google Groups > "vim_mac" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- -- You received this message from the "vim_mac" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_mac" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
