How to make whole line ignore semi-colon?
hbarcelos opened this issue ยท 4 comments
Sometimes we want to surround and entire line, but keep the ;
as the last character.
If I enable the vim-surround
mode I can:
foo| bar baz;
-> yssb -> (foo| bar baz;)
.
Would it be possible to make the "whole line" text object ignore the ;$
pattern so I can:
foo| bar baz;
-> yssb -> (foo| bar baz);
.
Unfortunately, there is no such functionality, but it seems convenient. I may consider including it.
Here are a couple of workarounds (default bindings)
sat;)
or if the line contains semi-colons
sa/;$<cr>)
Thanks for that. Workarounds are nice!
They assume I'm already at the beginning of the line though.
Most of the time I use sandwich, I'm in the middle of some line.
_sat;) might do the trick though.
It would be nice to have a i;
text object though, so I could simply:
sai;)
sri;)]
ci;
It would be nice to have a i; text object though, so I could simply:
Sounds good.
function! s:textobj_line_without_semicolon(a_or_i) abort
if a:a_or_i is# 'a'
normal! v0og_
else
normal! v^og_
endif
if getline('.') =~# ';$'
normal! h
endif
endfunction
onoremap <silent> i; :<C-u>call <SID>textobj_line_without_semicolon('i')<CR>
xnoremap <silent> i; :<C-u>call <SID>textobj_line_without_semicolon('i')<CR>
onoremap <silent> a; :<C-u>call <SID>textobj_line_without_semicolon('a')<CR>
xnoremap <silent> a; :<C-u>call <SID>textobj_line_without_semicolon('a')<CR>