Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Added smoothie version of the gg motion
Browse files Browse the repository at this point in the history
Closes psliwka#1
  • Loading branch information
subnut committed Nov 16, 2020
1 parent fa61acd commit c230928
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions autoload/smoothie.vim
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,24 @@ function smoothie#backwards()
call s:update_target(-winheight(0) * v:count1)
endfunction

" Smooth equivalent to gg.
function smoothie#gg()
if g:smoothie_disabled
exe 'normal! gg'
return
endif
" gg behaves like a jump-command
" so, append current position to the jumplist
" but before that, save v:count into a variable
let l:count = v:count
execute "normal! m'"
let s:ctrl_f_invoked = v:false
call s:update_target(l:count - line('.'))
" suspend further commands till the destination is reached
" see point (3) of https://github.com/psliwka/vim-smoothie/issues/1#issuecomment-560158642
while line('.') > (l:count ? l:count : 1)
sleep 1 m
endwhile
endfunction

" vim: et ts=2
6 changes: 6 additions & 0 deletions plugin/smoothie.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if has('nvim') || has('patch-8.2.1280')
noremap <silent> <Plug>(SmoothieUpwards) <cmd>call smoothie#upwards() <CR>
noremap <silent> <Plug>(SmoothieForwards) <cmd>call smoothie#forwards() <CR>
noremap <silent> <Plug>(SmoothieBackwards) <cmd>call smoothie#backwards() <CR>
noremap <silent> <Plug>(Smoothie_gg) <cmd>call smoothie#gg() <CR>
if !get(g:, 'smoothie_no_default_mappings', v:false)
silent! map <unique> <C-D> <Plug>(SmoothieDownwards)
Expand All @@ -13,12 +14,14 @@ if has('nvim') || has('patch-8.2.1280')
silent! map <unique> <C-B> <Plug>(SmoothieBackwards)
silent! map <unique> <S-Up> <Plug>(SmoothieBackwards)
silent! map <unique> <PageUp> <Plug>(SmoothieBackwards)
silent! map <unique> gg <Plug>(Smoothie_gg)
endif
else
nnoremap <silent> <Plug>(SmoothieDownwards) :<C-U>call smoothie#downwards() <CR>
nnoremap <silent> <Plug>(SmoothieUpwards) :<C-U>call smoothie#upwards() <CR>
nnoremap <silent> <Plug>(SmoothieForwards) :<C-U>call smoothie#forwards() <CR>
nnoremap <silent> <Plug>(SmoothieBackwards) :<C-U>call smoothie#backwards() <CR>
nnoremap <silent> <Plug>(Smoothie_gg) :<C-U>call smoothie#gg() <CR>
if !get(g:, 'smoothie_no_default_mappings', v:false)
silent! nmap <unique> <C-D> <Plug>(SmoothieDownwards)
Expand All @@ -29,5 +32,8 @@ else
silent! nmap <unique> <C-B> <Plug>(SmoothieBackwards)
silent! nmap <unique> <S-Up> <Plug>(SmoothieBackwards)
silent! nmap <unique> <PageUp> <Plug>(SmoothieBackwards)
silent! nmap <unique> gg <Plug>(Smoothie_gg)
endif
endif

" vim: et ts=2

0 comments on commit c230928

Please sign in to comment.