I am currently setting up my Vim to work with matlab. In matlab, sections are separated by
%%, and I am looking for a command to select my current section.
I currently use
nnoremap <Leader>f mf:?%%<CR><Down>v/%%<CR><Up>$:SlimuxREPLSendSelection<CR>`f
to mark the current position as f, search upwards for %%, and select to the next occurrence of %%. The selection is then send to the matlab terminal via Slimux and then I go back to mark f.
However, I would like to extend this to the case when there is no %% before the cursor (then vim should go to the beginning of the file) or when there is no %% after the cursor (then vim should go to the end of the file).
The solution by Tumbler41 almost worked for me, I had to change it a tiny bit because the Slimux function call wouldn't work and to make it able to cope when the cursor is on
nnoremap <Leader>f :call SendSection()<CR>:SlimuxREPLSendSelection<CR>`f function! SendSection() normal! mf if (search('%%', 'b') <= line("'f")) normal! jV else normal! ggV endif if (search('%%') > line("'f")) normal! k else normal! G endif endfunction