tags:

views:

464

answers:

3

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.

+9  A: 

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.

Paul Tomblin
Almost. Don't use :set, but :setlocal.
Luc Hermitte
@Luc, what's the difference?
Paul Tomblin
:set changes the settings for all windows, :setlocal for the window containing the blah.txt buffer.
rampion
thanks guys for your help.
Casey
Then accept the answer, as it helps.
Zsolt Botykai
@Zsolt Botykai...accepted ;)
Casey
:set applies not to all windows, but to all buffers.
Luc Hermitte
+3  A: 

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.

Jeremy Cantrell
You know, I could see wanting to keep these things if you're going to have dozens of rules for dozens of different file types, but in my case, I have about 3 lines that apply to c, c++, java and .pl, and that's about it. I can't see proliferating files all over the place for that.
Paul Tomblin
I really don't think I deserved a downvote just because you prefer bunches of files instead of one.
Paul Tomblin
I prefer the correct way. The downvote was not because I dislike you, but because I feel your answer is not the preferable way of doing it. Let's be adults here. Try not to take it personally.
Jeremy Cantrell
A: 

A good solution to this is the "after" directory. You can add an rc file for anything you want in there, syntax highlighting, file types, etc. These configurations are run after all other configurations are run, so after the system configs and after your .vimrc. So you can create, on a unix type system, an file called ~/.vim/after/ftplugin/text.vim and add the two lines you want in there. They options will be set for the text file type, but not for other file types. You can have different files in each of those directories for other filetypes, such as perl.vim.

Since you are not in a unix environment, you will need to find your [runtime directory][1] by checking the [runtimepath][2] option. You would create your "after" directory and the files there.

NOTE:

The links are not working for me, probable because of the anchors:

gpojd