Questions tagged [filetype]

Questions about making Vim to have a defined behavior according the type of the edited file.

Filter by
Sorted by
Tagged with
79
votes
5answers
68k 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 ...
39
votes
1answer
21k 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 ...
34
votes
4answers
8k 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 ...
21
votes
3answers
9k 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/, ...
21
votes
2answers
5k 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-...
19
votes
2answers
1k 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=...
14
votes
2answers
4k 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 ...
14
votes
3answers
1k 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 ...
14
votes
1answer
2k 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 ...
11
votes
2answers
6k 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 ...
9
votes
3answers
5k 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 ...
8
votes
2answers
6k 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 ...
8
votes
2answers
236 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
1answer
368 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
1answer
161 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
1answer
453 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
3answers
2k 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 ...
7
votes
1answer
885 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 ...
6
votes
2answers
105 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
1answer
3k 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 $ ...
6
votes
1answer
637 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 ...
6
votes
2answers
157 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 ...
5
votes
2answers
1k 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
1answer
1k 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
1answer
517 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 ...
5
votes
1answer
245 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
2answers
236 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
1answer
3k views

What is the 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....
4
votes
2answers
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.)
4
votes
1answer
679 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 ...
4
votes
2answers
967 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: ...
4
votes
2answers
147 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 ...
4
votes
1answer
327 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 ...
4
votes
1answer
284 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 ...
4
votes
1answer
1k 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 ...
4
votes
1answer
226 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. ...
3
votes
2answers
559 views

How to set commands for unrecognised file type

I want to set some commands for specific filetypes. For example an abbreviation: :iabbr Sb SameBatch The files have extension like .data, .pro. Their grammar, syntax-highlighting are defined in the ...
3
votes
2answers
248 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 ...
3
votes
1answer
561 views

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

I always prefer shebangs over extensions. A lot of times I make a new file without an extension in vim, which gets opened as plain text, since no extension is provided, which is completely normal. ...
3
votes
4answers
934 views

Autocmd on directory to replace netrw

I use the ranger plugin wich I can trigger with a shortcut. But when I open a directory I would like to use the plugin instead of netrw. So I have found that the filetype of directories is netrw, ...
3
votes
3answers
419 views

Is it possible to add a specific text string in the beginning of creating a certain file type? [duplicate]

Just like the topic says; is it possible to add a certain text string in the beginning of a file if I create a certain file type? For example, if I create a random Python file with vim random.py. Can ...
3
votes
1answer
2k 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 ...
3
votes
2answers
197 views

write a key command for a markdown comment

I've been messing about with file type specific commands this evening (which is going to be very useful) and I'm trying to write a markdown comment command at the moment. I'm not sure how to go about ...
3
votes
1answer
396 views

Using Pandoc with vim keybindings

I am trying to define a keymapping in vimrc to compile my markdown file with Pandoc. So I am using this: autocmd FileType markdown nmap <F9> :!pandoc % -o %:r.pdf <cr> But, in markdown ...
3
votes
2answers
475 views

Selectively enable a subset of vim plugins for specific category of workflows (plugin virtualenv for vim projects)

I use vim for many different categories of projects, typically: Writing code (3 languages, python, Matlab and C) Writing documentation ( .rst, .html) Writing reports (.tex) Readme file (.md) As a ...
3
votes
1answer
1k 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 ...
3
votes
1answer
716 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, ...
3
votes
3answers
758 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 ...
3
votes
1answer
322 views

Jump to the definition in a scss file

How, in vim, can I jump to the mixin that is @includeed in a SCSS file? For example, I'd like to put the cursor over avatar below and hit some magic key in vim that'll take me to that mixin...but how?...
3
votes
1answer
33 views

Ask if file extension is missing when opening new file

I use auto completion in my shell (zsh) and I'm often a bit sloppy. Scenario: Imagine I have the files sourcecode.c and sourcecode.h in the current directory. I type vim sour<TAB><ENTER> ...