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?
VIM syntax highlighting
Re:VIM syntax highlighting
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:
If you really want all text files to be detected as Javascript files, you can put the following in your .vimrc:
(at least if I'm not mistaken)
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
Code: Select all
autocmd FileType text setlocal syntax=javascript
Re:VIM syntax highlighting
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
Re:VIM syntax highlighting
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.
Just asking... not that I really expect a fix.
Re:VIM syntax highlighting
I had to change that tomystran wrote:Code: Select all
autocmd FileType text setlocal syntax=Java Script
Code: Select all
autocmd BufEnter *.txt setlocal ft=javascript
Only Human