Live data from Hacker News

Better line numbers for Vim

myusuf3.github.io

31–40 of 46 posts

Re: Better line numbers for Vim

#31
post #24

I'm living happily with this: "relative number switches - show numbers in insert mode, relative in normal autocmd InsertEnter * :set number autocmd InsertLeave * :set relativenumber

I have two more events since I don't need relative numbers in a buffer that I'm not currently working in:

  set relativenumber
  autocmd InsertEnter,WinLeave * :set norelativenumber
  autocmd InsertLeave,WinEnter * :set relativenumber
(Also, :set number does not reset to non-relative numbers anymore for me)

Re: Better line numbers for Vim

#32
post #12

My problem with relative numbering is that it doesn't seem to work correctly when a line is wrapped. Say I want to move 6 lines down. I use 6j, but one of the lines I want to jump over is wrapped and occupies 2 lines in my editor. That will mean my cursor will end up at the line that was previous numbered 5. This behavior drives me nuts.

If you?ve remapped `j` and `k` to move visually, you can still move linewise using `` (Enter) and `-`. They are equivalent to `j^` and `k^`.

Re: Better line numbers for Vim

#33
post #30
post #28

Earlier quoted context omitted.

Debian does move slowly (that's why it is good for servers; you don't have to update often) but you probably need to update your server. On Debian Wheezy, I have got Vim 7.3.547.

>Debian Wheezy I believe due to a mistake it ended up on Debian 6 (Squeeze). Still, shouldn't 7.3 be available via apt-get?

Nope, this is what Packages.bz2 shows for Debian 6:

  Package: vim
  ...
  Version: 2:7.2.445+hg~cb94c42c0e1a-1
  ...
  Filename: pool/main/v/vim/vim_7.2.445+hg~cb94c42c0e1a-1_i386.deb
And the file is still available here: http://debian.ipacct.com/debian/pool/main/v/vim/vim_7.2.445+...

Edit: and no, it wouldn't be available to Debian Squeeze users, since it is served as an update to Wheezy users and not as a separate package (even if it was, it would have been made available only to Wheezy).

Re: Better line numbers for Vim

#34
I got to know the numbers plugin from http://vim.spf13.com/ This distribution gets you a really good head start on vim and lets you install additional plugins easily with its VBundle Integration and its customization options.

And in case if you ever wondered, why the ESC key is used to change to normal mode, you should read up on the history of the escape key. Therefore I use CTRL-

to switch to normal mode, so my hands can stay on the keyboard.

Re: Better line numbers for Vim

#36
post #12

My problem with relative numbering is that it doesn't seem to work correctly when a line is wrapped. Say I want to move 6 lines down. I use 6j, but one of the lines I want to jump over is wrapped and occupies 2 lines in my editor. That will mean my cursor will end up at the line that was previous numbered 5. This behavior drives me nuts.

If you?ve remapped `j` and `k` to move visually, you can still move linewise using ` ` (Enter) and `-`. They are equivalent to `j^` and `k^`.

That's right, I have remapped j and k. I had it for so long that I forgot it is not the default behavior.

Re: Better line numbers for Vim

#37
Honestly, if you already use powerline or familiar extension, you can look at the status bar for the absolute line. I find it's no need for changing between modes.

And if you use Mac OSX and latest vim version installed by homebrew, in relative line number mode of vim, instead of 0 it is the row line number.

Re: Better line numbers for Vim

#38
In the video, the author moves a block of code by: 1. going to the start of the code block 2. changing mode to visual 3. moving to the end of the block 4. deleting the block 5. moving to the insertion point 6. inserting the delete buffer

I'd like to suggest that using absolute line numbers shortens this considerably. For example

:43,48m63

removes lines 43 to 48 and inserts them after line 63 regardless of the current cursor position (no need to move cursor).

Not saying relative line numbers are bad, just, there's a quicker way, at least for the demo use case.

Re: Better line numbers for Vim

#39
I used to use Relative Line Numbers, until I switched over to EasyMotion. (Original fork: https://github.com/Lokaltog/vim-easymotion. I use a different fork, but don't have the URL for it ATM).

If you haven't tried it, EasyMotion is far, far better and contains much more functionality (covers far more use cases).

Re: Better line numbers for Vim

#40
Plugin functionality aside, the use case in the video demo is IMO better addressed by not worrying about line numbers at all.

Position the cursor at the start of the function, then d} (delete 1 paragraph forward). Alternatively if you don't have a clean paragraph boundary, use V to start a visual highlight, then move the cursor (up,down,},10down,whatever) to the end, then d to delete.

Then } (move 1 paragraph forward)

Then p to paste

Post reply on HN