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

Apply command to each line in "range" / selection #79

Closed
amerlyq opened this issue Sep 21, 2021 · 2 comments
Closed

Apply command to each line in "range" / selection #79

amerlyq opened this issue Sep 21, 2021 · 2 comments

Comments

@amerlyq
Copy link

amerlyq commented Sep 21, 2021

I have a command here:

nmap <buffer> <Plug>(nou-set-goal-mandatory) "_c<Plug>(textobj-nou-goal-i)!<Esc>

which works as [_] task -> [!] task.
Often I have multiple tasks in column and want to apply transformation in batch.
But looking through sources of textobj-user and experimenting with it had no results.
How this usecase can be implemented?
Is it outside of scope of textobj-user or is it not solvable in general?
Am I supposed to write "range" function wrapper and apply textobj manually to each line?

@kana
Copy link
Owner

kana commented Sep 21, 2021

It's outside the scope of vim-textobj-user. Your usage implies modifying multiple text objects at once. But Vim can't handle multiple ranges at the same time. Therefore vim-textobj-user can't support such usage.

So you have to define a custom key mapping for that batch operation. For example:

vnoremap <buffer> <Plug>(nou-set-goal-mandatory-batch) :normal "_c<Plug>(textobj-nou-goal-i)!<C-v><Esc><CR>

(Note that this example assumes that <Plug>(textobj-nou-goal-i) selects a range within the cursor line.)

@amerlyq
Copy link
Author

amerlyq commented Sep 23, 2021

I was able to make it work only like this:

xnoremap <buffer> <Plug>(nou-set-goal-mandatory) :<C-u>exe "'<,'>norm \"_c\<Plug>(textobj-nou-goal-i)!<C-v><Esc>"<CR>

Ugly hell :)

@amerlyq amerlyq closed this as completed Sep 23, 2021
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

2 participants