Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more

Questions tagged [line-numbers]

Vim can output the number of each line on the left side of the screen. Questions about customizing this behavior.

Filter by
Sorted by
Tagged with
0 votes
2 answers
30 views

Visual Mode increasing numbers by 1

I have many rows with numbers, some rows are blank though: 1 some text 2 some text 7 some text some text 9 some text 11 some text some text 17 ...
athos's user avatar
  • 195
0 votes
1 answer
40 views

Gap between number line and text buffer

Is there a way to specify the gap between the number line column and the text buffer. The defaults are too close to my liking.
Modem Mibm's user avatar
1 vote
2 answers
94 views

Yank current line range

I would like to yank the current selected line range (not the line range content). For example, if my selection goes from line 51 to 67, I looking for a way to yank 51,67 to my default register.
Martin Delille's user avatar
1 vote
0 answers
21 views

How can I create a popup at a given buffer line and column when the wrap option is set?

When you do popup_create({whatever}, #{ line: m, col: n}), m and n are meant to be screen column numbers, as per :help popup_create-arguments. But what if I want to position the popup at a specific ...
Enlico's user avatar
  • 2,214
0 votes
2 answers
41 views

Misunderstanding of interaction between local options, moving between windows, and WinLeave, WinEnter, BufLeave, BufEnter events

This what is logged in :messages when I'm printing the value of nu and rnu upon the 4 events WinLeave, WinEnter, BufLeave, BufEnter during the action, done twice, of opening :help and closing it. The ...
Enlico's user avatar
  • 2,214
1 vote
1 answer
1k views

`E492: Not an editor command` error only when opening file, but not when using :so %

I have the following in my vimrc: call plug#begin() Plug 'https://github.com/vim-scripts/RltvNmbr.vim' call plug#end() set number RltvNmbr When I type :so % while in my vimrc, it will turn on the ...
brianxk's user avatar
  • 21
0 votes
0 answers
41 views

Windows: "syntax incorrect" -- can I ask Vim for the line number?

I use vim on Windows, using a "_vimrc" configuration file. When running the vim command in the prompt, I get the following error message before Vim starts every single time: The syntax of ...
gustafbstrom's user avatar
4 votes
1 answer
2k views

Why are relative line numbers useful in Vim?

I have been used to absolute line numbers (:set number norelativenumber). I'm unable to find a good reason and utility value for relative line numbers (:set nonumber relativenumber) line or hybrid ...
Senthil Kumaran's user avatar
2 votes
2 answers
404 views

Replace characters in relative linespan

I know that I can replace characters in a linespan via something to the effect of :300,305s/foo/bar/g But when I'm deep in the code, and I know that I just want to replace in the next five lines, I'm ...
Yehuda's user avatar
  • 275
2 votes
1 answer
290 views

vim line number does weird things on lines starting with an 8

I have some commands set up that run the test under my current cursor position. using the command rails test <filename>:<linenumber>. I execute this command through exec '!rails test %:'....
Enermis's user avatar
  • 161
0 votes
1 answer
219 views

How to restore cursor position after the document is reformatted?

I'm reformatting an XML document with an external command from a vimscript function which accepts a range, and I need the cursor to stay at the same line it was before the reformatting. When trying ...
Tomáš Bažant's user avatar
3 votes
2 answers
888 views

How can I add a specific range of numbers into to each line at a particular location?

For example, we have: 1 this is line. please go to file example.txt for more information. 2 this is line. please go to file demo.txt for more information. 3 this is line. please go to file ...
data 's user avatar
  • 33
0 votes
1 answer
301 views

keyboard shortcut to insert text at the end of several lines of same length instead of 10,12s/$/pattern_to_be_inserted/gc

to insert the same text inside several lines in one particular line <ctrl> + <v> to select the line and then <shift> + <i> to insert a texte BEFORE the particular column. Is ...
ecjb's user avatar
  • 149
1 vote
1 answer
400 views

How can I use a variable line number with a command?

I want to move a line to another specified in a variable. So where I might do this to move the current line up seven lines: :m-7 I want to do it with a variable line destination. Something like this: ...
markling's user avatar
  • 389
1 vote
3 answers
884 views

How supply range to normal mode key-binding?

I've created a mapping to a function that accepts a range. Like this: command! -range Test call TestFunc(<range>,<line1>,<line2>) nnoremap <leader>t :Test<CR> How do I ...
markling's user avatar
  • 389
3 votes
1 answer
116 views

How to show line numbers only at fixed intervals?

I know how to show absolute as well as cursor-relative line numbers but I do not need to see each line number and they look too crowded. I would like to just see line numbers at an interval, say every ...
Ketan's user avatar
  • 265
3 votes
1 answer
23 views

What are the propagation rules for local window settings defined in .vimrc?

In my .vimrc I have :set number. This window-local setting is applied for new windows (e.g., when running :split some_new_file). However, when I open a help window with :help, there are no line ...
dannyadam's user avatar
  • 482
1 vote
1 answer
391 views

Make Line Numbers Appear in Documentation

I have set number in my init.vim (I am using neovim) and it works fine for any buffers I'm editing. However, I have to enter :set number into the command line to make line numbers appear in the ...
Jordan Mandel's user avatar
-1 votes
1 answer
209 views

How to check if total number of lines are bigger than 10 in Vim? [closed]

I want to check if number of lines are bigger than 10 in Vim. I tried to use this code in vimrc file: if line("$") > 10 colorscheme currentline endif Edit: I made a colorscheme with ...
sbh's user avatar
  • 63
2 votes
2 answers
591 views

Set line numbers based on line count

If a file has a large number of lines, I'd like to enable line numbers, otherwise leave them off by default. If I run the command: if line('$') > 150 | :set number | endif while vim is open, file ...
user avatar
3 votes
1 answer
214 views

line numbers in vim -H reversed

Recently I installed vim 8.2 on Windows 10 and vim 8.1.2269 on Linux Ubuntu. Both are compiled with +rightleft option. When I use gvim -H or vim -H (without vimrc file) and run :set number, I get line ...
Dan Haran's user avatar
1 vote
0 answers
379 views

jump to line via letters instead of relative numbers

I currently use relative numbers to jump from my current line to another one. But since typing letters is easier then numbers, i wanted to know if there is a way to replace the line numbers with ...
Mars Rover's user avatar
0 votes
1 answer
221 views

How to track down the code during debugging?

The problem I'm trying to troubleshoot now is specific to recent neovim 0.5.0 (exact version I'm using is NVIM v0.5.0-ef3230f35 but this issue reproduces in the same way on all my machines each ...
Steven Lu's user avatar
  • 2,271
2 votes
0 answers
136 views

Truncate line numbers when they are too large

So I'm using Vim's line numbering with set number set numberwidth=4 But I find that if line numbers exceed 999, then the gutter is automatically expanded to accommodate them. I actually don't want ...
Matt Phillips's user avatar
0 votes
1 answer
40 views

Line numbers relative to the screen

Is it possible to make Vim show line numbers relative to the screen? Not to the beginning of the file, and not to the current position of the cursor, but relative to the first line that is currently ...
Kamil S.'s user avatar
  • 111
3 votes
1 answer
3k views

What are the benefits and use cases of relativenumber?

I have tried the relativenumber option several times, and I really don't get the point. People say that it's easier because they don't have to do the mental math of how many lines to go up or down ...
Thaddaeus Markle's user avatar
1 vote
1 answer
261 views

How to toggle relative number for all opened windows?

I have this in my .vimrc: nnoremap <C-a> :set relativenumber!<cr> This toggles the relative number feature only in the current window. Is it possible to toggle it in all opened windows ...
Salahuddin Ahmed's user avatar
2 votes
2 answers
130 views

Set line number on chunks of file

Following an example such as: ##1## many text and lines ##z## ##2## more text ##z## ...etc How could i make the line number display only on chunks of text, inside of the ##digit## and the ##z## ...
Nordine Lotfi's user avatar
1 vote
0 answers
59 views

How to make Vim not be a line editor

Vim is famously (or infamously) a child of line-based editing. For many cases this is acceptable. But I wish to use it primarily as an academic tool with large amounts of text. I want the experience ...
Shadow43375's user avatar
1 vote
1 answer
110 views

navigate lines with alphabets

I am using Programmer Dvorak layout. So typing numbers for navigation is not easy. Can I instead navigate with alphabetical characters showing up in place of relative numbers? Any other ideas?
Rounak Jain's user avatar
1 vote
1 answer
440 views

inserting a line number into substitution text

I have a long script file that I need to run in an application. I generally create these by running a query against the application and then creating the script I need using VIM. Sometimes these can ...
klamerus's user avatar
4 votes
0 answers
334 views

Add vertical line between line numbers and file contents

I have set number in my ~/.vimrc, which enables line numbers. Generally they are quite useful, but it can be a bit tricky to discern the actual contents of a numerical data file from the line numbers, ...
Quasímodo's user avatar
  • 2,466
2 votes
0 answers
852 views

Vimdiff : highlight line numbers differently

I use relative line numbers thanx to the following settings in my vimrc: set number set relativenumber Since I don't want to wrap lines in diff mode, it's sometimes hard to tell which line include a ...
Dupond's user avatar
  • 45
1 vote
0 answers
412 views

Why is Neovim highlighting the cursor line numbers after the cursor has moved off?

I have turned on CursorLineNr highlighting as shown in this init.vim file. When I have my cursor on a line that wraps, it highlights all the individual "lines" on that line, as usual. However once my ...
Michael Lan's user avatar
2 votes
1 answer
241 views

Visual/Operator-pending autocommand?

Last week, I turned off 'number' and have been using only 'relativenumber', plus a line/column count in my status line. I don't really look at line numbers that much. But now I've had a radical idea. ...
D. Ben Knoble's user avatar
  • 26.4k
0 votes
1 answer
315 views

How can I keep the cursor position when piping the buffer through an external command?

I sometimes make shortcuts for myself, which run some external command on the current buffer, such as nnoremap <C-f> :%!clang-format -style=file<C-m> which formats the buffer with clang'...
oarfish's user avatar
  • 1,277
3 votes
1 answer
175 views

How to open multiple files with cursor for all files being at the last line?

My experiments generate several log files, which I sometimes monitor manually. Some of the log files have an error message in the last line. I want to open all log files with the cursor located at ...
user3342981's user avatar
2 votes
2 answers
530 views

How to get line numbers of a different window

I would like to get these line numbers of a different window without moving to that window. line('w0') line('w$') line('.') line('$') As for the first two, we can use getwininfo([{winid}]) which ...
Rick Howe's user avatar
  • 353
3 votes
2 answers
1k views

Add line numbers and remove line numbers to selected lines

Based on the accepted answer of the following post How to add permanent line numbers to a file? I would like to have the capacity to select a certain number of lines and add numbers to those ...
cosmicraga's user avatar
0 votes
1 answer
315 views

lines numbering and formatting

For practicing in vim I made: $ man bash > PracticeFile but upon setting up line numbers, using: :set nu the formatting got messed up, so that letters at the end of line are closer to number ...
pigeon's user avatar
  • 25
12 votes
3 answers
2k views

Visual Block Mode edit with sequential number [duplicate]

Suppose I'd like to create a list - "1" - "2" - "3" what Is the smartest way to create such? My attempt would be to i- "1"ESCyypp to get - "1" - "1" - "1" and then jump to the second line's 1 ...
Joel's user avatar
  • 223
0 votes
1 answer
58 views

Why doesn't this `:execute` command work?

I was looking at this question on Unix & Linux Stack Exchange, and I thought I could write an answer for it using Vim. I ran the following for a quick test, and was surprised to find it didn't ...
Wildcard's user avatar
  • 4,429
5 votes
3 answers
5k views

How to copy lines with line numbers?

I would like to copy several lines with line numbers; the text from set number isn't copied. Is there any way to do this?
toraritte's user avatar
  • 400
0 votes
1 answer
561 views

Enable line numbering for directories

When viewing a directory (using :Explore, for example), I would like to see line numbers. I can run :set number after opening the directory, and that works, but I can't get numbering to turn on by ...
Jasha's user avatar
  • 503
10 votes
3 answers
4k views

Show absolute and relative line numbers (not hybrid)

I'm trying to find a way to show relative line numbers as well as absolute line numbers, but not the way hybrid line numbers does it. I want to see both at all times, probably each displayed on a ...
sleighty's user avatar
  • 209
0 votes
1 answer
887 views

Highlight specific line numbers in the gutter

Can you target a spesific line number in the gutter? Let's say I want line 20 in the gutter te be red for some reason. Possible? Like CursorLineNr, but defining the line number yourself. In short I'm ...
Audun Olsen's user avatar
4 votes
4 answers
3k views

Nvim can not detect focus change inside tmux sessions

I use the following setting for automatic line number toggle. augroup numbertoggle autocmd! autocmd BufEnter,FocusGained,InsertLeave * set relativenumber autocmd BufLeave,FocusLost,InsertEnter ...
jdhao's user avatar
  • 1,143
1 vote
1 answer
135 views

excluding line numbering from mkview/loadview

I include set number in my .vimrc file to have line numbers automatically displayed upon opening a file. I also use the following code block to automatically save and load the view when closing and ...
user001's user avatar
  • 153
0 votes
1 answer
373 views

How to display a sign before the line number gutter?

I'd like to display some characters in left side of the line number gutter just like the vim-syntastic plugin does to show the errors. back when I was starting to learn vim I saw a plugin doing just ...
John Fred Fadrigalan's user avatar
1 vote
1 answer
2k views

How could I turn off the terminal line number while keep the editor line number in vimrc

I want to show line number in the editor, thus I use set nu in my vimrc. But when I open the embedded terminal with :ter, there are also line numbers there which I feel not comfortable. How could I ...
coin cheung's user avatar