Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typescript syntax files for Vim

NotificationsYou must be signed in to change notification settings

leafgarland/typescript-vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


NOTE: This Typescript syntax was created before Typescript's 1.0 release, more than a decade ago. I hope ithas been helpful but there are now other options available. Vim has includedTypescript syntax for some years,which receives more frequent updates at its ownrepository.Neovim can also use atreesitter grammar for highlighting.


Syntax file and other settings forTypeScript. Thesyntax file was originally from this 2012blogpost.

CheckoutTsuquyomi for omni-completionand other features for TypeScript editing.

Install

From Vim 8 onward, the plugin can be installed as simply as (Unix/Mac):

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

On Windows/Powershell, use the following:

git clone https://github.com/leafgarland/typescript-vim.git $home/vimfiles/pack/typescript/start/typescript-vim

For older versions of Vim, the simplest way to install is via a Vim add-in manager such asPlug,Vundle orPathogen.

See theInstallation Wiki

Pathogen

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

If you want to install manually then you need to copy the files from thisrepository into your vim path, see the vim docs for:helpruntimepathfor more information. This might be as simple as copying the files anddirectories to~/.vim/ but it depends on your Vim install and operatingsystem.

Usage

Once the files are installed the syntax highlighting and other settings will beautomatically enabled anytime you edit a.ts file.

Indenting

This plugin includes a custom indenter (based onpangloss/vim-javascript'sindenter),it works pretty well but there are cases where it fails. If these bother you orwant to use other indent settings you can disable it by setting a flag in your.vimrc:

letg:typescript_indent_disable=1

If you want the indenter to automatically indent chained method calls as you type.

something.foo().bar();

Then add something likesetlocal indentkeys+=0. to your.vimrc, see:help 'indentkeys' in vim for more information.

If you use the= operator to re-indent code it will always indentchained method calls - this can be disabled by changing the regex theindent script uses to identify indented lines. In this case removing '.'from the regex means that it wont indent lines starting with '.'. Note,this is not ideal as the regex may change making your setting out of date.

letg:typescript_opfirst='\%([<>=,?^%|*/&]\|\([-:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)'

Compiler settings

This plugin contains compiler settings to setmakeprg anderrorformat.The compiler settings enable you to call thetsc compiler directly from Vimand display any errors or warnings in Vim's QuickFix window.

To run the compiler, enter:make, this will runtsc against the last savedversion of your currently edited file.

The default formakeprg istsc $* %. You can enter other compiler options into your:makecommand line and they will be inserted in place of$*.

There are options to change the compiler name and to insert default options.

letg:typescript_compiler_binary='tsc'letg:typescript_compiler_options=''

These options will be passed to the binary as command arguments. For example,ifg:typescript_compiler_binary = 'tsc' andg:typescript_compiler_options = '--lib es6',l:makeprg will be:tsc --lib es6 $* %.

You can completely override this plugin's compiler settings with something likethis in your.vimrc, where you can set makeprg to whatever you want.

autocmdFileTypetypescript :setmakeprg=tsc

Note, this plugin's compiler settings are not used by Syntastic which has its ownway of changing the options. Seehttps://github.com/scrooloose/syntastic#faqargs.

You can use something like this in your.vimrc to make the QuickFixwindow automatically appear if:make has any errors.

autocmdQuickFixCmdPost[^l]* nestedcwindowautocmdQuickFixCmdPostl* nestedlwindow

Syntax highlighting

Syntax highlighting for TypeScript can be customized by following variables.

  • g:typescript_ignore_typescriptdoc: When this variable is defined, doccomments will not behighlighted.
  • g:typescript_ignore_browserwords: When this variable is set to1, browser API names such aswindow ordocument will not be highlighted. (default to0)

Obligatory screenshot

About

Typescript syntax files for Vim

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp