Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:37:15+00:00 2026-05-24T05:37:15+00:00

In general I prefer to have annotation tags for methods, including @Test ones, on

  • 0

In general I prefer to have annotation tags for methods, including @Test ones, on the line before the method declaration like this

@Test
public void testMyMethod() {
// Code
}

rather than

@Test public void testMyMethod() {
// Code
}

I have java specific settings in ~/.vim/ftplugins/java.vim. What can I add to java.vim such that indentation is skipped at the first line after the @Test tag? At the moment vim will, as it is supposed to according to java.vim, indent 4 characters giving

@Test
____* <-- cursor placed here

while I would prefer

@Test
* <-- Cursor placed here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:37:16+00:00Added an answer on May 24, 2026 at 5:37 am

    I do something similar in C++, where my company’s coding style doesn’t want indents in namespace blocks. There’s an answer for that at this post, adapting it to your question would just swap the '^\s*namespace.*' bit to your desired pattern. If it’s for all annotations, perhaps simply…

    function! IndentAnnotation()
      let l:cline_num = line('.')
      let l:pline_num = prevnonblank(l:cline_num - 1)
      let l:pline = getline(l:pline_num)
      let l:retv = cindent('.')
      while l:pline =~# '\(^\s*{\s*\|^\s*//\|^\s*/\*\|\*/\s*$\)'
        let l:pline_num = prevnonblank(l:pline_num - 1)
        let l:pline = getline(l:pline_num)
      endwhile
      if l:pline =~# '^\s*@.*'
        let l:retv = 0
      endif
      return l:retv
    endfunction
    
    setlocal indentexpr=IndentAnnotation()
    

    Save this in your vimfiles (inside ~/vimfiles or on windows in your homedir or inside ProgramFiles\vim\vimfiles) as indent/java.vim. You may be able to simplify by removing the while/endwhile hunt for a non-blank line if you require an annotation to occur on a line exactly above the line you’re indenting (with no intervening blank lines).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have general question regarding the use of pointers vs. references in this particular
This is a general question on programming style. Let's say I have an object
This question is specific to Erlang, but may have general implications to other IO
I have some general purpose classes in one project that I would like to
As a general rule, I prefer using value rather than pointer semantics in C++
General Follow the same standards for all tests. Be clear about what each test
General context : MVVM application. I have a View called JobView. Its DataContext is
general question is i like to build logger class that writes to single log
In general, I occasionally have a chain of nested macros with a few preprocessor
I have posted this to ServerFault, but the Node.js community seems tiny there, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.