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,202
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,013
22 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.7k
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.8k
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

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.7k
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,913
10 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.6k
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
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.8k
7 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
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,907
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.6k
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
6 votes
Accepted

Is it possible to have vim run a command every time save `:w` is invoked?

Does something like this exist? In Vim this is called an autocommand. The relevant help topic can be found by typing :h autocommand (sic!) An example code to put into vimrc: augroup typescript_save ...
Matt's user avatar
  • 20.6k
6 votes
Accepted

What is the most idiomatic way to achieve filetype-specific functions?

Function defined in ftplugins In ftplugins we can define script local functions and global functions that are defined only when a buffer of the given filtetype is loaded. In the second case, the ...
Luc Hermitte's user avatar
  • 17.3k
5 votes

How to set commands for unrecognised file type

Use a function for this: function! FTManage() let l:filetype = &filetype if l:filteype == 'data' " do stuff endif endfunction autocmd! FileType * call FTManage() Here you pass ...
nobe4's user avatar
  • 16k
5 votes
Accepted

How to set commands for unrecognised file type

You could use the BufEnter autocommand event like this: autocmd! BufEnter *.data :iabbr <buffer> di ditto The abbreviation will be created when you enter a buffer which is named anything ...
statox's user avatar
  • 49.6k
5 votes
Accepted

In what order does vim read ftplugin files, syntax files, and the .vimrc when `filetype plugin on` and `set syntax=filetype` are called?

When filetype plugin on is encountered in your vimrc, $VIMRUNTIME/ftplugin.vim is immediately executed. This creates an auto command which does the following: exe 'runtime! ftplugin/' . name . '.vim ...
Antony's user avatar
  • 2,570
5 votes

How can I automate filetype detection when using sudoedit?

tpope/vim-eunuch Like you've discussed, $SUDO_COMMAND can be used to find the original filename(s). Together with a nifty usage of fnameescape and doautocmd it is possible to deduce the correct ...
timss's user avatar
  • 291
5 votes

How to force Vim to open given file as another filetype? (e.g. .txt.gz?)

There are two answers to your question: General In order to open a file, overriding the default filetype detection, you can just specify a :setf[iletype] command as part of :edit. For example: :...
Ingo Karkat's user avatar
  • 17.8k
5 votes
Accepted

Autocmd on directory to replace netrw

I had a look at how Dirvish did it, and tested this: augroup ranger au! au VimEnter * sil! au! FileExplorer * au BufEnter * if s:isdir(expand('%')) | bd | exe 'Ranger' | endif augroup END ...
user9433424's user avatar
  • 6,118
5 votes
Accepted

Is it possible to create a function with the same name for different filetypes (and different implementations)?

Inside ftplugin/<filetype>.vim you could set a buffer local variable to point to the correct function: function s:CurrentFunctionName() abort " Implement the function here endfunction let b:...
Nate Bosch's user avatar

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