Added text object for commands (#244)
This commit is contained in:
parent
61ec408961
commit
7a7299c2e8
@ -29,9 +29,11 @@ disabled if desired.
|
|||||||
- Move between sections with `[[`, `[]`, `][`, `]]`
|
- Move between sections with `[[`, `[]`, `][`, `]]`
|
||||||
- Move between matching delimiters with `%`
|
- Move between matching delimiters with `%`
|
||||||
- Text objects
|
- Text objects
|
||||||
|
- `ic ac` Commands
|
||||||
|
- `id ad` Delimiters
|
||||||
- `ie ae` LaTeX environments
|
- `ie ae` LaTeX environments
|
||||||
- `i$ a$` Inline math structures
|
- `i$ a$` Inline math structures
|
||||||
- `id ad` Delimiters
|
- `ip ap` Paragraphs
|
||||||
- Other mappings
|
- Other mappings
|
||||||
- Delete the surrounding command or environment with `dsc`/`dse`
|
- Delete the surrounding command or environment with `dsc`/`dse`
|
||||||
- Change the surrounding command or environment with `csc`/`cse`
|
- Change the surrounding command or environment with `csc`/`cse`
|
||||||
|
@ -393,6 +393,14 @@ function! s:init_mappings() " {{{1
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if g:vimtex_text_obj_enabled
|
if g:vimtex_text_obj_enabled
|
||||||
|
call s:map('x', 'ic', '<plug>(vimtex-ic)')
|
||||||
|
call s:map('x', 'ac', '<plug>(vimtex-ac)')
|
||||||
|
call s:map('o', 'ic', '<plug>(vimtex-ic)')
|
||||||
|
call s:map('o', 'ac', '<plug>(vimtex-ac)')
|
||||||
|
call s:map('x', 'id', '<plug>(vimtex-id)')
|
||||||
|
call s:map('x', 'ad', '<plug>(vimtex-ad)')
|
||||||
|
call s:map('o', 'id', '<plug>(vimtex-id)')
|
||||||
|
call s:map('o', 'ad', '<plug>(vimtex-ad)')
|
||||||
call s:map('x', 'ie', '<plug>(vimtex-ie)')
|
call s:map('x', 'ie', '<plug>(vimtex-ie)')
|
||||||
call s:map('x', 'ae', '<plug>(vimtex-ae)')
|
call s:map('x', 'ae', '<plug>(vimtex-ae)')
|
||||||
call s:map('o', 'ie', '<plug>(vimtex-ie)')
|
call s:map('o', 'ie', '<plug>(vimtex-ie)')
|
||||||
@ -401,10 +409,6 @@ function! s:init_mappings() " {{{1
|
|||||||
call s:map('x', 'a$', '<plug>(vimtex-a$)')
|
call s:map('x', 'a$', '<plug>(vimtex-a$)')
|
||||||
call s:map('o', 'i$', '<plug>(vimtex-i$)')
|
call s:map('o', 'i$', '<plug>(vimtex-i$)')
|
||||||
call s:map('o', 'a$', '<plug>(vimtex-a$)')
|
call s:map('o', 'a$', '<plug>(vimtex-a$)')
|
||||||
call s:map('x', 'id', '<plug>(vimtex-id)')
|
|
||||||
call s:map('x', 'ad', '<plug>(vimtex-ad)')
|
|
||||||
call s:map('o', 'id', '<plug>(vimtex-id)')
|
|
||||||
call s:map('o', 'ad', '<plug>(vimtex-ad)')
|
|
||||||
call s:map('x', 'ip', '<plug>(vimtex-ip)')
|
call s:map('x', 'ip', '<plug>(vimtex-ip)')
|
||||||
call s:map('x', 'ap', '<plug>(vimtex-ap)')
|
call s:map('x', 'ap', '<plug>(vimtex-ap)')
|
||||||
call s:map('o', 'ip', '<plug>(vimtex-ip)')
|
call s:map('o', 'ip', '<plug>(vimtex-ip)')
|
||||||
|
@ -20,13 +20,21 @@ function! vimtex#text_obj#init_buffer() " {{{1
|
|||||||
nnoremap <buffer> <sid>(v) v
|
nnoremap <buffer> <sid>(v) v
|
||||||
nnoremap <buffer> <sid>(V) V
|
nnoremap <buffer> <sid>(V) V
|
||||||
|
|
||||||
" Paragraphs
|
" Commands
|
||||||
xnoremap <silent><buffer> <sid>(vimtex-ip) :<c-u>call vimtex#text_obj#paragraphs(1)<cr>
|
xnoremap <silent><buffer> <sid>(vimtex-ic) :<c-u>call vimtex#text_obj#commands(1)<cr>
|
||||||
xnoremap <silent><buffer> <sid>(vimtex-ap) :<c-u>call vimtex#text_obj#paragraphs()<cr>
|
xnoremap <silent><buffer> <sid>(vimtex-ac) :<c-u>call vimtex#text_obj#commands()<cr>
|
||||||
xmap <silent><buffer> <plug>(vimtex-ip) <sid>(vimtex-ip)
|
xmap <silent><buffer> <plug>(vimtex-ic) <sid>(vimtex-ic)
|
||||||
xmap <silent><buffer> <plug>(vimtex-ap) <sid>(vimtex-ap)
|
xmap <silent><buffer> <plug>(vimtex-ac) <sid>(vimtex-ac)
|
||||||
onoremap <silent><buffer> <plug>(vimtex-ip) :execute "normal \<sid>(V)\<sid>(vimtex-ip)"<cr>
|
onoremap <silent><buffer> <plug>(vimtex-ic) :execute "normal \<sid>(v)\<sid>(vimtex-ic)"<cr>
|
||||||
onoremap <silent><buffer> <plug>(vimtex-ap) :execute "normal \<sid>(V)\<sid>(vimtex-ap)"<cr>
|
onoremap <silent><buffer> <plug>(vimtex-ac) :execute "normal \<sid>(v)\<sid>(vimtex-ac)"<cr>
|
||||||
|
|
||||||
|
" Delimiters
|
||||||
|
xnoremap <silent><buffer> <sid>(vimtex-id) :<c-u>call vimtex#text_obj#delimiters(1)<cr>
|
||||||
|
xnoremap <silent><buffer> <sid>(vimtex-ad) :<c-u>call vimtex#text_obj#delimiters()<cr>
|
||||||
|
xmap <silent><buffer> <plug>(vimtex-id) <sid>(vimtex-id)
|
||||||
|
xmap <silent><buffer> <plug>(vimtex-ad) <sid>(vimtex-ad)
|
||||||
|
onoremap <silent><buffer> <plug>(vimtex-id) :execute "normal \<sid>(v)\<sid>(vimtex-id)"<cr>
|
||||||
|
onoremap <silent><buffer> <plug>(vimtex-ad) :execute "normal \<sid>(v)\<sid>(vimtex-ad)"<cr>
|
||||||
|
|
||||||
" Environments
|
" Environments
|
||||||
xnoremap <silent><buffer> <sid>(vimtex-ie) :<c-u>call vimtex#text_obj#environments(1)<cr>
|
xnoremap <silent><buffer> <sid>(vimtex-ie) :<c-u>call vimtex#text_obj#environments(1)<cr>
|
||||||
@ -44,17 +52,36 @@ function! vimtex#text_obj#init_buffer() " {{{1
|
|||||||
onoremap <silent><buffer> <plug>(vimtex-i$) :execute "normal \<sid>(v)\<sid>(vimtex-i$)"<cr>
|
onoremap <silent><buffer> <plug>(vimtex-i$) :execute "normal \<sid>(v)\<sid>(vimtex-i$)"<cr>
|
||||||
onoremap <silent><buffer> <plug>(vimtex-a$) :execute "normal \<sid>(v)\<sid>(vimtex-a$)"<cr>
|
onoremap <silent><buffer> <plug>(vimtex-a$) :execute "normal \<sid>(v)\<sid>(vimtex-a$)"<cr>
|
||||||
|
|
||||||
" Delimiters
|
" Paragraphs
|
||||||
xnoremap <silent><buffer> <sid>(vimtex-id) :<c-u>call vimtex#text_obj#delimiters(1)<cr>
|
xnoremap <silent><buffer> <sid>(vimtex-ip) :<c-u>call vimtex#text_obj#paragraphs(1)<cr>
|
||||||
xnoremap <silent><buffer> <sid>(vimtex-ad) :<c-u>call vimtex#text_obj#delimiters()<cr>
|
xnoremap <silent><buffer> <sid>(vimtex-ap) :<c-u>call vimtex#text_obj#paragraphs()<cr>
|
||||||
xmap <silent><buffer> <plug>(vimtex-id) <sid>(vimtex-id)
|
xmap <silent><buffer> <plug>(vimtex-ip) <sid>(vimtex-ip)
|
||||||
xmap <silent><buffer> <plug>(vimtex-ad) <sid>(vimtex-ad)
|
xmap <silent><buffer> <plug>(vimtex-ap) <sid>(vimtex-ap)
|
||||||
onoremap <silent><buffer> <plug>(vimtex-id) :execute "normal \<sid>(v)\<sid>(vimtex-id)"<cr>
|
onoremap <silent><buffer> <plug>(vimtex-ip) :execute "normal \<sid>(V)\<sid>(vimtex-ip)"<cr>
|
||||||
onoremap <silent><buffer> <plug>(vimtex-ad) :execute "normal \<sid>(v)\<sid>(vimtex-ad)"<cr>
|
onoremap <silent><buffer> <plug>(vimtex-ap) :execute "normal \<sid>(V)\<sid>(vimtex-ap)"<cr>
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}1
|
" }}}1
|
||||||
|
|
||||||
|
function! vimtex#text_obj#commands(...) " {{{1
|
||||||
|
let l:cmd = vimtex#cmd#get_current()
|
||||||
|
if empty(l:cmd) | return | endif
|
||||||
|
|
||||||
|
let [l1, c1] = [l:cmd.pos_start.lnum, l:cmd.pos_start.cnum]
|
||||||
|
let [l2, c2] = [l:cmd.pos_end.lnum, l:cmd.pos_end.cnum]
|
||||||
|
|
||||||
|
if a:0 > 0
|
||||||
|
let l2 = l1
|
||||||
|
let c2 = c1 + strlen(l:cmd.name) - 1
|
||||||
|
let c1 += 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
call cursor(l1, c1)
|
||||||
|
normal! v
|
||||||
|
call cursor(l2, c2)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" }}}1
|
||||||
function! vimtex#text_obj#delimiters(...) " {{{1
|
function! vimtex#text_obj#delimiters(...) " {{{1
|
||||||
let [l:open, l:close] = vimtex#delim#get_surrounding('delim_all')
|
let [l:open, l:close] = vimtex#delim#get_surrounding('delim_all')
|
||||||
if empty(l:open) | return | endif
|
if empty(l:open) | return | endif
|
||||||
|
@ -95,9 +95,11 @@ Feature overview~
|
|||||||
- Move between sections with `[[`, `[]`, `][`, `]]`
|
- Move between sections with `[[`, `[]`, `][`, `]]`
|
||||||
- Move between matching delimiters with `%`
|
- Move between matching delimiters with `%`
|
||||||
- Text objects
|
- Text objects
|
||||||
|
- `ic` `ac` Commands
|
||||||
|
- `id` `ad` Delimiters
|
||||||
- `ie` `ae` LaTeX environments
|
- `ie` `ae` LaTeX environments
|
||||||
- `i$` `a$` Inline math structures
|
- `i$` `a$` Inline math structures
|
||||||
- `id` `ad` Delimiters
|
- `ip` `ap` Paragraphs
|
||||||
- Other mappings
|
- Other mappings
|
||||||
- Delete the surrounding command or environment with `dsc`/`dse`
|
- Delete the surrounding command or environment with `dsc`/`dse`
|
||||||
- Change the surrounding command or environment with `csc`/`cse`
|
- Change the surrounding command or environment with `csc`/`cse`
|
||||||
@ -307,12 +309,14 @@ This feature is explained in more detail later, see |vimtex-imaps|.
|
|||||||
tsd |<plug>(vimtex-delim-toggle-modifier)| `n`
|
tsd |<plug>(vimtex-delim-toggle-modifier)| `n`
|
||||||
<F7> |<plug>(vimtex-cmd-create)| `ni`
|
<F7> |<plug>(vimtex-cmd-create)| `ni`
|
||||||
]] |<plug>(vimtex-delim-close)| `i`
|
]] |<plug>(vimtex-delim-close)| `i`
|
||||||
a$ |<plug>(vimtex-a$)| `nxo`
|
ac |<plug>(vimtex-ac)| `nxo`
|
||||||
i$ |<plug>(vimtex-i$)| `nxo`
|
ic |<plug>(vimtex-ic)| `nxo`
|
||||||
ae |<plug>(vimtex-ae)| `nxo`
|
|
||||||
ie |<plug>(vimtex-ie)| `nxo`
|
|
||||||
ad |<plug>(vimtex-ad)| `nxo`
|
ad |<plug>(vimtex-ad)| `nxo`
|
||||||
id |<plug>(vimtex-id)| `nxo`
|
id |<plug>(vimtex-id)| `nxo`
|
||||||
|
ae |<plug>(vimtex-ae)| `nxo`
|
||||||
|
ie |<plug>(vimtex-ie)| `nxo`
|
||||||
|
a$ |<plug>(vimtex-a$)| `nxo`
|
||||||
|
i$ |<plug>(vimtex-i$)| `nxo`
|
||||||
ap |<plug>(vimtex-ap)| `nxo`
|
ap |<plug>(vimtex-ap)| `nxo`
|
||||||
ip |<plug>(vimtex-ip)| `nxo`
|
ip |<plug>(vimtex-ip)| `nxo`
|
||||||
% |<plug>(vimtex-%)| `nxo`
|
% |<plug>(vimtex-%)| `nxo`
|
||||||
@ -1118,11 +1122,17 @@ Map definitions~
|
|||||||
*<plug>(vimtex-delim-close)*
|
*<plug>(vimtex-delim-close)*
|
||||||
Close the current environment or delimiter (insert mode).
|
Close the current environment or delimiter (insert mode).
|
||||||
|
|
||||||
*<plug>(vimtex-a$)*
|
*<plug>(vimtex-ac)*
|
||||||
Text object for inline math (inclusive).
|
Text object for commands (inclusive).
|
||||||
|
|
||||||
*<plug>(vimtex-i$)*
|
*<plug>(vimtex-ic)*
|
||||||
Text object for inline math (exclusive).
|
Text object for commands (exclusive).
|
||||||
|
|
||||||
|
*<plug>(vimtex-ad)*
|
||||||
|
Text object for delimiters (inclusive).
|
||||||
|
|
||||||
|
*<plug>(vimtex-id)*
|
||||||
|
Text object for delimiters (exclusive).
|
||||||
|
|
||||||
*<plug>(vimtex-ae)*
|
*<plug>(vimtex-ae)*
|
||||||
Text object for environments (inclusive).
|
Text object for environments (inclusive).
|
||||||
@ -1130,11 +1140,11 @@ Map definitions~
|
|||||||
*<plug>(vimtex-ie)*
|
*<plug>(vimtex-ie)*
|
||||||
Text object for environments (exclusive).
|
Text object for environments (exclusive).
|
||||||
|
|
||||||
*<plug>(vimtex-ad)*
|
*<plug>(vimtex-a$)*
|
||||||
Text object for delimiters (inclusive).
|
Text object for inline math (inclusive).
|
||||||
|
|
||||||
*<plug>(vimtex-id)*
|
*<plug>(vimtex-i$)*
|
||||||
Text object for delimiters (exclusive).
|
Text object for inline math (exclusive).
|
||||||
|
|
||||||
*<plug>(vimtex-ap)*
|
*<plug>(vimtex-ap)*
|
||||||
Text object for paragraphs (inclusive).
|
Text object for paragraphs (inclusive).
|
||||||
|
Loading…
Reference in New Issue
Block a user