We’re rewarding the question askers & reputations are being recalculated! Read more.
90

The simplest way is to use the binary option. From :help binary: This option should be set before editing a binary file. You can also use the -b Vim argument. When this option is switched on a few options will be changed (also when it already was on): 'textwidth' will be set to 0 'wrapmargin' will be set to 0 'modeline' will be ...


46

filetype plugin indent on is like a combination of these commands: filetype on filetype plugin on filetype indent on It turns on "detection", "plugin" and "indent" at once. You can check for yourself by reading :help :filetype-overview. Detection What does filetype "detection" do? From the docs: Each time a new or existing file is edited, Vim will try ...


25

The best method is to put those settings in ~/.vim/after/ftplugin/<filetype>.vim. For HTML (assuming you want 4 characters-wide tabs): ~/.vim/after/ftplugin/html.vim setlocal shiftwidth=4 setlocal softtabstop=4 setlocal noexpandtab Using an ftplugin is prefered to using autocommands because Vim already does filetype checks by itself and already ...


21

Yes this is possible and useful and even considered best practice. They are called filetype plugins in Vim speech. And Vim even comes with many filetype plugins (as well as indent and syntax files) for several languages. You need to enable this in your .vimrc like this: filetype plugin on then put your specific filetype settings into a file (creating non-...


19

To view the content of a binary file in a hex view, open the file, switch on binary mode, and filter the buffer through the xxd command: :set binary :%!xxd You can make changes in the left area (edit the hex numbers), and when ready, filter through xxd -r, and finally save the file: :%!xxd -r :w If the filtering step after opening and before closing ...


19

The preferred approach is to create a ~/.vim/filetype.vim, as mentioned in :help 43.2 and explained in Vim FAQ 26.8: A better alternative to the above approach is to create a filetype.vim file in the ~/.vim directory (or in one of the directories specified in the 'runtimepath' option) and add the following lines: " my filetype file if exists("...


16

The reason Vim detects the filetype for *.cpp and not for *.CPP files is that Vim has auto-commands for *.cpp setting the filetype, but nothing for *.CPP: :au BufRead *.cpp --- Auto-Commands --- filetypedetect BufRead *.cpp if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif :au BufRead *.java --- Auto-Commands --- filetypedetect ...


15

Functionality like this is handled by autocmds. In order to disable autocmds for a specific command, you can use :noautocmd (abbreviated :noau). In this case :noau e foo.xlsx will simply open the raw file rather than triggering the autocmds that try to open the zip file. You can also use this from your shell: $ vim -c 'noau e foo.xlsx' If you want ...


14

I currently have this line as an ugly hack in my .vimrc: autocmd BufRead *.md set ft=markdown I'm still wondering if there's a better way, though.


14

You can do this with autocommands in your .vimrc. For example, I have a function html_like_mode that sets up various things for editing HTML files. In my .vimrc, I have: au BufNewFile,BufRead *.html call s:html_like_mode() That keys off of the file extension. You can also key off of the filetype, if you have that enabled: au FileType perl setlocal ...


14

You could do (in your global .vimrc): autocmd BufEnter *.tpp :setlocal filetype=cpp


13

I found a solution. Setting nomodifiable prevents the file being edited (as used in help windows). I created a simple function to set or unset modifiable depending on if readonly is set and attached it to an autocmd. " Don't allow editing of read only files autocmd BufRead * call RONoEdit() function! RONoEdit() if &readonly == 1 set nomodifiable ...


11

Is this usage of <buffer> correct? I think it is correct, but you just need to wrap it inside an augroup, and clear the latter, to make sure that the autocmd won't be duplicated every time you execute a command which reloads the same buffer. As you explained, the special pattern <buffer> allows you to rely on the built-in filetype detection ...


10

This seems to the the "zip" plugin, which is shipped with Vim and enabled by default. :help zip has some information about it, among other things: PREVENTING LOADING If for some reason you do not wish to use vim to examine zipped files, you may put the following two variables into your <.vimrc> to prevent the zip plugin from loading: let g:...


10

You could use :make for this; you can set makeprg (short for make program) to any command. Some examples: au FileType ruby set makeprg=ruby\ % au FileType javascript set makeprg=node\ % au FileType python set makeprg=python\ % au FileType coffeescript set makeprg=coffee\ -c\ % noremap ,b :make<CR> :make was originally intended to run the make tool ...


10

In the file filetype.vim that is shipped with your distribution you will find a line that looks probably similar to this (on my machine it lives at /usr/share/vim/vim74) : au BufNewFile,BufRead *.md,*.m2,*.mi setf modula2 Now, this tells vim to set the filetype as modula2 if your file has such an ending. To override this behaviour you can put a line like ...


10

Instead of checking the extension and setting the textwidth accordingly you could simply create a tex.vim (the name must match the filetype) file in .vim/ftplugin/ or for Windows $HOME/vimfiles/ftplugin/ and set textwidth there. This will help you to keep your .vimrc clean. Your .vim/ftplugin/tex.vim file would look like: setlocal textwidth=79 As 8bittree ...


9

augroup allows you to group related autocommands into named groups. (See here to learn about Autocommand Groups.) We use augroups to add autocommands to ~/.vimrc in a way that won't add a duplicate every time we source it. augroup vimrc autocmd! augroup END autocmd vimrc FileType html setlocal shiftwidth=4 tabstop=4


9

In the file recognition procedure used to detect what syntax highlighting to use, there can be a few kinds of checks. The most known one is checking the the file extension. This is done by a command of the following structure: au BufRead,BufNewFile *.my setfiletype my-type Another way, used for makefiles for example, is assigning the auto-cmd ...


8

The default ftplugin (/usr/share/vim/vim74/ftplugin/cpp.vim on my system) should already do this: " Only do this when not done yet for this buffer if exists("b:did_ftplugin") finish endif " Behaves just like C runtime! ftplugin/c.vim ftplugin/c_*.vim ftplugin/c/*.vim runtime should be relative to the runtimepath: There can be multiple {file} ...


8

In ~/.vimrc you can add the following line: au BufReadPost,BufNewFile *.md,*.txt,*.tex setlocal tw=79 For extra commands, separate them by |. This will set your settings right after reading the file, or opening a new file into the buffer for specific extensions.


7

Add this to your .vimrc: autocmd BufRead * let &l:modifiable = !&readonly


7

When there's not enough information to decide otherwise, 'filetype' is set to the most basic -- plaintex. Your existing file must have had enough content for the detection to determine that it was actually LaTeX, so 'filetype' was set to tex. The required command to prefer LaTex when there isn't enough information is let g:tex_flavor = "latex" Note, that'...


7

If the file has been saved the easiest way is simply to run: :e However, if the file has not been saved, this will result in an error. In this case a different command can be run: :filetype detect If this seems like too much to type, a mapping can easily be made and placed in your vimrc: nnoremap <F5> :filetype detect<CR>


6

In the same spirit as @Sundar answer but with a little more flexible syntax you can do: let ftToIgnore = ['latex', 'plaintex'] autocmd BufWritePre * if index(ftToIgnore, &ft) < 0 | set your options I tend to prefer this syntax because: You can easily add new filtetypes if you want. The condition length stay the same no matter how many filetypes you'...


6

Use the "bvi" editor. http://bvi.sourceforge.net/ (It's in every Linux repository.) $ apt-cache show bvi [snip] Description-en: binary file editor The bvi is a display-oriented editor for binary files, based on the vi text editor. If you are familiar with vi, just start the editor and begin to edit! If you never heard about vi, maybe bvi is not the ...


6

I can only answer the second part of your question. You can tell Vim that you're editing a Prolog file with this command: :set syntax=prolog If you never work in Perl, then it wouldn't seem "dictatorial" to add custom configuration in your ~/.vimrc: autocmd BufNewFile,BufRead *.pl setfiletype prolog syntax=prolog


6

Vim already comes with Markdown support so what happens is that you have two Markdown ftplugins doing the same thing. Since you "fixed" one (~/.vim/ftplugin/markdown.vim) without "fixing" the other ($VIMRUNTIME/ftplugin/markdown.vim), your fix is simply overridden by the built-in ftplugin. If you insist on disabling HTML support in markdown buffers you can ...


6

There is actually a good description in help filetype. Any options that are defined for a filetype will be set with setlocal: :setl[ocal] ... Like ":set" but set only the value local to the current buffer or window. Not all options have [..] For example /usr/share/vim/vim80/ftplugin/javascript.vim defines: setlocal commentstring=/...


Only top voted, non community-wiki answers of a minimum length are eligible