88 votes
Accepted

What is the difference between `filetype plugin indent on` and `filetype indent on`?

filetype plugin indent on is like a combination of these commands: filetype on filetype plugin on filetype indent on It turns on "detection", "plugin" and "indent" at once. You can check for ...
Flimm's user avatar
  • 2,182
35 votes
Accepted

Is it possible and useful to split vimrc?

Yes this is possible and useful and even considered best practice. They are called filetype plugins in Vim speech. And Vim even comes with many filetype plugins (as well as indent and syntax files) ...
Christian Brabandt's user avatar
32 votes
Accepted

How do I tell vim that some file extensions are synonymous?

The preferred approach is to create a ~/.vim/filetype.vim, as mentioned in :help 43.2 and explained in Vim FAQ 26.8: A better alternative to the above approach is to create a filetype.vim file in ...
mMontu's user avatar
  • 6,600
30 votes

For an autocmd in a ftplugin, should I use pattern matching or <buffer>?

Is this usage of <buffer> correct? I think it is correct, but you just need to wrap it inside an augroup, and clear the latter, to make sure that the autocmd won't be duplicated every time you ...
user852573's user avatar
  • 1,003
25 votes

How do I tell vim that some file extensions are synonymous?

You could do (in your global .vimrc): autocmd BufEnter *.tpp :setlocal filetype=cpp
edi9999's user avatar
  • 1,172
19 votes

How to create a new vim filetype?

Create ~/.vim/ftdetect/SOME_EXTENSION.vim and add this line to it: autocmd BufNewFile,BufRead *.SOME_EXTENSION set filetype=SOME_FILETYPE So if you wanted vim to use the filetype html for all files ...
Cory Klein's user avatar
17 votes
Accepted

How to create a new vim filetype?

The symlink you've created at ~/.vim/ftplugin/Rhtml.vim tells Vim how to handle files with the RHTML filetype, but you haven't told Vim how to recognise which files should have this filetype. ...
Rich's user avatar
  • 31.3k
16 votes
Accepted

Is there any list of filetype extension names?

The reason Vim detects the filetype for *.cpp and not for *.CPP files is that Vim has auto-commands for *.cpp setting the filetype, but nothing for *.CPP: :au BufRead *.cpp --- Auto-Commands --- ...
muru's user avatar
  • 24.7k
16 votes
Accepted

What is the difference between 'set ft=' and 'setfiletype'?

From the :setfiletype help: :setf[iletype] [FALLBACK] {filetype} :setf :setfiletype Set the 'filetype' option to {filetype}, but only if ...
Charles Gueunet's user avatar
13 votes
Accepted

How do I run a specific vim command when opening a file with a given extension?

Instead of checking the extension and setting the textwidth accordingly you could simply create a tex.vim (the name must match the filetype) file in .vim/ftplugin/ or for Windows $HOME/vimfiles/...
ap0's user avatar
  • 306
13 votes

How to edit binary files with Vim?

TL;DR Answer Open the file with Vim in binary mode: vim -b <file_to_edit> In Vim, get into hex editing mode like so: :%!xxd -p To save: :%!xxd -p -r :w The first line will convert the ...
Hintron's user avatar
  • 239
13 votes
Accepted

Why is "set noexpandtab" in my ~/.vimrc ignored when I open a file?

It is not ignored, it is overwritten by your filetype plugin. In this case the python plugin. You can verify that like Marth said, with the :verbose command: :verbose set expandtab? If you want to ...
B.G.'s user avatar
  • 1,116
13 votes
Accepted

How to do file type detection based on file contents (e.g. a certain shebang line)?

If you want to introduce a file type and that file type can only be identified by examining the contents of such files then you'll need to add appropriate logic to a file named scripts.vim. But first, ...
B Layer's user avatar
  • 19.6k
12 votes

How do I run a specific vim command when opening a file with a given extension?

In ~/.vimrc you can add the following line: au BufReadPost,BufNewFile *.md,*.txt,*.tex setlocal tw=79 For extra commands, separate them by |. This will set your settings right after reading the ...
kenorb's user avatar
  • 18.2k
12 votes

Blocking changes to read only file

Add this to your .vimrc: augroup NoModWhenReadOnly autocmd! autocmd BufRead * let &l:modifiable = !&readonly augroup END
s4y's user avatar
  • 316
10 votes
Accepted

What does "filetype plugin on" really do?

There is actually a good description in help filetype. Any options that are defined for a filetype will be set with setlocal: :setl[ocal] ... Like ":set" but set only the value local to the ...
laktak's user avatar
  • 2,898
9 votes

How to edit binary files with Vim?

Use the "bvi" editor. http://bvi.sourceforge.net/ (It's in every Linux repository.) $ apt-cache show bvi [snip] Description-en: binary file editor The bvi is a display-oriented editor for binary ...
RonJohn's user avatar
  • 191
9 votes

Mardown files always have vimwiki filetype (vimwiki plugin)

This is the expected behavior of the plugin when you create a file in your vimwiki the filetype is set to vimwiki. If you don't want files created outside of the wiki directory to have this filetype ...
statox's user avatar
  • 49.4k
8 votes
Accepted

How can I make highlighting commands in .vimrc take effect immediately with Vim 7.4?

This is no definite answer and your problem sounds like issue 542. Apparently you can work around it, by writing your own basic colorscheme, instead of writing those hi ... statements directly into ...
Christian Brabandt's user avatar
8 votes
Accepted

How to reload the current file to change syntax highlighting (ex: adding a shebang)?

If the file has been saved the easiest way is simply to run: :e However, if the file has not been saved, this will result in an error. In this case a different command can be run: :filetype detect ...
8 votes
Accepted

Vim never shows line number for Python files even though I have `.vimrc`

Why it didn't work From :help FileType, *FileType* FileType When the 'filetype' option has been set. The pattern is matched against the ...
D. Ben Knoble's user avatar
  • 25.3k
7 votes
Accepted

Using Pandoc with vim keybindings

Your mapping has a few issues: autocmd FileType markdown nmap <F9> :!pandoc % -o %:r.pdf <cr> You use a recursive command :nmap, but you don't need recursiveness, so you should prefer :...
user938271's user avatar
  • 5,867
7 votes
Accepted

How do I port a filetype command to neovim's lua format?

How can I port filetype plugin indent on? You don't. This is the default (in Neovim). From :he nvim-defaults, Syntax highlighting is enabled by default :filetype plugin indent on is enabled by ...
Matt's user avatar
  • 20.4k
6 votes
Accepted

How to enable syntastic only for Python?

From the syntastic docs: 'syntastic_mode_map' Default: { "mode": "active", "active_filetypes": [], "passive_filetypes": [] ...
Thomas Upton's user avatar
6 votes
Accepted

Why does Vim load unrelated ftplugins?

Vim already comes with Markdown support so what happens is that you have two Markdown ftplugins doing the same thing. Since you "fixed" one (~/.vim/ftplugin/markdown.vim) without "fixing" the other ($...
romainl's user avatar
  • 39.2k
6 votes
Accepted

How to make autocmd FileType work when a file has multiple / compound dot separated types?

Use :autocmd FileType *markdown* :echom "a" This will match for the mk.markdown pattern as well as the regular markdown pattern. It's important to keep the '*' to have the pattern match even when ...
Christian Brabandt's user avatar
6 votes

Is it possible and useful to split vimrc?

Ftplugin As mentioned do put settings pertaining to a certain file type in ftplugin. Separate into Files Break up code into different files. For example where my vimrc file is, there is a sub init/ ...
run_the_race's user avatar
6 votes

Is it possible and useful to split vimrc?

It is completely possible to do what you want. Some of the others have said about filetype plugins which work well for that. But you can source and .vim file in your vimrc so you can split the ....
Spector's user avatar
  • 61
6 votes
Accepted

Change the filetype based on tags / regions in the file

Regarding the proposal and links provided in comments you could define a function as follow: function! s:setFileType() if searchpair('<script', '', '</script>', 'bnW') set ft=...
dNitro's user avatar
  • 401

Only top scored, non community-wiki answers of a minimum length are eligible