Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions autoload/vimtex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ function! s:init_default_mappings() abort " {{{1
call s:map(1, 'o', '[N', '<plug>(vimtex-[N)')
call s:map(1, 'o', '[n', '<plug>(vimtex-[n)')

call s:map(1, 'n', ']R', '<plug>(vimtex-]R)')
call s:map(1, 'n', ']r', '<plug>(vimtex-]r)')
call s:map(1, 'n', '[R', '<plug>(vimtex-[R)')
call s:map(1, 'n', '[r', '<plug>(vimtex-[r)')
call s:map(1, 'x', ']R', '<plug>(vimtex-]R)')
call s:map(1, 'x', ']r', '<plug>(vimtex-]r)')
call s:map(1, 'x', '[R', '<plug>(vimtex-[R)')
call s:map(1, 'x', '[r', '<plug>(vimtex-[r)')
call s:map(1, 'o', ']R', '<plug>(vimtex-]R)')
call s:map(1, 'o', ']r', '<plug>(vimtex-]r)')
call s:map(1, 'o', '[R', '<plug>(vimtex-[R)')
call s:map(1, 'o', '[r', '<plug>(vimtex-[r)')

call s:map(1, 'n', ']/', '<plug>(vimtex-]/)')
call s:map(1, 'n', ']*', '<plug>(vimtex-]*)')
call s:map(1, 'n', '[/', '<plug>(vimtex-[/)')
Expand Down
33 changes: 33 additions & 0 deletions autoload/vimtex/motion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ function! vimtex#motion#init_buffer() abort " {{{1
onoremap <silent><buffer> <plug>(vimtex-[m) :execute "normal \<sid>(V)" . v:count1 . "\<sid>(vimtex-[m)"<cr>
onoremap <silent><buffer> <plug>(vimtex-[M) :execute "normal \<sid>(V)" . v:count1 . "\<sid>(vimtex-[M)"<cr>

" Frames
nnoremap <silent><buffer> <plug>(vimtex-]r) :<c-u>call vimtex#motion#frame(1,0,0)<cr>
nnoremap <silent><buffer> <plug>(vimtex-]R) :<c-u>call vimtex#motion#frame(0,0,0)<cr>
nnoremap <silent><buffer> <plug>(vimtex-[r) :<c-u>call vimtex#motion#frame(1,1,0)<cr>
nnoremap <silent><buffer> <plug>(vimtex-[R) :<c-u>call vimtex#motion#frame(0,1,0)<cr>
xnoremap <silent><buffer> <sid>(vimtex-]r) :<c-u>call vimtex#motion#frame(1,0,1)<cr>
xnoremap <silent><buffer> <sid>(vimtex-]R) :<c-u>call vimtex#motion#frame(0,0,1)<cr>
xnoremap <silent><buffer> <sid>(vimtex-[r) :<c-u>call vimtex#motion#frame(1,1,1)<cr>
xnoremap <silent><buffer> <sid>(vimtex-[R) :<c-u>call vimtex#motion#frame(0,1,1)<cr>
xmap <silent><buffer> <plug>(vimtex-]r) <sid>(vimtex-]r)
xmap <silent><buffer> <plug>(vimtex-]R) <sid>(vimtex-]R)
xmap <silent><buffer> <plug>(vimtex-[r) <sid>(vimtex-[r)
xmap <silent><buffer> <plug>(vimtex-[R) <sid>(vimtex-[R)
onoremap <silent><buffer> <plug>(vimtex-]r) :execute "normal \<sid>(V)" . v:count1 . "\<sid>(vimtex-]r)"<cr>
onoremap <silent><buffer> <plug>(vimtex-]R) :execute "normal \<sid>(V)" . v:count1 . "\<sid>(vimtex-]R)"<cr>
onoremap <silent><buffer> <plug>(vimtex-[r) :execute "normal \<sid>(V)" . v:count1 . "\<sid>(vimtex-[r)"<cr>
onoremap <silent><buffer> <plug>(vimtex-[R) :execute "normal \<sid>(V)" . v:count1 . "\<sid>(vimtex-[R)"<cr>

" Comments
nnoremap <silent><buffer> <plug>(vimtex-]/) :<c-u>call vimtex#motion#comment(1,0,0)<cr>
nnoremap <silent><buffer> <plug>(vimtex-]*) :<c-u>call vimtex#motion#comment(0,0,0)<cr>
Expand Down Expand Up @@ -189,6 +207,21 @@ function! vimtex#motion#environment(begin, backwards, visual) abort " {{{1
endfor
endfunction

" }}}1
function! vimtex#motion#frame(begin, backwards, visual) abort " {{{1
let l:count = v:count1
if a:visual
normal! gv
endif

let l:re = g:vimtex#re#not_comment . (a:begin ? '\\begin\s*\{frame\}' : '\\end\s*\{frame\}')
let l:flags = 'W' . (a:backwards ? 'b' : '')

for l:_ in range(l:count)
call search(l:re, l:flags)
endfor
endfunction

" }}}1
function! vimtex#motion#comment(begin, backwards, visual) abort " {{{1
let l:count = v:count1
Expand Down
21 changes: 21 additions & 0 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ FEATURE OVERVIEW *vimtex-features*
- Move between section boundaries with `[[`, `[]`, `][`, and `]]`
- Move between environment boundaries with `[m`, `[M`, `]m`, and `]M`
- Move between math environment boundaries with `[n`, `[N`, `]n`, and `]N`
- Move between frame environment boundaries with `[r`, `[R`, `]r`, and `]R`
- Move between comment boundaries with `[*` and `]*`
- Move between matching delimiters with `%`
- Text objects
Expand Down Expand Up @@ -787,6 +788,10 @@ This feature is explained in more detail later, see |vimtex-imaps|.
]N |<plug>(vimtex-]N)| `nxo`
[n |<plug>(vimtex-[n)| `nxo`
[N |<plug>(vimtex-[N)| `nxo`
]r |<plug>(vimtex-]r)| `nxo`
]R |<plug>(vimtex-]R)| `nxo`
[r |<plug>(vimtex-[r)| `nxo`
[R |<plug>(vimtex-[R)| `nxo`
]/ |<plug>(vimtex-]/| `nxo`
]* |<plug>(vimtex-]star| `nxo`
[/ |<plug>(vimtex-[/| `nxo`
Expand Down Expand Up @@ -2965,6 +2970,22 @@ object, see |text-objects|.
go to [count] previous end of a math zone.
|exlusive| motion.

*<plug>(vimtex-]r)*
go to [count] next start of a frame environment.
|exlusive| motion.

*<plug>(vimtex-]R)*
go to [count] next end of a frame environment.
|exlusive| motion.

*<plug>(vimtex-[r)*
go to [count] previous start of a frame environment.
|exlusive| motion.

*<plug>(vimtex-[R)*
go to [count] previous end of a frame environment.
|exlusive| motion.

*<plug>(vimtex-]/)*
go to [count] next start of a LaTeX comment "%".
|exlusive| motion.
Expand Down
45 changes: 45 additions & 0 deletions test/tests/test-motions/test-beamer-motions.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
\documentclass[]{beamer}

\begin{document}

Test file for frame/beamer motion.

\begin{frame} % [r[r or 2[r
\frametitle{Test I}
Simple frame % [R[R or 2[R
\end{frame}

\begin{frame} % [r
\frametitle{Test II}
Frame with nested environments.
\begin{equation}
\begin{aligned}
1 + 1 = & 2
\end{aligned}
\end{equation}
\end{frame} % [R

\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\end{enumerate}
% CURSOR
\begin{frame} % ]r
\frametitle{Test III}
Frame with nested environments.
\begin{block}{A block}
Block body
\end{block}
\end{frame} % ]R

\begin{frame} % ]r]r or 2]r
\frametitle{Test IV}
Frame with nested environments.
\begin{exampleblock}{A block}
Block body
\end{exampleblock}
\end{frame} % ]R]R or 2]R

\end{document}
26 changes: 26 additions & 0 deletions test/tests/test-motions/test-beamer-motions.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set nocompatible
let &rtp = '../../..,' . &rtp
filetype plugin on
syntax on

nnoremap q :qall!<cr>

silent edit test-beamer-motions.tex

if empty($INMAKE) | finish | endif

" vint: -ProhibitCommandRelyOnUser

normal 28G2]r
call vimtex#test#assert_equal(line('.'), 37)

normal 28G]R
call vimtex#test#assert_equal(line('.'), 35)

normal 28G2[r
call vimtex#test#assert_equal(line('.'), 7)

normal 28G[R
call vimtex#test#assert_equal(line('.'), 20)

quit!