加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何正确缩进VIM中的打字稿文件

发布时间:2020-12-15 21:06:23 所属栏目:安全 来源:网络整理
导读:我对VIM很陌生,一直在使用bundle来格式化/着色/缩进我的文件.我目前从这里下载了一个打字稿 vim语法“bundle”: https://github.com/leafgarland/typescript-vim.git,问题是缩进对我来说似乎打破了,考虑下面的例子,在autoindenting(gg = G)之后的文件: mod
我对VIM很陌生,一直在使用bundle来格式化/着色/缩进我的文件.我目前从这里下载了一个打字稿 vim语法“bundle”: https://github.com/leafgarland/typescript-vim.git,问题是缩进对我来说似乎打破了,考虑下面的例子,在autoindenting(gg = G)之后的文件:

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

实际上我希望如下:

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

这是typescript.vim ftplugin文件:

compiler typescript                                                             

setlocal autoindent
setlocal cindent
setlocal smartindent
setlocal indentexpr&

setlocal commentstring=// %s

我尝试摆弄不同的缩进设置无济于事.我正在使用我的VIM设置并从这里捆绑:https://github.com/gisenberg/.vim,我使用git在本地计算机上同步这些文件.

TIA!

解决方法

根据 Vim indentation documentation,您应该能够尝试以下内容,看看是否适合您.

手动摆弄

If you change the current line’s indentation manually,Vim ignores the
cindent settings for that line.

由于TypeScript中此模式的频率,这可能会令人讨厌.

尖括号

If you really want to re-indent when you type : use <:>.

这会让你缩进,而不会丢失任何有用的cindent部分.

改变cinkeys

这包含影响cindent设置的设置,默认情况下为:

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

但是你可能会有一些运气改变它:

"0{,e"

Ditch Cindent

你可以完全删除c风格的缩进,但删除这一行:

setlocal cindent

我已经介绍了很多选项,因为这是Vim的本质,这就是代码编辑的本质 – 您需要尝试选项以找出最适合您的选项.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读