Questions tagged [filetype]
Questions about making Vim to have a defined behavior according the type of the edited file.
35
questions
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 ...
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, ...
10
votes
0
answers
855
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 ...
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
...
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 ...
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 ...
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 ...
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
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....
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 ...
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 ...
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 ...
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 ...
3
votes
1
answer
2k
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
1
answer
202
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{...
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
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=...
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/...
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 ...
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
2
answers
191
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?
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
0
answers
889
views
"^[[201~" character being pasted at the end of file
I'm trying to copy-paste by hand this file, but whenever I paste the contents in vim the last line shows this weird character at the end of the line ^[[201~.
My guess is that it's one of those wrong ...
3
votes
1
answer
10k
views
Why files in `~/.config/nvim/after/ftplugin/` are not taken into acount?
My neovim doesn't load file type plugins when loading a ruby/eruby file. Here is the corresponding configuration files:
for f in ~/.config/nvim/after/ftplugin/* ; do echo "# $f" ; cat $f; done
# /...
3
votes
2
answers
1k
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
4
answers
3k
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, ...
2
votes
2
answers
271
views
Where do filetype-specific autocommands live?
I have a plugin for a specific filetype (*.tex), and I'm wondering where I can find all the commands which are executed when I type :e examplefile.tex? In general, is there a standardized practice for ...
2
votes
0
answers
703
views
Vim not recognizing markdown and tex files
Here is a sample of my .vimrc, that doesn't do a thing (the autocmd does not work) when I open a .md or .tex file, but works fine for .py files:
augroup filetype_python
autocmd FileType python ...
1
vote
1
answer
589
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 ...
0
votes
2
answers
4k
views
How do I port a filetype command to neovim's lua format?
Currently my .vimrc file has this in it,
filetype plugin indent on -- filetype detection[ON] plugin[ON] indent[ON]
How can I port filetype plugin indent on to neovim's lua format?
0
votes
1
answer
265
views
filetype plugin indent on is blowing up my vim
I have the following vimrc.
I noticed that there is a single line that's blowing up my usage of the FZF :BTags command:
filetype plugin indent on
Ie when I run the command :BTags I get this error
...