How to embed typescript files in VIM

I am new to VIM and am working on using a package to format / colorize / indent my files. Currently, I have downloaded the syntax typescript vim syntax: https://github.com/leafgarland/typescript-vim.git , the problem is that the indentation seems to be broken for me, consider in the following example after auto-detection (gg = G) the file:

module Module { class Foo { // some string here bar: string; // bar is incorrectly indented } } 

When in fact I expect the following:

 module Module { class Foo { // some string here bar: string; // bar is correctly indented } } 

This is the typescript.vim ftplugin file:

 compiler typescript setlocal autoindent setlocal cindent setlocal smartindent setlocal indentexpr& setlocal commentstring=//\ %s 

I tried to mess around with different indent settings to no avail. I use the VIM settings and the package from here: https://github.com/gisenberg/.vim , I synchronize these files on my local computer using git.

TIA!

+4
source share
2 answers

According to the Vim fingerprint documentation , you can try the following to find out if it suits you.

Hand driving

If you change the current indentation of a line manually, Vim ignores the cindent for that line.

This can be annoying due to the frequency of this pattern in TypeScript.

Angle brackets

If you really want to backtrack as you type : use <:> .

This will give you padding without losing any of the cindent parts that you find useful.

Change cinkeys

It contains settings that affect the cindent parameter, by default it is:

 "0{,0},0),:,0#,!^F,o,O,e" 

But you might be lucky to change it to:

 "0{,0},0),0#,!^F,o,O,e" 

Ditch cindent

You can completely remove the c-style padding, but by removing this line:

 setlocal cindent 

I looked at several options, because the nature of Vim and the nature of code editing - you need to try the options to find out what suits you best.

+2
source

Try this plugin - https://github.com/jason0x43/vim-js-indent . It supports TypeScript and fixed all my indentation issues.

+1
source

Source: https://habr.com/ru/post/1469359/


All Articles