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

How to make whole line ignore semi-colon? #141

Open
hbarcelos opened this issue Jun 3, 2022 · 4 comments
Open

How to make whole line ignore semi-colon? #141

hbarcelos opened this issue Jun 3, 2022 · 4 comments

Comments

@hbarcelos
Copy link

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);.

@machakann
Copy link
Owner

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

@EgZvor
Copy link

EgZvor commented Nov 9, 2022

Here are a couple of workarounds (default bindings)

sat;)

or if the line contains semi-colons

sa/;$<cr>)

@hbarcelos
Copy link
Author

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;

@machakann
Copy link
Owner

machakann commented Nov 14, 2022

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants