Wednesday, January 11, 2023

Re: Highlighting cursor lines

I now have the following Vim script in place; I decided to create a highlight group called CursorLineNC, When you leave a window, it sets a match on the current line. When you enter it again, it removes it. I always have 'cursorline' on, so this works well (the match supersedes the cursorline setting) unless scrollbind or cursorbind are set, where you can see the current cursor line in the other window moving, while the CursorLineNC highlighted line remains where it was. Frankly, I'm not sure I consider that a bug because it's a visual indicator of where I was when I was last in the window, even if that's not where I will be the next time I go in there; otherwise, it could be turned off in an OptionSet autocommand if cursorbind/scrollbind are turned on.

def HighlightCurrentLine(): void
  w:matchLine = matchadd( 'CursorLineNC', '\%' .. line( '.' ) .. 'l' )
enddef

def ClearCurrentLineHighlight(): void
  if ( exists( 'w:matchLine' ) )
    matchdelete( w:matchLine )

    unlet w:matchLine
  endif
enddef

augroup highlightCursorLine
  au!

  au WinLeave          * HighlightCurrentLine()
  au BufEnter,WinEnter * ClearCurrentLineHighlight()
augroup END

All the best,

Salman

On Wed, Jan 11, 2023 at 9:38 AM Salman Halim <salmanhalim@gmail.com> wrote:
On Tue, Jan 10, 2023 at 8:53 PM Owajigbanam Ogbuluijah <xigbanam@gmail.com> wrote:
I had thought Vim dims inactive windows the same way TMux does; but this question made me realize I've been hallucinating that feature all these while.

I was surprised, also; there is a StatusLineNC, but no CursorLineNC or CursorColumnNC.
 

One way is to play with your au! commands as you've done; finding the right visual cue which works for you. I've always worked around this with the iTerm cursor-focus feature — dunno if that's the real name. If you press Command + / in iTerm, there's an obvious highlight which shows you where your cursor is.

I'm on OS X, but I'm sure this would work in iTerm across OSes. There could also be equivalent in other shell apps; but I only use iTerm

I believe such an option can be used in Windows where pressing the Control key highlights the cursor. I'm trying to figure out a way to make the other windows' current lines be highlighted differently just because I want it (and think it's a good idea). Maybe I should add a match that highlights the current line when I leave the window and remove it when I enter the window.

Thanks for confirming that I wasn't just not able to find the feature and that it really doesn't exist.
 


- Igbanam

On Tue, Jan 10, 2023 at 7:14 PM Salman Halim <salmanhalim@gmail.com> wrote:
Hello,

Is there a way to highlight the cursor line in other windows in the current tab differently than the window that has the focus? I like to know which line is selected in each window, but also want to be able to tell at a glance which is the window where my editing and cursor movement will happen.


--
 
Salman

I, too, shall something make and glory in the making.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEe4Ay%3DuoS1g_iWMO1uQsuG231n1CMZf115tym2HTt-iVw%40mail.gmail.com.

No comments: