Search code examples
regexemacsline

How to kill every line that has the pattern: #+NAME:, in Emacs?


I have a lot of org-mode code-blocks and I would like to delete all their names, so they are all unique when I run them again.

e.g.,

#+NAME: 05298705-f04e-47df-b7f0-ca8bd2d0ef4c
#+begin_src ein-r :session localhost :results output :exports both :eval no
  life_2015_clean$Status <- as.numeric(as.factor(life_2015_clean$Status))
  ## life_2015_clean <- na.omit(life_2015_clean) ## eliminando muitos dados.
  summary(life_2015_clean)
#+end_src

Would become

#+begin_src ein-r :session localhost :results output :exports both :eval no
  life_2015_clean$Status <- as.numeric(as.factor(life_2015_clean$Status))
  ## life_2015_clean <- na.omit(life_2015_clean) ## eliminando muitos dados.
  summary(life_2015_clean)
#+end_src

as well as any line that has #+NAME: (...) in it.


Solution

  • Use command flush-lines (also known as delete-matching-lines) to delete lines that match a regexp.

    You just need a regexp that matches (only) lines that you want to delete.

    It sounds like you want to match #+NAME: (...), so perhaps try a regexp such as this: ^#[+]NAME: (.