rkitover / vimpager

Use Vim as PAGER
http://www.vim.org/scripts/script.php?script_id=1723
Other
774 stars 72 forks source link

vimpager's cursor stuck in 6th to last line #212

Open 1-61803 opened 7 years ago

1-61803 commented 7 years ago

I tested this with v2.06 in Apple's provided vim 7.3 with no plugins in vanilla OS X and also in my main system with vim 8 from MacPorts. I can scroll and search the text, but the cursor remains stuck in the 6th to last line — I also can exceptionally jump to the last line — and in both lines I can move left and right, but neither upwards nor downwards. Only when I leave Less Mode I can freely move the cursor again.

lucc commented 7 years ago

That is intended, as vimpager tries to be a pager. That means text is displayed in pages. There is also no cursor in other pagers like less or more.

1-61803 commented 7 years ago

Since paging makes the cursor flicker, which I think is most noticeable depending on the contrast of the colors selected for cursor and background — can I disable the cursor or change its color (to be the same as the background)?

lucc commented 7 years ago

In vim you can use set t_ve=. (Doesn't work in neovim for me.)

1-61803 commented 7 years ago

How can I disable the cursor only in Less Mode?

rkitover commented 7 years ago

Please install master, it's light years ahead of 2.06. It's my fault we haven't done any releases since then but that will be fixed soon.

If you want to move the cursor freely, you can toggle less mode with ,v.

If you want to run code when vimpager is active, you can do something like this in your .vimrc :

if exists(`g:vimpager.enabled`)
    set t_ve=
endif

as for having a hook when less mode is active, I have not implemented that yet but I will try to soon.

1-61803 commented 7 years ago

I cloned the repo and I am on master already, sorry for the confusion.

I thought something like this to toggle the cursor visibility would work, but it doesn't.

if exists('g:vimpager.enabled')
    set t_ve=
elseif exists('g:vimpager.disabled')
    set t_vi=
endif
rkitover commented 7 years ago

@1-61803 Put this in your ~/.vimrc :

let g:less = { 'scrolloff': 0 }

function s:HideCursorInLessMode()
    if exists('g:less.buffers.'.bufnr('%').'.enabled') && g:less.buffers[bufnr('%')].enabled ==# 1
        if &l:t_ve !=# ''
            let s:current_t_ve = &l:t_ve
            setlocal t_ve=
        endif
    else
        if exists('s:current_t_ve') && &l:t_ve ==# ''
            let &l:t_ve = s:current_t_ve
            normal! M
        endif
    endif
endfunction

function s:RestoreCursor()
    if exists('s:current_t_ve') && s:current_t_ve !=# ''
        let &t_ve = s:current_t_ve
    endif
endfunction

augroup hide_cursor_for_less
    autocmd!
    autocmd BufWinEnter,CursorHold,CursorHoldI,CursorMoved,CursorMovedI * call s:HideCursorInLessMode()
    autocmd VimLeave * call s:RestoreCursor()
augroup END

This will work more or less until I add something to support this.

1-61803 commented 7 years ago

Ok, that works, except for the position of the cursor — depending on whether you change between modes with/without moving/scrolling, it's not always consistent, showing sometimes between 5th-8th line from top/bottom. Could you make it always restore to the center of the screen as a trade-off?

rkitover commented 7 years ago

@1-61803

Try adjusting your scrolloff setting, e.g. to disable scrolloff:

let g:vimpager = { 'scrolloff': 0 }

that will make the cursor move like it does in vim normally, or you could try setting it to e.g. 15 or whatever.

1-61803 commented 7 years ago

scrolloff doesn't work as expected, it hasn't changed the behaviour above.

Furthermore, I now noticed, although I haven't made any other changes to my ~/.vimrc, that, when saving it, the functions output these errors

Error detected while processing function <SNR>1_RestoreCursor:
line    1:
E121: Undefined variable: s:current_t_ve
E15: Invalid expression: s:current_t_ve !=# ''
rkitover commented 7 years ago

@1-61803 does setting g:vimpager.scrolloff do anything at all? If not, you are not setting it correctly.

I updated the code above to fix that problem.

1-61803 commented 7 years ago

:set so=999 centers the cursor :set so=0 resets scrolloff :set g:vimpager.scrolloff=999 gives E518: Unknown option: g:vimpager.scrolloff=999

I thought something like execute "normal! M" at the end of RestoreCursor would work, but it doesn't, in the function at least.

rkitover commented 7 years ago

@1-61803 that is a variable and not a vim option, somewhere at the top of your ~/.vimrc you have to do something like this:

let g:vimpager = {} " initialize the dict
let g:vimpager.scrolloff = 999 " set the option

or in one line:

let g:vimpager = { 'scrolloff': 999 }
1-61803 commented 7 years ago

I tried the one-liner but it didn't change the position. Anyway, I don't want the cursor to remain in the middle of the screen when Less Mode is disabled, I only want to go there, that's why I tried execute "normal! M" at the end of RestoreCursor, but that didn't work either. The joy of vimscript I guess.

rkitover commented 7 years ago

@1-61803 it's actually g:less.scrolloff and NOT g:vimpager.scrolloff, I should read my own docs. Sorry I haven't worked on this stuff in a while.

Anyway, I modified the code above to disable scrolloff and do a normal! M when less mode is disabled.

1-61803 commented 7 years ago

That works fine, thanks. If you implement it in the plugin and need someone to test it, just post in this issue and I'll give it a shot.

1-61803 commented 7 years ago

I've been using it a bit and found out that from Less Mode I can disable it with just v (,v works also) and that I can change to Insert Mode with i and a or to Visual Mode if I select text (I have mouse enabled), where I don't have a cursor anymore. How can you make it only change to full vim mode with ,v?

1-61803 commented 7 years ago

I tried remapping Insert to no avail. In HideCursorInLessMode() I use map i <Nop> and it works, but getting i back in RestoreCursor() doesn't. I tried unmap i, map clear and map <Insert> i. Any ideas?