Tip 1380 Printable Monobook Previous Next
created November 7, 2006 · complexity basic · author pulp · version n/a
Use this code to highlight the cursor line after a jump. This makes it easy to spot the new cursor position. The highlight will be removed automatically.
function s:Cursor_Moved() let cur_pos= winline ('.') if g:last_pos==0 set cul let g:last_pos=cur_pos return endif let diff= g:last_pos - cur_pos if diff > 1 || diff < -1 set cul else set nocul endif let g:last_pos=cur_pos endfunction autocmd CursorMoved,CursorMovedI * call s:Cursor_Moved() let g:last_pos=0
Comments
I think it should be better this way:
if diff >= 1 || diff <= -1
instead of
if diff > 1 || diff < -1
If you still want to be able to manually set the cursor line: In your autocmd section: let g:manual_cursor=0 Create a mapping to manually toggle the cursorline and set a global var for the function to check: nnoremap <silent> <LocalLeader>tc :set invcul cul?<CR>:let g:manual_cursor=&cul In the function definition: if g:cursor_manual return endif Then, '\tc' in normal mode allows you to toggle a persistent or transient cursorline ( where 'tc' is a mnemonic for "toggle cursor").