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
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 ...
3
votes
1answer
749 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, ...
79
votes
5answers
70k 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 ...
15
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 ...
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 ...
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 $ ...
3
votes
1answer
2k 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
1answer
102 views

formatoptions for hybrid (short markup + long paragraphs) content

I am trying to write my PhD thesis in vim using LaTeX So the documents will have two distinct types of content - markups that are relatively short, and paragraph text that is rather long. \begin{...
3
votes
0answers
258 views

Support for embedded languages

Vim supports syntax highlighting for embedded languages, also called fenced code (:h :syn-include). However, you usually want that other vim settings and mappings are adjusted for embedded languages ...
2
votes
1answer
632 views

Set mappings depending on file type

I'd like to set some file-type dependent mappings to quickly run files. For example, I have some mappings like these: nnoremap <silent><leader>z :w<CR> :!clear; gcc %; ./a.out<cr&...
1
vote
1answer
89 views

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

I am editting typescript now, and I'd like to be able to have it so, whenever :w is invoked, the shell runs tsc compiling my new save. This beats having to !tsc every time. Does something like this ...
19
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=...
22
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/, ...
5
votes
1answer
541 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 ...
3
votes
2answers
496 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 ...
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 ...
5
votes
1answer
251 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
1answer
341 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 ...
11
votes
2answers
7k 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 ...
8
votes
1answer
167 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 ...
7
votes
1answer
904 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
106 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?
3
votes
4answers
979 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, ...
1
vote
1answer
196 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 ...