How do I set the filetype option for files with names matching a

particular pattern or depending on the file extension? You can set the ‘filetype’ option for files with names matching a particular pattern using an autocmd. For example, to set the ‘filetype’ option to ‘c’ for all files with extension ‘.x’, you can use the following autocmd:

    autocmd! BufRead,BufNewFile *.x     setfiletype c

A better alternative to the above approach is to create a filetype.vim file in the ~/.vim directory (or in one of the directories specified in the ‘runtimepath’ option) and add the following lines:

    " my filetype file

    if exists("did_load_filetypes")

        finish

    endif

    augroup filetypedetect

        au! BufRead,BufNewFile *.x       setfiletype c

    augroup END

Read free Software Algorithms and Computer Science Books by CodeAhoy Learn.

Introduction to Recursion and Backtracking

Sorting Algorithms

Introduction to C Programming Language

And More...

Speak Your Mind