1

Is there a way do execute an action (change c, delete d, and so on) to the beginning or to the end of a motion?

For example:

Suppose we have:

Praesentium officia mollitia iste molestiae ipsa qui molestias sed. Aut quae
voluptas saepe qui eos. Non explicabo error rem enim voluptatem quibusdam.
Dolor labore labore est sequi nulla amet vel. Amet numquam vel ut nulla sunt et
sit rerum.

Minima est blanditiis facere consequuntur eos omnis laborum voluptatem. Sunt
sit id et voluptatibus consequatur blanditiis dignissimos. Quisquam qui commodi
ut eum error. CURSOR IS HERE -> _ <- . Occaecati quaerat porro quos veniam.
Similique impedit nisi totam.

Consequatur necessitatibus dolorem fugiat. Ullam ipsam et quos et omnis
blanditiis. Laboriosam ducimus et et deserunt beatae natus omnis. Eum officiis
dolore voluptas molestias. Assumenda illum qui cupiditate dicta. Minus
aspernatur omnis deleniti et voluptates.

Where the cursor is at the indicated position.

Pressing dap we get:

Praesentium officia mollitia iste molestiae ipsa qui molestias sed. Aut quae
voluptas saepe qui eos. Non explicabo error rem enim voluptatem quibusdam.
Dolor labore labore est sequi nulla amet vel. Amet numquam vel ut nulla sunt et
sit rerum.

Consequatur necessitatibus dolorem fugiat. Ullam ipsam et quos et omnis
blanditiis. Laboriosam ducimus et et deserunt beatae natus omnis. Eum officiis
dolore voluptas molestias. Assumenda illum qui cupiditate dicta. Minus
aspernatur omnis deleniti et voluptates.

Pressing dip we get:

Praesentium officia mollitia iste molestiae ipsa qui molestias sed. Aut quae
voluptas saepe qui eos. Non explicabo error rem enim voluptatem quibusdam.
Dolor labore labore est sequi nulla amet vel. Amet numquam vel ut nulla sunt et
sit rerum.


Consequatur necessitatibus dolorem fugiat. Ullam ipsam et quos et omnis
blanditiis. Laboriosam ducimus et et deserunt beatae natus omnis. Eum officiis
dolore voluptas molestias. Assumenda illum qui cupiditate dicta. Minus
aspernatur omnis deleniti et voluptates.

I'd like something like this: pressing dsp (delete from CURSOR to the START of the motion, in this case, to the start of paragprah.) we should get:

Praesentium officia mollitia iste molestiae ipsa qui molestias sed. Aut quae
voluptas saepe qui eos. Non explicabo error rem enim voluptatem quibusdam.
Dolor labore labore est sequi nulla amet vel. Amet numquam vel ut nulla sunt et
sit rerum.

_ <- . Occaecati quaerat porro quos veniam.
Similique impedit nisi totam.

Consequatur necessitatibus dolorem fugiat. Ullam ipsam et quos et omnis
blanditiis. Laboriosam ducimus et et deserunt beatae natus omnis. Eum officiis
dolore voluptas molestias. Assumenda illum qui cupiditate dicta. Minus
aspernatur omnis deleniti et voluptates.

Similarly, pressing dep (delete from CURSOR to the END of the motion. in this case, to the end of the paragprah):

Praesentium officia mollitia iste molestiae ipsa qui molestias sed. Aut quae
voluptas saepe qui eos. Non explicabo error rem enim voluptatem quibusdam.
Dolor labore labore est sequi nulla amet vel. Amet numquam vel ut nulla sunt et
sit rerum.

Minima est blanditiis facere consequuntur eos omnis laborum voluptatem. Sunt
sit id et voluptatibus consequatur blanditiis dignissimos. Quisquam qui commodi
ut eum error. CURSOR IS HERE -> _ 

Consequatur necessitatibus dolorem fugiat. Ullam ipsam et quos et omnis
blanditiis. Laboriosam ducimus et et deserunt beatae natus omnis. Eum officiis
dolore voluptas molestias. Assumenda illum qui cupiditate dicta. Minus
aspernatur omnis deleniti et voluptates.

So, basically, the idea is prefixing the motions with a modifier (for example, s for start, e for end) the same way it is done with the modifiers a (around) and i (inner).

Is this possible in Vim ? Maybe through some plugin?

3
  • This is where it helps to separate motions ({, e, etc.) from text-objects (ap, aw, etc.): both can be arguments to operators, though motions are also available on their own.
    – D. Ben Knoble
    Aug 9, 2021 at 17:28
  • See also vi.stackexchange.com/q/22570/18609, in particular the last answer talking about the "vim-ninja-feet" plug-in.
    – filbranden
    Aug 9, 2021 at 18:12
  • 1
    Thanks @filbranden. The answer combined with your comment gives what I needed! Aug 9, 2021 at 21:00

1 Answer 1

3

Try using the motions that take you forward and backward for a paragraph:

d{ deletes from cursor backwards to start of paragraph.
d} deletes from cursor forward to end of paragraph.

See all motions in :help motions.txt

                            *{*
{           [count] paragraphs backward.  |exclusive| motion.

                            *}*
}           [count] paragraphs forward.  |exclusive| motion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.