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
3
votes
0answers
64 views

Syntax-aware line wrapping

Is there a way to make the automatic line wrapping of vim aware of the syntax of the file instead of just wrapping at the closest whitespace? I am specifically interested in Python but I guess it ...
3
votes
1answer
1k 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. ...
1
vote
1answer
144 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{...
0
votes
1answer
68 views

Disabling indentation for filenames without suffix

VIM's Wikia documentation states that you can disable indentation for certain filestypes by inserting the line let b:did_indent = 1 in the file ~/.vim/indent/<filetype>.vim where <filetype&...
3
votes
1answer
7k 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 # /...
0
votes
2answers
93 views

Scons files not recognised as Python but as conf

Neovim assigns a file type of "conf" to SConscruct and SConscript files -- aka the scons configuration scripts. This is wrong. It should be Python. I tried adding: au BufNewFile,BufRead SCons* setf ...
3
votes
1answer
803 views

Set formatoptions for a specific file

In my ftplugin/plaintext.vim script, I have the formatoptions set for editing mostly prose: setlocal formatoptions=tcroqan1j However, in very specific instances -- particularly, Python's idiomatic ...
18
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 ...
3
votes
2answers
533 views

Are commands in filetype plugins rerun every time the buffer is loaded?

Every time I switch back and forth between two buffers, vim tries to re-load some file specific commands. The error message is E174: Command already exists: add ! to replace it` I am using ...
2
votes
0answers
385 views

in-line math equation rendering/preview for macvim/vim for filetypes other than RMarkdown

I recently installed vim-rmarkdown package, and found that the package allows me to see the rendered math equation in macvim, and when move cursor over, the line will render back to latex equation ...
11
votes
1answer
5k 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 ...
3
votes
2answers
618 views

How to tell vim to behave the same for file extension .in and .mako

I noticed Vim will choose the correct syntax when I open a file that ends with .c.in or .pl.in. I would like to tell Vim to behave the same with extensions like .c.mako or .pl.mako. How is it ...
0
votes
2answers
424 views

Vi/Vim 8 on debian stretch : filetype “bindzone” not loaded automatically

When opening a bind zone file, I have to type by hand :set ft=bindzone to get syntax highlighting. It's not set automatically on load. On another hand others filetypes (such as php, perl or kind) are ...
0
votes
1answer
103 views

Open One File-type per Tab

In vim you can open all files in present directory with vim *. All of a specific file type in directory with vim *.py. Recursively we use vim **/* and vim **/*.py. To open all files in tabs vim -p *...
0
votes
1answer
919 views

How to correctly indent when beginning a new line below the cursor ('o')? [duplicate]

Screenshots My problem I am working on a js file, using eslint as my linter with the ale plugin, configured using the airbnb standard which mandates 2 space indentation. When I open a new line by ...
1
vote
3answers
1k views

How to remove every second column in Vim?

I have a CSV file where I want to remove every second column. Each column value are separated by quotes and the column values can contain field separators: this means that convenient solutions such as ...
3
votes
4answers
2k 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
2answers
1k 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 ...
1
vote
2answers
817 views

Display enclosing namespace, class, and function

How can I convince Vim or Neovim to show the enclosing namespace, class, and function that the cursor is in? Some programming languages have no interesting namespaces or class names. In general, this ...
1
vote
2answers
328 views

Set folding method for c and cpp files, but not h and hpp

I am in the process of customizing my vim setup, and since I write a lot in C, I have a whole function dedicated just for those files, which I call with autocmd filetype c,cpp,h,hpp call C_syntax(). ...
1
vote
0answers
82 views

Why is filetype not set after :find from autocmd?

Objective I want vi file to act like :find file if file doesn't exist. That is, I want to be able to edit a file by name, without giving a path to the file, from the command line: mkdir -p a/b/c ...
1
vote
1answer
925 views

Adding multiple syntax group to a syntax region

I’m writing a syntax file for Bats. I started my syntax file by loading the bash syntax: let g:is_bash=1 runtime! syntax/sh.vim unlet b:current_syntax I then defined the Bats custom keywords: ...
0
votes
1answer
686 views

NeoVim ftplugins Not working - Arch Linux

I have been using vim for a while on Arch Linux and decided to make a shift to Neovim. It's mostly working fine. The vimrc is sourced and thus all my configuration files and plugins are working fine, ...
1
vote
0answers
702 views

Syntastic not working with local eslint

I have a scenario where I have a local .eslintrc and the local eslint package installed. However, I notice that it does not populate a loclist on a file called app.js when I open the file and when I ...
3
votes
2answers
799 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 ...
1
vote
1answer
273 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 ...
2
votes
1answer
154 views

How do I test ftplugin scripts efficiently

Say I am writing a plugin and constantly editing scripts in ftplugin. How do I efficiently test the changes? I can't simply source the editted file because they are filetype-specific. For example, if ...
2
votes
1answer
1k 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&...
4
votes
1answer
853 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 ...
17
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 ...
55
votes
1answer
33k 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
225 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 ...
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
237 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
395 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
1answer
316 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 ...
1
vote
0answers
155 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?
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 ...
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
195 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 ...
4
votes
2answers
298 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-...
3
votes
3answers
703 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 ...
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.)
5
votes
1answer
857 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
289 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
664 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 ...
8
votes
1answer
558 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 ...
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 ...
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
325 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 ...