Monday, December 26, 2011

Re: why is Vim coloring text in txt files?

On 27/12/11 05:26, wolfv wrote:
> Thanks Tony. I don't know what else to do. Most of this Vim code is
> over my head. I am using Vim 7.3 on Windows 7. This is what it says
> in my :h runtimepath:
>
> PC, OS/2: "$HOME/vimfiles,
> $VIM/vimfiles,
> $VIMRUNTIME,
> $VIM/vimfiles/after,
> $HOME/vimfiles/after"
>
> This is a list of directories which will be searched for runtime
> files:
> filetype.vim filetypes by file name |new-filetype|
> scripts.vim filetypes by file contents |new-filetype-scripts|
> autoload/ automatically loaded scripts |autoload-functions|
> colors/ color scheme files |:colorscheme|
> compiler/ compiler files |:compiler|
> doc/ documentation |write-local-help|
> ftplugin/ filetype plugins |write-filetype-plugin|
> indent/ indent scripts |indent-expression|
> keymap/ key mapping files |mbyte-keymap|
> lang/ menu translations |:menutrans|
> menu.vim GUI menus |menu.vim|
> plugin/ plugin scripts |write-plugin|
> print/ files for printing |postscript-print-encoding|
> spell/ spell checking files |spell|
> syntax/ syntax files |mysyntaxfile|
> tutor/ files for vimtutor |tutor|
>
> So what code do I put in what file?
>
> Regards,
> wolfv

All commands I give below should be run from within Vim.

First, create a vimfiles subfolder in what Vim know as $HOME:

:!mkdir $HOME/vimfiles

If you get an error saying that the directory already exists, that's OK.
For a different error, if it isn't obvious what to do, come back here.

Second, create a filetype.vim in that new subfolder (I assume that you
don't yet have one in _that_ directory):

:e ~/vimfiles/filetype.vim

" filetype detection script (user customizations)
" I'll say this once only
if exists("did_load_filetypes")
finish
endif

" allow continuation lines
let s:cpo = &cpo
set cpo&vim

augroup filetypedetect

" text files
au BufRead,BufNewFile
\ *.txt,README*,LISEZMOI*,LIESMICH*,LEESMIJ*
\ setf text

" add additional filetype detection autocommands above this line
augroup END
let &cpo = s:cpo

Then save your work:

:x

You might also want to set back $VIMRUNTIME/filetype.vim to what it was
before you changed it.

The next time you start Vim, it will regard files matching the patterns
you set in that autocommand as being text files. (I gave an example, you
may vary it if you prefer a different list: LISEZMOI, LIESMICH and
LEESMIJ are used for README in French, German and Dutch respectively.)

Best regards,
Tony.
--
"I can remember when a good politician had to be 75 percent ability and
25 percent actor, but I can well see the day when the reverse could be
true."
-- Harry Truman

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment