36

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?

Nico Schlömer
  • 37,093
  • 21
  • 139
  • 189
  • 2
    I installed [Pathogen](https://github.com/tpope/vim-pathogen) and the `au ...` instruction in the `~/.vimrc` is all I need. – bloodyKnuckles May 21 '17 at 13:48
  • 1
    I think over time this has changed a bit. I went to this plugin's github and now it only requires this `git clone https://github.com/leafgarland/typescript-vim.git ~/.vim/pack/typescript/start/typescript-vim` to actually work. – DAEMonRaco Dec 03 '19 at 17:33

4 Answers4

32

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

Plugin 'leafgarland/typescript-vim'

Highlighting works now.

Nico Schlömer
  • 37,093
  • 21
  • 139
  • 189
18

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
dino
  • 1,015
  • 8
  • 13
  • 4
    The problem with this approach is that when you move to a new machine and need this set up again, you have nothing in .vimrc that helps you install the plugins you've been using. – mrk May 07 '19 at 18:01
  • 1
    I have .vim as a git repo, and install plugins with `git submodule add` instead of `git clone`, so it's all tracked – Mark K Cowan May 11 '20 at 17:32
3

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.

Kemin Zhou
  • 4,375
  • 1
  • 29
  • 47
  • Thanks, worked for me. In the ftdetect/typescript.vim file the following options are set: `" use set filetype to override default filetype=xml for *.ts files` `autocmd BufNewFile,BufRead *.ts set filetype=typescript` `" use setfiletype to not override any other plugins like ianks/vim-tsx` `autocmd BufNewFile,BufRead *.tsx setfiletype typescript` it would probably be safest just to copy that into .vimrc – MyrionSC2 Oct 27 '19 at 10:05
0

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).

sleske
  • 73,934
  • 32
  • 166
  • 212