Often, I find myself editing an HTML file with some JavaScript in it at the bottom. I use a vertical (vsp) or horizontal (sp) split on the file so I can see the JavaScript and the HTML in two different windows. I'd like to use

set syn=html

for the HTML window and

set syn=javascript

in the other.

Unfortunately, this command effects both buffers so the JavaScript will be highlighted as HTML and vice versa. Is there any way to make the windows' highlighting independent of each other.

  • Great question; however I suspect the answer might be use another editor. – miltonb Dec 14 '16 at 23:59

You can't really do that with split windows, since windows are not connected to the filetype stuff -- highlighting, indentation and so on. They're simply different layouts to view the same content.

I do understand your problem, though, which is why I wrote a plugin a while back to do something about it. It's not an ideal solution, but it might be enough: https://github.com/AndrewRadev/inline_edit.vim.

The plugin lets you use a keybinding to open the javascript in a separate buffer, which mirrors the original one -- every change in the javascript buffer updates the original buffer.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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