How to get both absolute and relative line numbers in ideavim for IntelliJ?
Asked Answered
L

7

21

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

Lorant answered 8/5, 2020 at 14:37 Comment(0)
G
27

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.

Grimm answered 8/5, 2020 at 14:55 Comment(4)
I have it setup in vscode. Check this image. i.sstatic.net/LM70W.png . I am new to vim, so I am not sure if its because of vscode's implementation.Lorant
Yeah, this is a VSCode peculiarity. Standard Vim doesn't support this (maybe through a plugin?) and IdeaVim doesn't support it, either.Grimm
The respective command is set number relativenumber, so you can copy-paste :)Carnatic
set number relativenumber for some reason, this doesn't work in ideamvim for me.Lorant
S
14

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.

Shaveling answered 24/8, 2020 at 13:39 Comment(1)
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.Lorant
L
13

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://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMxcF_AZVLQamyA/Z4mBp.png

Lowering answered 3/9, 2021 at 6:14 Comment(2)
Works on macOS 11.2.3 using IntelliJ IDEA 2021.2.3Scilicet
It says "Not compatible with the version of your running IDE (CLion 2022.1.3)", but it works well. Maybe we just need to repackage it?Rosauraroscius
L
5

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.

Lorant answered 26/3, 2021 at 1:26 Comment(0)
S
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

Slander answered 23/7, 2022 at 16:24 Comment(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.Wax
A
1

As of 2024, intelliJ no longer supports https://plugins.jetbrains.com/plugin/19193-relative-line-numbers.

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

To enable both relative and absolute line numbers, go to Settings > Editor > Line Numbers and enable both "Relative values and "Absolute values" checkbox

Alimentary answered 23/4 at 20:16 Comment(0)
S
-1

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

enter image description here.

Shopwindow answered 20/1, 2021 at 0:55 Comment(1)
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: i.sstatic.net/LM70W.png. I have set it up on my vscode but only in intellij I am not able to replicate this feature.Lorant

© 2022 - 2024 — McMap. All rights reserved.