vim-sandwich icon indicating copy to clipboard operation
vim-sandwich copied to clipboard

How to make whole line ignore semi-colon?

Open hbarcelos opened this issue 3 years ago • 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);.

hbarcelos avatar Jun 03 '22 00:06 hbarcelos

Unfortunately, there is no such functionality, but it seems convenient. I may consider including it.

machakann avatar Jun 06 '22 15:06 machakann

Here are a couple of workarounds (default bindings)

sat;)

or if the line contains semi-colons

sa/;$<cr>)

EgZvor avatar Nov 09 '22 07:11 EgZvor

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;

hbarcelos avatar Nov 11 '22 19:11 hbarcelos

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>

machakann avatar Nov 14 '22 15:11 machakann