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
1
vote
1answer
252 views

Vim typescript files doesn't open first time

I have a strange issue with TypeScript or .ts files in terminal vim. I tried opening it from NERDTree or Control+P. It finds the file but for some strange reason after I hit the Enter key from ...
52
votes
1answer
31k 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 ...
1
vote
1answer
199 views

Enable templating language (e.g., Liquid) syntax highlighting but keep native (html/css) commenting?

I just started working with Jekyll, which uses Liquid. As a templating language, Liquid is embedded into files of other types (e.g., HTML, CSS, or Markdown). Vim handles this sort of dual syntax ...
12
votes
3answers
8k 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 ...
6
votes
1answer
2k 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 ...
0
votes
1answer
222 views

Remove colon from keyword in C++ file?

: is set as keyword (set iskeyword) for C++ source file by default, is there a way to just disable that in my .vimrc file instead of doing set iskeyword-=: every time? It seems the plug-in set the ...
1
vote
1answer
339 views

How do I use regular expressions in ternary statements / keymappings?

I'd like to create a keymapping with a conditional statement, so that it behaves differently when a given line is blank. This thread gave me the following snippet, which is great – except that it ...
1
vote
0answers
144 views

Weird characters are appearing while i move in blank spaces

When I exited Insert Mode I began to move around the file, these images began to appear. Does someone know how to fix it?
3
votes
1answer
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 ...
1
vote
0answers
184 views

Some mappings in my .vim/ftplugin/*.vim change upon entering a window with different filetype, and some don't. What could be the reason for this?

I have special commenting macros for different languages in my ftplugin files, and macros for creating "dividers" (i.e. commented out line of dashes #--------...). I also define a Vimscript filetype ...
3
votes
3answers
618 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 ...
17
votes
1answer
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 ...
5
votes
2answers
2k 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, *....
1
vote
1answer
302 views

Vim indent rules apply to existing files but not to new ones

vim-erlang-runtime is set up for indenting Erlang files that works for already existing files and does not work for any newly created ones. To elaborate, when starting a function body whenever I ...
5
votes
1answer
278 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 ...
3
votes
2answers
636 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 ...
0
votes
1answer
3k views

Executing a function on buffer enter and on buffer leave events?

I would like to execute a certain function every time I leave a buffer associated with C++, and another function every time I enter a C++ buffer. I came up with this so far: " Buffer Leave augroup ...
8
votes
1answer
546 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 ...
3
votes
0answers
54 views

Can I apply one file's filetype to another, without actually opening the first file?

For context, see How can I automate filetype detection when using sudoedit? Say filea has filetype foo, which is detected based on varying factors, including the name, the full path or the contents ...
3
votes
2answers
309 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 ...
5
votes
1answer
778 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 ...
8
votes
1answer
200 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 ...
3
votes
1answer
115 views

How to set filetype to PKGBUILD when the filename is PKGBUILD?

I want vim to automatically set the filetype to PKGBUILD when I am editing files that are named "PKGBUILD". How can I accomplish this?
3
votes
1answer
151 views

Automate running SQL filetype scripts when opening a PHP file

When I open a PHP file in Vim I want Vim to provide SQL assistance as well as all the PHP assistance. From :h sql-completion-filetypes: This can be enabled easily with the following steps (assuming ...
29
votes
4answers
8k 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-...
4
votes
2answers
292 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-...
5
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 ...
5
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.)
27
votes
3answers
13k 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/, ...
11
votes
2answers
9k 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 ...
1
vote
0answers
56 views

filetype plugin not loaded on files opened with edit command

I've turned on filetype indent and plugins on with the following in my vimrc file: filetype indent plugin on Everything is fine when I open a file from terminal, but if I open another buffer ...
4
votes
1answer
426 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
2answers
1k 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: ...
1
vote
0answers
89 views

Strange behaviour when editing c and cpp files after update [closed]

After updating vim, it behaves very irrationally when I try to edit a c or cpp file. Here is a picture: I have tried to debug a bit, and both vim -u NORC -N --cmd 'call pathogen#infect()' file.c ...
1
vote
2answers
860 views

Setting foldmethod=expr when re-sourcing vimrc?

I have the following on my vimrc file to handle custom folding: " ++ Folding set foldenable " enable folding ...
8
votes
4answers
3k 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 ...
2
votes
1answer
1k views

How can I prevent the default loading of ftplugin/text.vim for certain *.txt files

I have to edit a bunch of *.txt files for which I want to define a specific filetype. So, in my vimrc, I add a autocmd! BufReadPost bunchOfFiles/*.txt :set ft=bunchOfFilesFT This reads ftplugin/...
3
votes
1answer
389 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
0answers
73 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 ...
16
votes
3answers
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 ...
1
vote
1answer
135 views

`filetype plugin on` and square brackets

With this .vimrc: nnoremap [ :lp^M nnoremap ] :lne^M filetype plugin on vim becomes sluggish when switching between "errors" of location list with square brackets. As opposed to using lprevious/...
10
votes
2answers
1k 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 ...
5
votes
1answer
3k 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
231 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 ...
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 ...
1
vote
0answers
153 views

Disable tar.vim plugin from command line? [duplicate]

The tar.vim plugin tries to give a special view of tar files. Its filetype "detection" matches against the filename. If I try to download a tar file from the web and get an HTML error page, I cannot ...
16
votes
2answers
5k 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 ...
8
votes
1answer
462 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, ...
95
votes
5answers
90k 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 ...
20
votes
2answers
2k 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=...