I edit a lot of PHP code with Vim, and I've run into a snag with some macros in my .vimrc.I currently use these two macros to comment/uncomment in C-stylec-style (//) comment (press the [.] key)au FileType php vnoremap . :s/^\(\s*\)\(.\+\)$/\1\/\/\2/<CR>:noh<CR>gvc-style (//) uncomment (press the [,] key)au FileType php vnoremap , :s/^\(\s*\)\/\//\1/<CR>:noh<CR>gvAnd these two to comment/uncomment in HTML-stylehtml-style (<!-- -->) comment (press the [.] key)au FileType html vnoremap . :s/^\(\s*\)\(.\+\)$/\1<!-- \2 -->/g<CR>:noh<CR>gvhtml-style (<!-- -->) uncomment (press the [,] key)au FileType html vnoremap , :s/^\(\s*\)<!-- \(.*\) -->/\1\2/g<CR>:noh<CR>gvThese macros work fine when applied to their intended file-type, but since there is often HTML embedded inside a PHP file, the PHP commenting style is useless.Is there a way for Vim to detect if it's working on a chunk of HTML code inside a PHP file, and then apply the correct commenting behaviour?Edit: I know that I can manually set the filetype, and that there are plugins available for this, I was looking to learn more about writing better macros.
Vim, context-sensitive comment/uncomment behavior
vim;php