Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using the terrific NrrwRgn plugin. I often edit XML files with PHP in CDATA sections, so in the narrowed buffer I get this:

<![CDATA[                        
$foo='bar';
doSomething($foo);
            ]]>

How can I have the narrowed region identified as PHP when it is PHP and as XML or something else when it is something else? Note that even in this example, by selecting the PHP section with vit\nr the CDATA tags are still there, so technically this is not-well-formed XML, not PHP.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I couldn't find a solution to this problem so I settled for

nnoremap <leader>js set ft=javascript

I, too, am curious for a solution.

share|improve this answer
add comment

I am not exactly sure, I completely understand what you want. The NrrwRgn plugin should automatically set the filetype of the narrowed window to that of the original buffer. If this is not what you want, you can however hook into NrrwRgn command on creation and closing of the windows. So here is what you could do:

Create a file ~/.vim/after/ftplugin/php.vim (create non-existing directories, on Windows, this would be $VIM/vimfiles/after/ftplugin/php.vim, where $VIM is whatever directory vim tells you, when issuing :echo $VIM) and put into it:

let g:nrrw_custom_options={}
let g:nrrw_custom_options['filetype']='php'

And in your .vimrc you put this:

let b:nrrw_aucmd_close= "unlet! g:nrrw_custom_options"

That should be all that needs to be setup and then whenever you narrow something from a php file, it will be automatically be set to filetype php.

Make sure filetype plugins are enabled so (you do this, by putting something like filetype plugin on into your .vimrc.

share|improve this answer
    
Thank you. The original buffer is XML and I am editing PHP that was in a CDATA section of the XML. I will try your solution and write back. Thanks. –  dotancohen Jul 5 '12 at 12:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.