Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 674
Nico Schlömer Avatar asked Jan 29 '16 15:01

Nico Schlömer


People also ask

How do I enable syntax highlighting in Vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

Does vim support TypeScript?

vim-jsx-pretty does have TypeScript support, but I had some performance issues when highlighting large TSX files. For projects that use styled components, I use styled-components/vim-styled-components which highlights CSS inside the styled and css template strings.

Does vim have syntax highlighting?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.

What is Vim polyglot?

A collection of language packs for Vim. One to rule them all, one to find them, one to bring them all and in the darkness bind them. It won't affect your startup time, as scripts are loaded only on demand*. It installs and updates 120+ times faster than the 599 packages it consists of.


2 Answers

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

Plugin 'leafgarland/typescript-vim' 

Highlighting works now.

like image 72
Nico Schlömer Avatar answered Oct 03 '22 23:10

Nico Schlömer


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 
like image 34
dino Avatar answered Oct 04 '22 00:10

dino