vim-lineletters (jump to any visible line in the buffer by using letters instead of numbers)

Plugin

I have created a plugin to display letters instead of numbers for the visible lines in the current buffer for easier jumping to line (since letters are easier to touch type than numbers).

Plugin here: https://github.com/skamsie/vim-lineletters/

It is a simpler alternative to the <Plug>(easymotion-bd-jk) action of Easymotion which I normally use but have some pet peeves with:

  • unecessary distraction by changing buffer colors
  • easymotion adds characters in the current buffer which triggers linter errors and the TextChanged event which can be annoying if you have some autocommands for it. 'lineletters' uses the sign column so it does not have this problem
  • the charaters are random each time, which kind of interrupts the flow. With 'lineletters' the characters are always the same and in the same order so with time you build some muscle memory. 'b' is always the second line, 'z' on the 26th line, lines lower in the window need to be prefixed, and so on.

Posted Dec 14, 2020, 9:36 PM UTC

5231
GuybrushThreepwo0d•

Oh snap I need this. Thanks.

2
skamsie_OP•

Great, I am glad you like it.

2
ProgMetalSlug•

Maybe a naive question but why not use /? It's builtin and all you have to do is type the characters you're looking at to jump there. It can't get any easier.

2
skamsie_OP•

Because in most cases the pattern you are looking for is not unique in the buffer so you either have to type a lot or follow-up with n or N or C-g / C-t (or think carefuly in advance before searching). I think plugins like 'easymotion' or 'vim-sneak' are popular just because they remove this need of thinking too much in advance about the line or place you want to jump to.

For example let's say you have these lines in a file and want to jump on line 40 that just has foo. How efficient is to go there with /?

35| def foo
36|   puts :foo
37| end
38|
39| # calling foo
40| foo
41|
42| def foobar
43|   puts :foobar
44| end
1
thebaazigarTM•

Another beginner question, I’m new to vim but have been using relative numbers with j/k for navigation like this. Are there any downsides to that?

1
skamsie_OP•

No, why would there be? I think it's what most people use, but me personally am not very good at touch typing numbers, especially in the 4-8 area. Also I don't like having the linenumbers column displayed all the time (mostly because of aesthetic reasons), unless I am pair programming.

1
sd5seandewar•

Using j and k aren't jump motions (:help jump-motions), and will not update the jumplist, which is very useful for returning back to where you were, even after numerous jumps (:help jumplist). This is why I prefer using / and ?, which also has no need for the line numbers column to be enabled. It is possible to extend the behaviour of j and k to update the jumplist (preferably only when using a count) using Vim script, though.

I can't check this right now, but if this plugin internally uses gg or G to implement its jumping (without :keepjumps), then it will also update the jumplist.

1
ProgMetalSlug•

I would do /foo<CR> and press n a few times. If I realized before hand that there's a lot of "foo" in there, I would do /^foo<CR>.

I think it's fine to do a little more typing or press the same key several times (n in this case) if it requires less mental overhead. Less typing is not always more efficient.

If I understand correctly, this plugin will only bring you to the right line but then you still have to move the cursor within that line with some other method. With /, it does both in just one motion.

1
skamsie_OP•

This plugin only solves the 'problem' of jumping to line which you would normally do using line numbers relative or not.

1
abraxasknister•

/^f<cr>

But I get it, it's not always that simple. On the other hand sneak has the exact same problem, doesn't it?

I tried easymotion, sneak and quickscope now and I use built-in stuff and kept sneak because it extents f past the line end.

1
abraxasknister•

I think this will be a really good replacement for relative line numbers. Numbers are awkward to type.

Is the line numbering absolute, ie the first line of the buffer is a, ect, or is it relative to the screen?

I'd also have kind of feature request: since it's sort of inevitable that there will be lines with two letters to jump to: why not always make it 2 and use home row keys (for the dvorak etc people you'd use a user defined alphabet) to make the pairs?

sf | def fac(n):
sj |     if n:
ad |         return fac(n-1)*n
a; |     return 1
lj |
lf | print(
;k |   [
;d |     for a in range(10)
fj |     fac(a)
dk |   ]
sl | )
2
skamsie_OP•

Is the line numbering absolute, ie the first line of the buffer is a, ect, or is it relative to the screen?

a will always be the top visible line in the current window, no matter if it's buffer line 1 or 1000.

I'd also have kind of feature request: since it's sort of inevitable that there will be lines with two letters to jump to: why not always make it 2 and use home row keys (for the dvorak etc people you'd use a user defined alphabet) to make the pairs?

I would not make it the default to always make it 2 chars, but additional options. One to configure your characters, and another one to enforce 2 chars always if you want.

Thank you for the idea and if you are interested to actually use it, you can ‘star’ or ‘watch’ the repo on github to see when I implement this change. Cheers!

1
abraxasknister•

I'd probably not make it a "enforce 2" but rather a "makes it 2 if screen height is longer than alphabet, else make it 1 or make it shortest possible" toggle

The idea goes a bit against the goal of having a simple mnemonic for "first line", "second line", etc

1
skamsie_OP•

I'd probably not make it a "enforce 2" but rather a "makes it 2 if screen height is longer than alphabet else make it 1

This is what currently happens, with the mention that it's about 'window' height and not screen height.

1
abraxasknister•

I thought the current behavior is "make it shortest possible"?

1
terminalcoder•

Fantastic plugin, thanks!!

1
skamsie_OP•

🙇

1
veydar_•

How does this compare to https://github.com/justinmk/vim-sneak? Seems like sneak gets me even closer to the target but doesn't require more keys

1
skamsie_OP•

it does not compare... vim-sneak is of course more powerful. This one is only for jumping to specific line.

1
veydar_•

Let me preface this by saying that I like a healthy plugin ecosystem so the more the merrier :)

What I meant by my question is why would I choose this plugin when there's already vim-sneak since I now have the option of:

  • Jumping to a line with just :50
  • Jumping to the target on that line with Sneak
  • Jumping to the line, but not the target, with this plugin

I don't mean this to be snarky. Maybe there's some cool use case I don't know so just out of curiosity what was the motivation to write this?

1
skamsie_OP•

I don't mean this to be snarky. Maybe there's some cool use case I don't know so just out of curiosity what was the motivation to write this?

The reason why I wrote the plugin is written in the post, mainly this:

It is a simpler alternative to the <Plug>(easymotion-bd-jk) action of Easymotion which I normally use but have some pet peeves with

If you are not familiar with vim-easymotion, is a plugin that overlays characters or combinations of characters in the current buffer that can be easily typed so you can jump directly on a specific place in the buffer. It has a lot of features, but the one I was using most <Plug>(easymotion-bd-jk) adds these characters on the first column of each line in the visible buffer. Why I don't entirely embrace this plugin is also stated in the main post:

unecessary distraction by changing buffer colors

easymotion adds characters in the current buffer which triggers linter errors and the TextChanged
event which can be annoying if you have some autocommands for it. 'lineletters' uses the sign column so it does not have this problem

the charaters are random each time, which kind of interrupts the flow. With 'lineletters' the characters are always the same and in the same order so with time you build some muscle memory. 'b' is always the second line, 'z' on the 26th line, lines lower in the window need to be prefixed, and so on.

Regarding jumping to line using numbers :50 I think that touch typing letters, or characters like , , ; ' is much easier than touch typing numbers. It's not always about the number of key presses, but also how conventient or fast is to type them. Also by using a plugin like 'lineletters' you can disable the linenumbers column altogether and win some screen estate, or for aesthetics reasons)

I hope this answers your question, even though everything was already written in the post...

1
veydar_•

Well I know vim-easymotion but there already exists a simpler alternative which is vim-sneak, hence my question.

Still cool idea!

1
i8Nails4Breakfast•

Whoah I literally had this idea yesterday and youve already made it! I agree typing numbers for k and j felt slow and unnatural

1
skamsie_OP•

Great to hear. Since this post, I have also made it work in visual mode as well!

1