0

When I scroll down a page the relative numbering is no longer based upon the cursor position.

Instead the line position relative to the top of the screen is displayed.

Sometimes I would like to delete or yank 200 lines and I dont want to have to do the subtraction and addition to figure out how many lines down my text is.

How can I show relative line numbers to the cursor even when scrolling?

Charles
  • 48,924
  • 13
  • 96
  • 136
Bryan
  • 15,409
  • 22
  • 92
  • 119
  • http://stackoverflow.com/questions/6037544/how-to-use-relative-line-numbering-universally-in-vim – Andy897 Oct 10 '13 at 22:11
  • http://jeffkreeftmeijer.com/2012/relative-line-numbers-in-vim-for-super-fast-movement/ – Andy897 Oct 10 '13 at 22:11
  • Sorry, but neither comment helps. I have relative numbering setup just fine. SCROLLING is the problem. – Bryan Oct 10 '13 at 22:29
  • It's impossible to do this because scrolling moves the cursor. Vim has a lot of poor design "features" like this. You have to find a different way to accomplish your task – Andy Ray Oct 10 '13 at 22:39
  • Alternative: use markers to bookmark your position before scrolling. I do that often. Perhaps it's even possible to setup Vim to auto-mark before any scroll. Check these questions http://stackoverflow.com/questions/680456/vim-keep-cursor-location-while-scrolling and http://stackoverflow.com/questions/4195795/vim-macvim-when-i-scroll-with-mouse-the-text-cursor-moves-too – Max Oct 11 '13 at 02:41
  • A workaround to the deletion issue would be to do something like '165,198d', where you want to delete everything between lines 165 and 198 (inclusive). – Cody Poll Oct 11 '13 at 13:12

2 Answers2

2

I think what you want is, you scroll with mouse, and expect that vim keeps the cursor in original place. E.g. your cursor is at line 5, and you scroll down 5000 lines, you expect your cursor is still at line 5. That is, the cursor is out of the window.

AFAIK, the cursor won't go out of the window. That means, if you keep scrolling down, and the cursor line will be the top line of your current window. and the rnu are gonna re-calculated by the cursor line.

May be you could just explain what do you want to do. the cases in your question could be done by 200dd or 200Y but I guess it is not as simple as that.

  • You may want to find out the ending line by reading/scanning your text lines, and pick the line number (rnu), and do a xxxdd if this was the case. Here you should use normal line number. e.g. your cursor was at line 5, and you scroll down a lot, find the line you want to delete till from line 5. you could do :5,.d vim will delete from line 5 to your current line.

  • Or you can do 5, 23452d if you find out the lines between 5 and 23452 need to be removed.

  • If you can search your ending line by /pattern search, vim can do :.,/foo/d this will delete from current line till the next line, which matches foo.

  • You can still press V enter line-wise visual mode, and moving down by vim-motions. when it reaches the point you want to remove/yand press Y or d

You can take a look this Question/answer: VIM to delete a range of lines into a register

At the end, I suggest you not using mouse in vim.

Community
  • 1
  • 1
Kent
  • 173,042
  • 30
  • 210
  • 270
  • Cursor will not go out of window never, also when coding in vim script. But when coding in VimL with `lazyredraw` set redraw is deferred until script ends or `:redraw` is called, thus “not going out of window” only limits possible states of underlying C structures. – ZyX Oct 11 '13 at 04:12
  • thank you @ZyX for the comment. the answer was edited accordingly. – Kent Oct 12 '13 at 10:51
1

This is probably because the cursor moves down a page when you scroll down a page. In vim, the cursor is always on the screen. If you're scrolling down with, say, the mouse wheel, the cursor will just get "stuck" on the top line (modulo scrolloff) and stay there as you continue to scroll down.

Perhaps use ShiftV to start a line-based visual selection before scrolling, then use d or y on the selection?

Eevee
  • 43,129
  • 10
  • 82
  • 119