如何让我的vim缩进Java注释是否正确? [英] How do I make vim indent java annotations correctly?

查看:323
本文介绍了如何让我的vim缩进Java注释是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当缩进的java code。与注释,VIM坚持缩进是这样的:

When indenting java code with annotations, vim insists on indenting like this:

@Test
    public void ...

我要的注释是在同一列的方法定义,但我似乎无法找到一种方法来告诉Vim这样做,也许除了使用缩进前pression,但我不知道如果我可以一起使用与常规cindent。

I want the annotation to be in the same column as the method definition but I can't seem to find a way to tell vim to do that, except maybe using an indent expression but I'm not sure if I can use that together with regular cindent.

编辑:文件类型插件已经开启我刚有点困惑缩进插件。该接受的答案可能是一个有点hackish,但对我的作品也是如此。

edit: The filetype plugin was already turned on I just got a bit confused about indenting plugins. The accepted answer may be a bit hackish but works for me as well.

推荐答案

编辑:我不能删除我自己的答案,因为它已经被接受,但是的 @ pydave的回答的似乎是更好(更健壮的)解决方案。



你可能要通过设置 类型插件缩进使用了Java的文件类型(而不是使用cindent)缩进文件。

I cannot delete my own answer because it has already been accepted, but @pydave's answer seems to be the better (more robust) solution.


You should probably be using the indentation file for the java FileType (instead of using cindent) by setting filetype plugin indent on.

这是说,从我的Linux发行版Vim的7.1未来的缩进文件(在当前的vim的svn看这仍然是7.2真)不占批注呢。因此,我复制 /usr/share/vim/vim71/indent/java.vim (见的https://vim.svn.sourceforge.net/svnroot/vim/branches/vim7.1/runtime/indent/java.vim)到〜/的.vim /缩进/ java.vim里,并添加以下行权结束前:

That said, the indentation file coming with the Vim 7.1 from my linux distribution (looking at the current vim svn this is still true for 7.2) doesn't account for annotations yet. I therefore copied /usr/share/vim/vim71/indent/java.vim (see https://vim.svn.sourceforge.net/svnroot/vim/branches/vim7.1/runtime/indent/java.vim) to ~/.vim/indent/java.vim and added the following lines right before the end:

let lnum = prevnonblank(v:lnum - 1)
let line = getline(lnum)
if line =~ '^\s*@.*$'
    let theIndent = indent(lnum)
endif

我不知道,如果这打破了其他任何压痕,但它为我工作。

I'm not sure if this breaks any of the other indentations, but it works for me.

这篇关于如何让我的vim缩进Java注释是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆