17

I am using IntelliJ IDE for my projects and just installed ideamvim plugin. In the .ideavimrc I added this property

set rnu

with this property I get relative line numbers in my files in intellij which is amazing. But can I ALSO get absolute line numbers? In my vscode, I have both absolute line numbers and relative line numbers, so I was wondering if it was possible to get the same behavior in intellij?

I am fine even if I have to install a new plugin in Intellij for this feature to work.

Thanks

theprogrammer
  • 1,698
  • 7
  • 28
  • 48

6 Answers6

20

You can do both set relativenumber and set number. This will give you absolute line number for the current line, but relative line numbers for everything else. You can't have two sets of numbers side by side.

citizenmatt
  • 18,085
  • 5
  • 55
  • 60
  • I have it setup in vscode. Check this image. https://i.stack.imgur.com/LM70W.png . I am new to vim, so I am not sure if its because of vscode's implementation. – theprogrammer May 08 '20 at 15:18
  • Yeah, this is a VSCode peculiarity. Standard Vim doesn't support this (maybe through a plugin?) and IdeaVim doesn't support it, either. – citizenmatt May 11 '20 at 08:59
12

You can download and install manual this plugin: https://plugins.jetbrains.com/plugin/7414-relative-line-numbers/versions

And:

  1. Download the latest jar from here
  2. Open Application folder, find the IntelliJ or Android Studio (or other JetBrains IDEs)
  3. Put the relative-line-numbers.jar file into plugins folder
  4. Restart your IntelliJ or Android Studio (or other JetBrains IDEs)

It worked at IntelliJ IDEA 2021.2.2 and windows 11 https://i.stack.imgur.com/Z4mBp.png

9

You can have "hybrid" numbering

Add this line to your ~/.ideavimrc file as per the documentation.

set number relativenumber

You can't have context-sensitive numbering

Automatic toggling between relative / absolute numbering as you can in Vim with

autocmd InsertEnter * : set norelativenumber
autocmd InsertLeave * : set relativenumber

... this doesn't work because IdeaVIM doesn't support autocmd.

Adrian
  • 2,244
  • 18
  • 20
  • I guess that's the limitation of vim and intellij. Check the vscode image I posted in the above comment. In vscode I am able to get both. – theprogrammer Aug 25 '20 at 00:07
4

I was able to get this to work in Intellij 2019 version. As of today this method doesn't work in latest Intellij version.

  1. Install Relative Line Numbers plugin in intellij, we will use this plugin to simulate relative line numbers.
  2. On the other hand, we will let ideavim simulate absolute line numbers. This can be done by adding set nu to your .ideavimrc file. You can directly open this file by clicking IdeaVim icon in bottom right of intellij. If not just search for this file. For me its in C:\Users\{userName}\.ideavimrc

After doing the above, you should have something that looks like this:

enter image description here

Note: The comments on the plugin website mention that it doesn't work for latest(2020 version) IntelliJ. I am using 2019 version and it works fine so far. The only problem I have noticed so far on my end is that when you open VCS window, you only get relative line numbers(for some reason ideavim buffer doesn't kick in). I will update this answer if I find any other issues. Until then I will keep this question open in case someone else has a working solution for latest intellij version.

theprogrammer
  • 1,698
  • 7
  • 28
  • 48
1

https://plugins.jetbrains.com/plugin/7414-relative-line-numbers

For anyone who wants to use this plugins in new version of intelliJ or AndroidStudio (or other JetBrains IDEs): [on macOS] Download the latest jar from here Open Application folder, find the IntelliJ or Android Studio (or other JetBrains IDEs) Right click -> Show Package Contents Put the relative-line-numbers.jar file into Contents/plugins folder Restart your IntelliJ or Android Studio (or other JetBrains IDEs) Find the Relative Line Numbers plugins in the bundled plugin area Just enable it! Tested by myself, it WORKS on Android Studio 4.2 Beta

Sam Yu
  • 11
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 25 '22 at 21:24
-1

The latest version (0.64) ideavim works. Set number and set relative number.

enter image description here.

HJW
  • 441
  • 4
  • 9
  • 2
    Actually this is not what the question that I asked. This was possible even before the latest ideavim version. What I want is to have both absolute and relative numbers on "ALL LINES", not just the line my cursor is on. Check this link: https://i.stack.imgur.com/LM70W.png. I have set it up on my vscode but only in intellij I am not able to replicate this feature. – theprogrammer Jan 20 '21 at 16:49