Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: delete to next character, when next character is not on same line

Tags:

vim

I'm sure that I'm going to get ridiculed for asking a duplicate question; someone must have asked the question before! But in an hour of searching I haven't found it. I must be searching for the wrong thing.

In Vi (or Vim) I am able to delete all characters up to the } character through the key sequence dt} (or df} if I want to remove the bracket as well).

However, this only works if the } character is on the current line. What I want to do is to delete everything up to the next } even if it's first occurrence is on a subsequent line.

I'm thinking something like d/} (where the slash /}<enter> in any other context, would take me to the next occurrence of }). For obvious reasons, this doesn't work, but I hope the intention is clear.

== EDIT ==

Okay okay okay... sorry. You're all right, it does work (on my clean-install machine). might be some messed-up mapping in a config file, but it's not working on my other one.

Hang head in shame

like image 575
cartbeforehorse Avatar asked Sep 26 '12 21:09

cartbeforehorse


3 Answers

d/}<cr> works. It's the canonical way to delete until the next } that's not on the same line. By the way, d?{<cr> does the same but in the opposite direction.

like image 175
romainl Avatar answered Nov 19 '22 19:11

romainl


This plugin should save you some keystrokes. It extends the functionality of fFtT,; so they work across lines.

like image 38
Raimondi Avatar answered Nov 19 '22 21:11

Raimondi


If the character is } or { placed at the beginning of the line, one way could be using Text object motions, so a command like d]] could be useful too.

like image 1
Birei Avatar answered Nov 19 '22 19:11

Birei