How do I set the filetype option for files with names matching a particular pattern or depending on the file extension?
‘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 For more information, read :help new-filetype :help 43.2 :help :setfiletype ============================================================================= SECTION 27 – EDITING PROGRAM FILES 27.1. How do I enable automatic indentation for C/C++ files? You can enable file-type based indentation using: :filetype indent on If you want to only enable automatic C indentation, then use: :set cindent For more inform
Related Questions
- For files with self-referencing data, where the child of a particular record appears as a parent in the file, are there any recursive relationships?
- How do I set the filetype option for files with names matching a particular pattern or depending on the file extension?
- Are the image names listed in the artwork.txt file or any other datafeed files?