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 matching delimiters with `%`
|
||||
- Text objects
|
||||
- `ic ac` Commands
|
||||
- `id ad` Delimiters
|
||||
- `ie ae` LaTeX environments
|
||||
- `i$ a$` Inline math structures
|
||||
- `id ad` Delimiters
|
||||
- `ip ap` Paragraphs
|
||||
- Other mappings
|
||||
- Delete the surrounding command or environment with `dsc`/`dse`
|
||||
- Change the surrounding command or environment with `csc`/`cse`
|
||||
|
@ -393,6 +393,14 @@ function! s:init_mappings() " {{{1
|
||||
endif
|
||||
|
||||
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', 'ae', '<plug>(vimtex-ae)')
|
||||
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('o', 'i$', '<plug>(vimtex-i$)')
|
||||
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', 'ap', '<plug>(vimtex-ap)')
|
||||
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
|
||||
|
||||
" Paragraphs
|
||||
xnoremap <silent><buffer> <sid>(vimtex-ip) :<c-u>call vimtex#text_obj#paragraphs(1)<cr>
|
||||
xnoremap <silent><buffer> <sid>(vimtex-ap) :<c-u>call vimtex#text_obj#paragraphs()<cr>
|
||||
xmap <silent><buffer> <plug>(vimtex-ip) <sid>(vimtex-ip)
|
||||
xmap <silent><buffer> <plug>(vimtex-ap) <sid>(vimtex-ap)
|
||||
onoremap <silent><buffer> <plug>(vimtex-ip) :execute "normal \<sid>(V)\<sid>(vimtex-ip)"<cr>
|
||||
onoremap <silent><buffer> <plug>(vimtex-ap) :execute "normal \<sid>(V)\<sid>(vimtex-ap)"<cr>
|
||||
" Commands
|
||||
xnoremap <silent><buffer> <sid>(vimtex-ic) :<c-u>call vimtex#text_obj#commands(1)<cr>
|
||||
xnoremap <silent><buffer> <sid>(vimtex-ac) :<c-u>call vimtex#text_obj#commands()<cr>
|
||||
xmap <silent><buffer> <plug>(vimtex-ic) <sid>(vimtex-ic)
|
||||
xmap <silent><buffer> <plug>(vimtex-ac) <sid>(vimtex-ac)
|
||||
onoremap <silent><buffer> <plug>(vimtex-ic) :execute "normal \<sid>(v)\<sid>(vimtex-ic)"<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
|
||||
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-a$) :execute "normal \<sid>(v)\<sid>(vimtex-a$)"<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>
|
||||
" Paragraphs
|
||||
xnoremap <silent><buffer> <sid>(vimtex-ip) :<c-u>call vimtex#text_obj#paragraphs(1)<cr>
|
||||
xnoremap <silent><buffer> <sid>(vimtex-ap) :<c-u>call vimtex#text_obj#paragraphs()<cr>
|
||||
xmap <silent><buffer> <plug>(vimtex-ip) <sid>(vimtex-ip)
|
||||
xmap <silent><buffer> <plug>(vimtex-ap) <sid>(vimtex-ap)
|
||||
onoremap <silent><buffer> <plug>(vimtex-ip) :execute "normal \<sid>(V)\<sid>(vimtex-ip)"<cr>
|
||||
onoremap <silent><buffer> <plug>(vimtex-ap) :execute "normal \<sid>(V)\<sid>(vimtex-ap)"<cr>
|
||||
endfunction
|
||||
|
||||
" }}}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
|
||||
let [l:open, l:close] = vimtex#delim#get_surrounding('delim_all')
|
||||
if empty(l:open) | return | endif
|
||||
|
@ -95,9 +95,11 @@ Feature overview~
|
||||
- Move between sections with `[[`, `[]`, `][`, `]]`
|
||||
- Move between matching delimiters with `%`
|
||||
- Text objects
|
||||
- `ic` `ac` Commands
|
||||
- `id` `ad` Delimiters
|
||||
- `ie` `ae` LaTeX environments
|
||||
- `i$` `a$` Inline math structures
|
||||
- `id` `ad` Delimiters
|
||||
- `ip` `ap` Paragraphs
|
||||
- Other mappings
|
||||
- Delete the surrounding command or environment with `dsc`/`dse`
|
||||
- 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`
|
||||
<F7> |<plug>(vimtex-cmd-create)| `ni`
|
||||
]] |<plug>(vimtex-delim-close)| `i`
|
||||
a$ |<plug>(vimtex-a$)| `nxo`
|
||||
i$ |<plug>(vimtex-i$)| `nxo`
|
||||
ae |<plug>(vimtex-ae)| `nxo`
|
||||
ie |<plug>(vimtex-ie)| `nxo`
|
||||
ac |<plug>(vimtex-ac)| `nxo`
|
||||
ic |<plug>(vimtex-ic)| `nxo`
|
||||
ad |<plug>(vimtex-ad)| `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`
|
||||
ip |<plug>(vimtex-ip)| `nxo`
|
||||
% |<plug>(vimtex-%)| `nxo`
|
||||
@ -1118,11 +1122,17 @@ Map definitions~
|
||||
*<plug>(vimtex-delim-close)*
|
||||
Close the current environment or delimiter (insert mode).
|
||||
|
||||
*<plug>(vimtex-a$)*
|
||||
Text object for inline math (inclusive).
|
||||
*<plug>(vimtex-ac)*
|
||||
Text object for commands (inclusive).
|
||||
|
||||
*<plug>(vimtex-i$)*
|
||||
Text object for inline math (exclusive).
|
||||
*<plug>(vimtex-ic)*
|
||||
Text object for commands (exclusive).
|
||||
|
||||
*<plug>(vimtex-ad)*
|
||||
Text object for delimiters (inclusive).
|
||||
|
||||
*<plug>(vimtex-id)*
|
||||
Text object for delimiters (exclusive).
|
||||
|
||||
*<plug>(vimtex-ae)*
|
||||
Text object for environments (inclusive).
|
||||
@ -1130,11 +1140,11 @@ Map definitions~
|
||||
*<plug>(vimtex-ie)*
|
||||
Text object for environments (exclusive).
|
||||
|
||||
*<plug>(vimtex-ad)*
|
||||
Text object for delimiters (inclusive).
|
||||
*<plug>(vimtex-a$)*
|
||||
Text object for inline math (inclusive).
|
||||
|
||||
*<plug>(vimtex-id)*
|
||||
Text object for delimiters (exclusive).
|
||||
*<plug>(vimtex-i$)*
|
||||
Text object for inline math (exclusive).
|
||||
|
||||
*<plug>(vimtex-ap)*
|
||||
Text object for paragraphs (inclusive).
|
||||
|
Loading…
Reference in New Issue
Block a user