简体   繁体   中英

TypeScript syntax highlighting in vim

I installed the typescript plugin via

git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/bundle/typescript-vim

and inserted

au BufRead,BufNewFile *.ts   setfiletype typescript

into by ~/.vim.rc . Linting via Syntastic and tsc/tslint works well, and

:set syntax

shows syntax=typescript . However,

:syntax

shows No Syntax items defined for this buffer and highlighting doesn't work.

Any idea what's going wrong?

What was missing from ~/.vimrc is a specification of where to find the plugin, ie,

Plugin 'leafgarland/typescript-vim'

Highlighting works now.

Vim 8 has native package loading. Leave .vimrc alone and just do this:

$ mkdir -p ~/.vim/pack/typescript/start
$ cd ~/.vim/pack/typescript/start
$ git clone https://github.com/leafgarland/typescript-vim.git

There are not so many postings when I searched on line for solving this problem. I installed Vundel, according to the instruction, and add the Plugin line to my ~/.vimrc file. Also added one line

autocmd BufNewFile,BufRead *.ts setlocal filetype=typescript

to vimrc. Still not working. Then I manually copied the typescript.vim file in each of the directories cloned from git: git@github.com:leafgarland/typescript-vim.git

compiler ftdetect ftplugin indent syntax

to their corresponding directories, respectively, to the /usr/share/vim/vim74/. If you use vim8.0 the directory basename will be vim80.

It started to work. This may not be a good solution, but at least it get me started.

While the other answers still work, vim now has TypeScript syntax highlighting built in.

So you can also just upgrade to Vim 8.2 (actually, I think v8.1.1486 is sufficient).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM