VIM syntax highlighting

Programming, for all ages and all languages.
Post Reply
Neo(out)

VIM syntax highlighting

Post by Neo(out) »

I have a query regrading the symtax highlighting in VIM. I have a normal user access to a remote machine and I have to edit some text files that are actually javascript files. Is there any way i can get the files ending with .txt to highlight as the javascript files for me? I cannto add any syntax files in the syntax dir of vim.
so is there any other way?
mystran

Re:VIM syntax highlighting

Post by mystran »

First of all, IIRC you can put all configuration in ~/.vim directory as well as the system-wide directory. So putting a custom systax highlight-script into ~/.vim/syntax/whatever.vim should work.

The second thing is with detecting filetype. Normally I would expect Vim to detect JavaScript when the file-extension is .js
but if you want .txt too, there are couple of options:

- Configure the detection in your .vimrc
- use a comment, with vim:syntax=javascript: in your javascript files

Notice that in order to get syntax highlighting at all, you might need to put the following in your ~/.vimrc:

Code: Select all

" enable syntax high-lighting
syntax on

" enable filetype autodetection
" also detect auto indent..
filetype plugin indent on
If you really want all text files to be detected as Javascript files, you can put the following in your .vimrc:

Code: Select all

autocmd FileType text setlocal syntax=javascript
(at least if I'm not mistaken)
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:VIM syntax highlighting

Post by Neo »

I just found out there I can open the file and then issue the command 'set ft=javascript' to get it to highlight accordingly. Is there any way this command can always be executed when i start VI /VIM
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:VIM syntax highlighting

Post by Solar »

~/.vimrc.
Every good solution is obvious once you've found it.
mystran

Re:VIM syntax highlighting

Post by mystran »

Urgh.. does this forum still convert "java"+"script" (that is, those words written together without a space between) automatically to Java Script? And if so, is there any sensible reason why this happens? It... kinda annoying every time we need to talk about javascript.

Just asking... not that I really expect a fix. :)
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:VIM syntax highlighting

Post by Neo »

mystran wrote:

Code: Select all

autocmd FileType text setlocal syntax=Java Script
I had to change that to

Code: Select all

autocmd BufEnter  *.txt  setlocal ft=javascript
Only Human
Post Reply