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 ...
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) ...
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 ...
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 ...
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
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 ...
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.
...
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 ---
...
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
...
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/...
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 ...
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 ...
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, ...
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 ...
12
votes
Blocking changes to read only file
Add this to your .vimrc:
augroup NoModWhenReadOnly
autocmd!
autocmd BufRead * let &l:modifiable = !&readonly
augroup END
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
...
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 ...
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 ...
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 ...
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
...
Community wiki
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 ...
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 :...
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 ...
6
votes
Accepted
How to enable syntastic only for Python?
From the syntastic docs:
'syntastic_mode_map'
Default: { "mode": "active",
"active_filetypes": [],
"passive_filetypes": [] ...
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 ($...
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 ...
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/ ...
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 ....
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=...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filetype × 216autocmd × 45
vimrc × 35
syntax-highlighting × 25
neovim × 17
indentation × 16
vimscript × 15
key-bindings × 11
plugin-system × 9
filetype-tex × 9
buffers × 6
folding × 6
ftplugin × 6
formatting × 4
statusline × 4
comments × 4
filetype-markdown × 4
filetype-python × 4
ftdetect × 4
command-line × 3
gvim × 3
autocompletion × 3
functions × 3
netrw × 3
plugin-ultisnips × 3