Any way to add additional space after line number in Vim? - vim

I am looking for a way to move text further from the line number in Vim. Default settings are to add one space after the line number when using set number. I would like to add a bit more. Using set numberwidth=n doesn't help, because additional space goes before the line number, not in between the line number and the text itself.

No native Vim option seems to alter this, but there is an old plugin which could accomplish what you want to achieve called vimroom. It is not actively being maintained and I don't know if it still works with current Vim versions. But this screenshot makes it look like it is possible to have the line numbers way on the left.
Hopefully this pointer helps you out!

Related

Is there a way to have vim start line numbering at 0?

I have added the set nu to my vimrc file, and I like it, but I would like to have vim start with line number 0 (it's to match the samples from a book I am using to learn C++).
I saw a suggestion to change set nu to set rnu, and at first it looked good, until I moved downward, and the 0 moved with my cursor. I understand what's going on here - it's displaying a 0 for my current position, and the lines above and below are renumbered relative to where 0 is. While cool, this is not what I want.
Thanks in advance!
Shane
This is not possible without patching the source.
Note that, in Vim, line numbers can be used in many more ways than in "regular" editors so changing how the line numbers are displayed will have a non-negligible impact in other areas. This doesn't seem like a very good idea.

Using vimscript, how to know if a line's no has changed?

Question
When buffer contents have changed how do I know if a line, having say a line no of 100, has shifted to line no 104?
Note: Content of the line may change so can't track the line using search patterns.
Hacky Solution
I was thinking using the TextChanged* events along with the current cursor position and change in the total number of lines will help. But this seems like it could lead to an incorrect answer.
Context
I'm trying to create a plugin as a wrapper around vim's tags functionality.
The issue is: if a tag was inserted at line 100 and 4 lines were added above it, the tag points to an incorrect location, i.e. line 100, whereas it should be 104.
How do I calculate this difference of 4?
Solutions that apply to both vim and neovim would be appreciated.

alter vim's mode indicator text to just the first letter in airline

I have vim with airline, that tells me which mode I am in. I would like to change it so that rather than the whole word it just displays the first letter. So N, I or V. Although I can find instructions for changing colours of the mode indicator, I can't find the command to add to my .vimrc that will change the text.
What do I add?
I don't use the plugin, but was able to locate the information in its help almost immediately.
You're looking for the g:airline_mode_map configuration; the example even does exactly what you're asking for (single mode letters), so just copy-and-paste the fragment into your ~/.vimrc!
Also, I would recommend to open an issue / ask the plugin author next time. It might take a bit longer until you get an answer, but it alerts the author about things that aren't yet documented or are hard to find in the documentation, so he can improve it.

Vim: Hide all code around selected code

I want to be able to hide all code around the specific section of code that I am working with. Now I am wondering if this is possible in Vim somehow. I have experimented with it a bit already and have been successful at hiding lines above and below my selection by using highlight group Igore. This enables me to only see the lines that I want to focus on but the problem is when I begin to edit the code and add or remove lines. When I add a line or remove a line the already set highlight group Ignore is still maintaining the set line numbers so I either get to see some of the hidden code or some of the code that I want to see gets long and extends into the hidden line numbers. So I am wondering if there is some way to fix this or any other way to accomplish what I want in Vim?
Appreciate any suggestions!
Hiding or shading parts of the buffer is not the Vim way. Folding is the built-in feature that comes closest. With :set foldmethod=manual, you can then use zf or :fold to hide the parts above and below.
For a plugin solution, have a look at NrrwRgn - A Narrow Region Plugin. It allows you to edit parts of a buffer in a separate scratch buffer, with automatic syncing back.
To hide a range of lines (let's say from 1 to 10 and 20 to end, you can type :1,10fo|20,$fo
From there, you can create a function based on the current cursor position -10/+10
Note you have first to :set foldmethod=manual to make this works.
EDIT: a simple solution : :1,.-10fo|.+10,$fo

Is there a way to show line numbers at end of the line in Vim

I am using
set relativenumber
set number
which let's me move easily around. However, it is often hard to know the exact the line number of the object where I would like to jump to because I first need to look to the left. I feel it would be easier if I could see the line numbers also on the right hand side right because my eyes have less space to follow (maybe?). I think the ideal setting would be to show the relative/absolute line number where the $ appears when whitespace characters are shown and to the left/right of the buffer. I.e.
1 Random text.$1 1
159 This is the line where the cursor is.$159 159
1 Some random text.$1 1
2 More random text. Another sentence. Maybe a third one? And so on.$2 2
3 Another line which might be quite long and my eyes focus somewhere here.$3 3
4 More random text containing more text and more words and stuff.$4 4
(In this example, I would like to do 3k but I may type 2k or 4k because I did not follow the correct line to the left.)
Is it possible to achieve this somehow?
Any suggestion on how to change my workflow are welcome, too.
Note: Using cursorline does not help as I do not seek the number of the current line.
No, there is no built-in support to your requirement. also I don't think this is easy to be done by plugin.
Maybe you could consider to change your habit/workflow. E.g. enable the cursorline option, to highlight your "current" line, it may let you easier to identify which line are you on right now.
To move cursor, if you don't want to count lines, you may want to try the EasyMotion plugin. It is very handy plugin. However it won't replace the hjkl ... motions.
No, that's not possible, unless you modify Vim's source code in a non-trivial way, or work around with kludges like a vertically split small scratch buffer at the side that is updated via autocmds.
Do you have :set cursorline? That helps (me) a lot to follow the current line, even with large window widths. Reducing those might help, too, though you have to deal with wrapping / scrolling of long lines then.

Resources