Emacs like Ctrl-l - Function to jump among Top, Middle and Bottom of window

2 Points

On vim we have a normal mode keybinding "H" to jump to the top, "M" to jump to the middle and "L" to jump to the bottom of window, but in Emacs we have Ctrl-l that "Toggles" among these three states. This is my function and mapping to solve this issue.

" Emacs like Ctrl-l - jumpt to Middle, Bottom and Top of the window
function! ToggleHML()
    set scrolloff=0
    let l:last_win_line = ( line('$') <= winheight('%') ? line('$')  : winheight('%')  )
    if winline() < l:last_win_line / 2
      normal M
    elseif winline() < l:last_win_line
      normal L
    else
      normal H
    endif
endfunction
nnoremap <C-l> :call ToggleHML()<CR>

Martínez Ortiz Saúl Axel

Martínez Ortiz Saúl Axel 5 years ago

I think it should do z., zb and zt instead of M, L and H.