Skip to content

Commit

Permalink
merge: add <plug>(vimtex-cmd-toggle-break) with default map
Browse files Browse the repository at this point in the history
refer: #2948
  • Loading branch information
lervag committed May 13, 2024
2 parents 8ca7438 + 23ee3ae commit 9665df7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ by default and must be manually enabled.
- Toggle inline and displaymath with `ts$`
- Toggle between e.g. `()` and `\left(\right)` with `tsd`
- Toggle (inline) fractions with `tsf`
- Toggle line-break macro `\\` with `tsb`
- Close the current environment/delimiter in insert mode with `]]`
- Add `\left ... \right)` modifiers to surrounding delimiters with `<F8>`
- Insert new command with `<F7>`
Expand Down
1 change: 1 addition & 0 deletions autoload/vimtex.vim
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function! s:init_default_mappings() abort " {{{1
call s:map(0, 'n', 'tsc', '<plug>(vimtex-cmd-toggle-star)')
call s:map(0, 'n', 'tsf', '<plug>(vimtex-cmd-toggle-frac)')
call s:map(0, 'x', 'tsf', '<plug>(vimtex-cmd-toggle-frac)')
call s:map(0, 'n', 'tsb', '<plug>(vimtex-cmd-toggle-break)')
call s:map(0, 'i', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'n', '<F7>', '<plug>(vimtex-cmd-create)')
call s:map(0, 'x', '<F7>', '<plug>(vimtex-cmd-create)')
Expand Down
16 changes: 16 additions & 0 deletions autoload/vimtex/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function! vimtex#cmd#init_buffer() abort " {{{1
xnoremap <silent><buffer> <plug>(vimtex-cmd-toggle-frac)
\ :<c-u>call vimtex#cmd#toggle_frac_visual()<cr>
nnoremap <silent><buffer> <plug>(vimtex-cmd-toggle-break)
\ :<c-u>call <sid>operator_setup('toggle_break')<bar>normal! g@l<cr>
endfunction

" }}}1
Expand Down Expand Up @@ -267,6 +270,18 @@ function! vimtex#cmd#toggle_frac_visual() abort " {{{1
call setreg('a', l:save_reg)
endfunction

" }}}1
function! vimtex#cmd#toggle_break() abort " {{{1
let l:lnum = line('.')
let l:line = getline(l:lnum)

let l:replace = l:line =~# '\s*\\\\\s*$'
\ ? substitute(l:line, '\s*\\\\\s*$', '', '')
\ : substitute(l:line, '\s*$', ' \\\\', '')

call setline(l:lnum, l:replace)
endfunction

" }}}1

function! vimtex#cmd#parser_separator_check(separator_string) abort " {{{1
Expand Down Expand Up @@ -609,6 +624,7 @@ function! s:operator_function(_) abort " {{{1
\ 'delete': 'delete()',
\ 'toggle_star': 'toggle_star()',
\ 'toggle_frac': 'toggle_frac()',
\ 'toggle_break': 'toggle_break()',
\ }[s:operator]
endfunction

Expand Down
6 changes: 6 additions & 0 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ FEATURE OVERVIEW *vimtex-features*
- Toggle inline and displaymath with `ts$`
- Toggle between e.g. `()` and `\left(\right)` with `tsd`/`tsD`
- Toggle (inline) fractions with `tsf`
- Toggle line-break macro `\\` with `tsb`
- Close the current environment/delimiter in insert mode with `]]`
- Add `\left ... \right)` modifiers to surrounding delimiters with `<F8>`
- Insert new command with `<F7>`
Expand Down Expand Up @@ -870,6 +871,7 @@ This feature is explained in more detail later, see |vimtex-imaps|.
tsc |<plug>(vimtex-cmd-toggle-star)| `n`
tse |<plug>(vimtex-env-toggle-star)| `n`
ts$ |<plug>(vimtex-env-toggle-math)| `n`
tsb |<plug>(vimtex-env-toggle-break)| `n`
<F6> |<plug>(vimtex-env-surround-line)| `n`
|<plug>(vimtex-env-surround-operator)| `n`
<F6> |<plug>(vimtex-env-surround-visual)| `x`
Expand Down Expand Up @@ -3740,6 +3742,10 @@ MAP DEFINITIONS *vimtex-mappings*
<
One may change the toggle sequence with |g:vimtex_env_toggle_math_map|.

*<plug>(vimtex-cmd-toggle-break)*
Toggle the line-break macro `\\` at the end of current line. This may
be convenient when working with array and math environments.

*<plug>(vimtex-env-surround-line)*
*<plug>(vimtex-env-surround-operator)*
*<plug>(vimtex-env-surround-visual)*
Expand Down
16 changes: 16 additions & 0 deletions test/test-commands/test-toggle-break.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set nocompatible
set runtimepath^=../..
filetype plugin on


" tsb / Toggle line break
for [s:in, s:out] in [
\ ['abc', 'abc \\'],
\ [' a + b = c', ' a + b = c \\'],
\ ['abc \\', 'abc'],
\ ['abc\\', 'abc'],
\]
call vimtex#test#keys('tsb', s:in, s:out)
endfor

call vimtex#test#finished()

0 comments on commit 9665df7

Please sign in to comment.