Peach Passion
Peach Passion

Reputation: 467

Switch back and forth between filetypes in VIM

Similar to how spell checking works. I have a custom syntax I wish to temporary apply to any filetype in the buffer. I figure the best way to do this is just change the filetype. But, I don't know how to get back to previous filetype without being explicit. How can I accomplish this?

Upvotes: 1

Views: 134

Answers (2)

Zsolt Botykai
Zsolt Botykai

Reputation: 51593

Set up a function and a keyboard map to do it for you, e.g.:

function! ToggleFileType()
   if g:my_file_type" == 0
      let ft=MYFILETYPE
      let g:my_file_type = 1
   else
      filetype detect
      let g:my_file_type = 0
   endif
endfunction

nmap <silent>  ;s  :call ToggleFileType()<CR>

So this way, hitting ;s (in normal mode) calls the above function, which checks which filetype is set, then toggles.

Upvotes: 1

fnl
fnl

Reputation: 2239

You can use :filetype detect to redetect the original filetype.

Upvotes: 1

Related Questions