From c8e39c01278b4ce3395e4131274a73ab7cd69e64 Mon Sep 17 00:00:00 2001 From: Rob B Date: Tue, 1 Jul 2025 21:43:42 +1000 Subject: [PATCH] runtime(go): add section movement Signed-off-by: Rob B --- runtime/ftplugin/go.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/runtime/ftplugin/go.vim b/runtime/ftplugin/go.vim index f3cae02065..7823fb3e77 100644 --- a/runtime/ftplugin/go.vim +++ b/runtime/ftplugin/go.vim @@ -49,6 +49,28 @@ if !exists('*' .. expand('') .. 'GoKeywordPrg') endfunc endif +noremap ]] call GoFindSection('next_start', v:count1) +noremap ][ call GoFindSection('next_end', v:count1) +noremap [[ call GoFindSection('prev_start', v:count1) +noremap [] call GoFindSection('prev_end', v:count1) + +function! GoFindSection(dir, count) + mark ' + let c = a:count + while c > 0 + if a:dir == 'next_start' + keepjumps call search('^\(type\|func\)\>', 'W') + elseif a:dir == 'next_end' + keepjumps call search('^}', 'W') + elseif a:dir == 'prev_start' + keepjumps call search('^\(type\|func\)\>', 'bW') + elseif a:dir == 'prev_end' + keepjumps call search('^}', 'bW') + endif + let c -= 1 + endwhile +endfunction + let &cpo = s:cpo_save unlet s:cpo_save