Loading ...
Sorry, an error occurred while loading the content.

Re: Highlight cursor line

Expand Messages
  • Dan Sharp
    ... A recent thread on this topic generated two different methods. Each has advantages and disadvantages. Try them and see which you like best. Notes: 1) To
    Message 1 of 2 , Feb 1, 2002
    • 0 Attachment
      >From: Vim User <vim_power@...>
      >
      >How do i highlight the current cursor line ?
      >thanks

      A recent thread on this topic generated two different methods. Each has
      advantages and disadvantages. Try them and see which you like best.

      Notes:
      1) To use version 1, you need to have +signs in your :version output. This
      appears to be the default on most non-unix systems. For unix, you need to
      compile vim with the --enable-featues=big or --enable-features=huge
      configure argument (the default compile uses --enable-features=normal, which
      does not include sign support).

      2) In version 1, the HiCur() function should only contain two "execute"
      lines. I believe the second line has been unintentionally wrapped in this
      email.

      Dan Sharp

      ------- Version 1 -------
      " Modified from a proposal by Benoit Cerrina
      "
      hi default curLine guibg=yellow ctermbg=yellow ctermfg=black
      au! CursorHold * call s:HiCur()
      sign define curline linehl=curLine
      nmap <silent> j j:call <SID>HiCur()<cr>
      nmap <silent> <Down> <Down>:call <SID>HiCur()<cr>
      nmap <silent> k k:call <SID>HiCur()<cr>
      nmap <silent> <Up> <Up>:call <SID>HiCur()<cr>
      function! s:HiCur()
      execute 'sign unplace 2121'
      execute 'sign place 2121 line='.line('.').' name=curline
      buffer='.bufnr("%")
      endfunction

      ------- Version 2 -------
      " Modified from a proposal by Thomas Urban
      "
      au! CursorHold * call s:HiCur()
      nmap <silent> j j:call <SID>HiCur("")<cr>
      nmap <silent> k k:call <SID>HiCur("")<cr>
      nmap <silent> <Up> <Up>:call <SID>HiCur("")<cr>
      nmap <silent> <Down> <Down>:call <SID>HiCur("")<cr>

      hi def link CurLine Todo

      function! s:HiCur(pattern)
      if a:pattern != ""
      exec "match CurLine '" . a:pattern . "'"
      endif
      let l = escape (getline("."), '/[]*.^$')
      if l == ''
      match none
      else
      exec ("match CurLine /^" . l . "$/")
      endif
      endfunction



      _________________________________________________________________
      MSN Photos is the easiest way to share and print your photos:
      http://photos.msn.com/support/worldwide.aspx
    Your message has been successfully submitted and would be delivered to recipients shortly.