ocp ua 源代码_使用ocp-indent在Vim中自动缩进OCaml代码

ocp ua 源代码

The built-in indenting in Vim for OCaml seems not very good. How to set up auto indenting for OCaml code in Vim? ocp-indent works very well for me. This posts introduces how to configure Vim to use ocp-indent to automatically indent/format OCaml code.

Vim中用于OCaml的内置缩进似乎不是很好。 如何在Vim中为OCaml代码设置自动缩进? ocp-indent对我来说效果很好。 这篇文章介绍了如何配置Vim以使用ocp-indent自动缩进/格式化OCaml代码。

First, install ocp-indent after installing opam:

首先,在安装opam之后安装 ocp-indent

$ opam install ocp-indent

Second, configure vim by adding these lines to your ~/.vimrc:

其次,通过~/.vimrc添加到~/.vimrc来配置vim

au BufEnter *.ml setf ocaml
au BufEnter *.mli setf ocaml
au FileType ocaml call FT_ocaml()
function FT_ocaml()
    set textwidth=80
    set colorcolumn=80
    set shiftwidth=2
    set tabstop=2
    " ocp-indent with ocp-indent-vim
    let opamshare=system("opam config var share | tr -d '\n'")
    execute "autocmd FileType ocaml source".opamshare."/vim/syntax/ocp-indent.vim"
    filetype indent on
    filetype plugin indent on
endfunction

You can use == to format the code selected or the current line now.

您现在可以使用==设置所选代码或当前行的格式。

Third, to make ocp-indent be automatically invoked by autoindent, add the ocp-indent-vim script. This ensures that ocp-indent will indent the current line after you input Enter, “if”, “else”, etc. You can use tools like pathogen to manage the installed plugins in Vim.

第三,要使ocp-indentautoindent自动调用,请添加ocp-indent-vim脚本 。 这样可以确保ocp-indent在输入Enter,“ if”,“ else”等之后缩进当前行。您可以使用病原体之类的 工具来管理Vim中已安装的插件。

Last, configuring the ocp-indent by adding these lines to ~/.ocp/ocp-indent.conf":

最后,通过将这些行添加到~/.ocp/ocp-indent.conf"来配置ocp-indent

# These are `normal`, `apprentice` and `JaneStreet` and set different defaults.
JaneStreet

You may choose the other defaults. The JaneStreet mode works great for me.

您可以选择其他默认值。 JaneStreet模式非常适合我。

翻译自: https://www.systutorials.com/auto-indenting-for-ocaml-code-in-vim-with-ocp-indent/

ocp ua 源代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值