Questions tagged [filetype]
Questions about making Vim to have a defined behavior according the type of the edited file.
210
questions
115
votes
5
answers
129k
views
How to edit binary files with Vim?
Is there a way to edit binary files in some kind of hexadecimal mode?
For example if I have some binary data shown by xxd or hexdump -C like this:
$ hexdump -C a.bin | head -n 5
00000000 cf fa ed ...
74
votes
1
answer
45k
views
What is the difference between `filetype plugin indent on` and `filetype indent on`?
I see one of these two lines in .vimrc files. This one seems to be most common:
filetype plugin indent on
But how does it differ from this line:
filetype indent on
I've found documentation for the ...
44
votes
4
answers
16k
views
How can I change the default indentation based on filetype?
I'd like to have different indentations based on the type of file I am working on. For example, working on a .c file I'd like my indentation be 4 spaces. In .html files I'd like to (have to) work with ...
38
votes
4
answers
13k
views
Is it possible and useful to split vimrc?
As per the title, is it possible to split the vimrc file in several sub-files? Keep separate files for groups of settings that concern one thing? This thing might be anything, any kind of user-...
36
votes
3
answers
18k
views
How do I tell vim that some file extensions are synonymous?
I edit C++ code in .cpp files, while template code goes into .tcc files. When I open such a file, no syntax highlighting is available. I tried set syntax=cpp in a a tpp.vim file in ~/.vim/ftplugin/, ...
25
votes
2
answers
19k
views
What does "filetype plugin on" really do?
I understand that it loads the ftplugin.vim file, but what does it really do? Does it set options (depending on the filetype)?
If I were to include this line at the start of my vimrc
filetype plugin ...
20
votes
1
answer
3k
views
For an autocmd in a ftplugin, should I use pattern matching or <buffer>?
I have an autocmd for TeX and Markdown files to save the file automatically. Nothing unusual:
autocmd CursorHold *.tex,*.md w
However, as custom settings for these files increased, I split them off ...
20
votes
2
answers
3k
views
Open .md files as Markdown
Vim, by default, opens all .md files as "modula2" code. I have never heard of modula2, nor do I plan to use it.
How can I tell vim to always treat foo.md as Markdown (as if I had typed :set ft=...
18
votes
2
answers
7k
views
How to tell Vim not to try to unzip a file?
I'm trying to open an .xlsx file in Vim, but got an error saying:
***error*** (zip#Browse) unzip not available on your system
I know it's a binary file, but I want to do some checksums and probably ...
18
votes
3
answers
2k
views
Blocking changes to read only file
When using Vim to edit a read only file it will just provide a warning the first time it is edited but allow any changes to take place. I can understand this behaviour could be useful for someone ...
16
votes
2
answers
8k
views
How to create a new vim filetype?
I have html settings set up in my ~/.vim/ftplugin/html.vim file. I would like these settings to apply to Rhtml files as well. I made a symbolic link with
ln -s ~/.vim/ftplugin/html.vim ~/.vim/...
16
votes
4
answers
12k
views
How can I make highlighting commands in .vimrc take effect immediately with Vim 7.4?
I have several highlight commands in my .vimrc file. In Vim 7.3, these took effect immediately after Vim had started. After updating to Vim 7.4, this is not the case anymore. Vim uses its default ...
14
votes
2
answers
13k
views
How do I run a specific vim command when opening a file with a given extension?
I want all of my files ending in .tex to have line length 80. So whenever I open a .tex file in vim I type :set tw=79. What would I put in my .vimrc to automate this?
What if I wanted it to work with ...
14
votes
1
answer
11k
views
What is the difference between 'set ft=' and 'setfiletype'?
I am using vim 8.1. When I need to change the default filetype for .s extension to gas (which by default is asm), I first look for the default command to set filetype in /usr/share/vim/vim81/filetype....
14
votes
1
answer
8k
views
Why is "set noexpandtab" in my ~/.vimrc ignored when I open a file? [duplicate]
I'm using Mac OS X 10.12 and I have set noexpandtab in my ~/.vimrc
There are 2 different behaviors :
$ vim file.py
If run Vim (8.0) to open one file and type :set expandtab?, it says expandtab
$ vim
...
12
votes
4
answers
4k
views
How do I define an autocommand to work on all files excepted a certain filetype?
For example, I have the following autocommand definition:
augroup cursorline
autocmd!
autocmd WinLeave,BufLeave * set nocursorline
autocmd WinEnter,BufEnter * set cursorline
augroup end
...
11
votes
2
answers
2k
views
Use single ftplugin for more than one filetype
I have an ftplugin under &runtimepath/ftplugin/c.vim which sets all my preferred options for c files. However, I would also like to use the same settings for cpp files. I could just copy the ...
11
votes
3
answers
3k
views
Setting syntax in ftplugin
I’m trying to set the syntax of Processing files (*.pde) to java with a ftplugin.
.vim/
after/
ftdetect/
pde.vim
ftplugin/
processing.vim
In after/ftdetect/pde.vim I ...
10
votes
0
answers
853
views
Support for embedded languages
Vim supports syntax highlighting for embedded languages or fenced code in markdown (:h :syn-include).
However, you usually want that other vim settings and mappings are adjusted for embedded languages ...
9
votes
1
answer
1k
views
How to do file type detection based on file contents (e.g. a certain shebang line)?
I have created a few scripts in .vim/ftdetct to e.g. detect the filetype of sshconfig files based on their filename:
autocmd BufRead,BufNewFile ~/.ssh/host-* setfiletype sshconfig
Now, how can I make ...
9
votes
2
answers
297
views
How can I get correct autocompletion for ambiguous file extensions?
I'm editing Prolog files as part of an exploratory project, and some of the files I'm working with have the extension .pl, which is shared by Perl files. Whenever I do work on a Prolog file named [...
8
votes
1
answer
630
views
Run shell commands on current file based on file extension
I'm currently doing a lot of work with both Ruby and JavaScript. I know that I can run my Ruby files with :! ruby % and likewise my JavaScript with :! node %, and that I can bind either of those to, ...
8
votes
1
answer
252
views
The first and last 5 lines of a file? Use for file specific spell ignore list?
Rumor has reached me that it is possible to place vim commands in the first five, or in the last five lines of a a file. But, I could not find this in Google. Any leads would be appreciated.
I ...
8
votes
1
answer
3k
views
How to force Vim to open given file as another filetype? (e.g. .txt.gz?)
Problem:
I have .glabels generated files, which are gzipped xml. When I rename file to have suffix .xml.gz, then VIM properly recognizes file and it's editable, human readable xml. After edit I have ...
8
votes
1
answer
603
views
What controls indentation of lines following an open square bracket when using cindent?
I am trying to build my own indent file for JavaScript. The default indent file for JavaScript turns cindent on, with minimal modifications, and I am using that as a base.
On Vim 7.3 for OSX El ...
7
votes
1
answer
4k
views
Filetype that LaTeX should be
From :help filetype:
If the first line of a *.tex file has the form %&<format> then this
determined the file type: plaintex (for plain TeX), context (for
ConTeXt), or tex (for ...
7
votes
2
answers
2k
views
Mardown files always have vimwiki filetype (vimwiki plugin)
Here is the relevant content of my .vimrc
let g:vimwiki_global_ext=0
let g:vimwiki_list = [{'path': 'C:\Users\<USER>\vimwiki',
\ 'syntax': 'markdown', 'ext': '.md'}]
The ...
7
votes
2
answers
3k
views
Multiple vimrc files for different file types in vim?
I'm a vim beginner. I want to handle multiple programming languages. I find great resources for how to perfect vim for one programming language by putting ton of stuff in one vimrc file. This is ...
6
votes
2
answers
190
views
Setting up ++ft according to the file extension
I have a lot of *.sage that follow the Python syntax. However, VIm does not recognize this. Can I make VIm set ++filetype based solely on the file extension?
6
votes
2
answers
2k
views
How to make autocmd FileType work when a file has multiple / compound dot separated types?
While working a Markdown plugin, we've wanted to change the filetype from mkd to markdown to increase compatibility with other plugins.
To avoid breaking users .vimrc that had autocommands like:
...
6
votes
1
answer
3k
views
In what order does Vim read ftplugin files, syntax files, and the .vimrc when the commands (e.g. set syntax=mysyntax, filetype plugin on) are called?
I've had some issues lately reconciling my .vimrc with files in ftplugin and after/ftplugin. In what order are all these things read?
For example: when I call in my .vimrc the command plugin filetype ...
6
votes
1
answer
1k
views
How can I automate filetype detection when using sudoedit?
sudoedit/sudo -e is often used for safely editing files as root. The way it works:
sudoedit copies the named files to temporary files
Then it opens the temporary files using the commands specified by ...
6
votes
1
answer
591
views
Where are vim compound (dotted) filetypes documented
Vim has some kind of support for dot-separated compound filetypes like "ruby.rspec" where settings/definitions for both will be loaded. I see mentions of it around the internet but I can't find any ...
6
votes
1
answer
1k
views
How to debug "Unknown function: dist#ft#SetFileTypeSH" after upgrade to 8.1
edit: Solution found! At the bottom of the post
I installed vim 8.1 via brew on macos Sierra yesterday, and I think that broke some of the filetype setting stuff. When I open a shell script, I get ...
6
votes
1
answer
510
views
Why does the "rst" filetype automatically indent subsequent list items?
I've been having trouble understanding the behavior defined in GetRSTIndent() in indent/rst.vim. I'm specifically using Neovim v0.2.2, but I believe this file has not changed between Vim/Neovim.
...
6
votes
2
answers
262
views
Identify if a buffer is CtrlP or not
I use a autocmd to display current tag via Tabgar plugin like this:
autocmd CursorHold * call TagbarCurrentTag
However, after I open CtrlP with :CtrlP for a while, the Tagbar's output No current tag ...
6
votes
0
answers
95
views
Filetype changes when using :split and :Explore
Why does using :split and :Explore cause the filetype to change?
For example, edit a file named text.man, and the filetype is set to man. Change the filetype to txt, then :split and :Explore in the ...
5
votes
2
answers
3k
views
Is there any list of filetype extension names?
I was told when add a line like # vim: filetype=r in a file, vim can recognizes the file type. It seems that for some files like *.cpp,*.java, vim can recognize the file while for files like *.CPP, *....
5
votes
1
answer
2k
views
How does Vim know how to syntax-highlight some files with strange extension or without extension at all?
Take markdown file as an example. I often found that some downloaded files suffixed with .md (rather than .markdown) can be recognized as markdown file, and syntax-highlighted as such. However, it ...
5
votes
3
answers
1k
views
How do I elegantly override file type detection patterns with more specific patterns
I have a file in my ~/.vim/ftdetect directory, which includes configuration such as:
autocmd BufRead,BufNewFile,BufWritePost .envrc.template set filetype=sh
However, I also have the vim-polyglot ...
5
votes
3
answers
2k
views
Syntax highlight fail for Prolog files
I'm having trouble configuring Vim on Manjaro:
After setting syntax on at .vimrc file, I make a Prolog program (bug.pl) which shows no syntax highlight:
But after I append /**/ to top of file (then ...
5
votes
2
answers
2k
views
How to enable syntastic only for Python?
There are various questions and answers about disabling/blacklisting certain file types.
How do I disable syntastic for all but one filetype? (Let's say Python.)
5
votes
3
answers
1k
views
Is it possible to create a function with the same name for different filetypes (and different implementations)?
Is it possible to create several functions with the same name whose implementation depends on the file type?
For example, I could imagine a function named CurrentFunctionName that returns the name of ...
5
votes
1
answer
2k
views
In an autocmd what's the use of the BufRead event?
I'm trying to learn a bit of vimscript and currently reading the 12th chapter of Learn Vimscript the Hard Way.
In this page, the author says :
A common idiom in Vim scripting is to pair the ...
5
votes
1
answer
361
views
Run file though a command when opening from Explore
I have configured vim to automatically decompile ".class" files similar to the instructions in: http://vim.wikia.com/wiki/VimTip54.
I have made a minor change to use cfr_0_115 as below:
augr class
...
4
votes
2
answers
325
views
Why does Vim load unrelated ftplugins?
When I open a file with .md extension, the filetype is set to markdown, as expected. But the ftplugin for HTML is also loaded as I can see since I have some insert mode mappings in there to auto-...
4
votes
3
answers
836
views
Vim can't detect if a file is vim file type by commenting a file with vim:ft=vim
It used to work by adding following line into a file even it has no suffix .vim, my vim version is v8.0.1500, on OS X 10.13.3
" vim:ft=vim
UPDATE:
I tried adding following two lines to $MYVIMRC, ...
4
votes
2
answers
365
views
How to display messages for a particular file type?
Is there any way to display messages in vim depending on the filetype being edited? It would be good if the messages pop after some specified time interval.
Use case
We tend to forget style guide ...
4
votes
1
answer
1k
views
Vim never shows line number for Python files even though I have `.vimrc`
I found it strange that I can never have Vim show line number automatically for .py files, even if I have this as my ~/.vimrc
set background=dark
autocmd FileType py,c set number
Strangely enough, ...
4
votes
1
answer
1k
views
Change the filetype based on tags / regions in the file
Recently I've started up with vuejs and I'm currently trying to set up my editor for using it. Vue uses a similar approach with React - keeping the HTML, Javascript & CSS in the same file - it ...