Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: would like it to turn settings on only for certain file types

Tags:

I've looked at this but it wasn't too much help. Maybe I didn't read it too well.

Basically what I want is when I open a .txt file the settings:

set wrap set linebreak 

are turned on. How might I go about doing that?

Thanks in advance.

Also, I'm using XP.

like image 876
Nope Avatar asked Jan 22 '09 15:01

Nope


People also ask

How do I change the filetype in Vim?

As other answers have mentioned, you can use the vim set command to set syntax. :set syntax=<type> where <type> is something like perl , html , php , etc. There is another mechanism that can be used to control syntax highlighting called filetype , or ft for short.

What is the use of Vimrc?

Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.

Where is filetype Vim?

$HOME\vimfiles\filetype. vim (Windows systems)


2 Answers

My answer to that question still applies:

Put autocmd commands based on the file suffix in your ~/.vimrc

autocmd BufRead,BufNewFile   *.txt set wrap linebreak 

As Luc says, you might prefer to

autocmd BufRead,BufNewFile   *.txt setlocal wrap linebreak 

if you're likely to open txt and non-txt files at the same time.

like image 172
Paul Tomblin Avatar answered Sep 29 '22 19:09

Paul Tomblin


Put this into ~/.vim/ftdetect/text.vim (this path will be slightly different on windows):

autocmd BufRead,BufNewFile *.txt setfiletype text 

Then put this into ~/.vim/ftplugin/text.vim:

setlocal wrap setlocal linebreak 

It's preferable to only do the autocmd once for a filetype, and to separate it from your vimrc file.

like image 44
Jeremy Cantrell Avatar answered Sep 29 '22 19:09

Jeremy Cantrell