Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New function to toggle \\ #2948

Closed
wants to merge 4 commits into from
Closed
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
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 end `\\` 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
5 changes: 5 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 end `\\` 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,9 @@ 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 command `\\` at the end of current line.

*<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()