vim 여러줄에 걸친 패턴 검색

DwYoon의 이미지

여러 줄에 걸친 패턴에 대한 검색은 어떻게 하죠.

예를 들어

#define 어쩌고
#define 저쩌고

#define 어쩌구
#define 저쩌구

#define 이러쿵
#define 저러쿵
#define 뭐라구

이런 문서에서

/#define.*$\n#define.*$

이라고 하면 빈줄 없이 "'#define'으로 시작되는 연속되는 두 줄"을 검색할 수 있는데, "'#define'으로 시작되는 연속되는 여러줄"은 어떻게 검색하죠.

/[#define.*$\n]*^$

로 해 봤는데 안 되네요.

irondog의 이미지

제가 아는한은 안되는 걸로 알고 있습니다.

perl에서는 뒤에 s옵션을 주면 single line으로 인식해서 가능 합니다만...
vim에서는 안되더군요.

저도 열심히 찾아 봤는데 결국 못 찾았습니다.

elien의 이미지

조금 복잡해보입니다만;
/\(\(^$\n\)\|\(\%^\)\)\(^#define.*\n\)\+\_^\_$
와 같은 식으로 하면 원하시는 결과와 비슷할 것이라 생각합니다. :)

기본적으로
/\(^#define.*\n\)\+\_^\_$
을 하면 "#define 으로 시작되는 연속되는 여러줄" 을 검색할 수 있습니다만,
그렇게하면 라인의 시작에 #define 이 있는 것을 검색한 것과 동일하게 됩니다.

따라서 "빈줄 다음의 #define 으로 시작되는 여러줄" 과 "파일의 처음 다음의 #define 으로 시작되는 여러줄"을 검색하도록 하였습니다....

훗, 못 믿겠나?

elien의 이미지

집에와서 살펴보았더니 조금 차이가 있었네요; :cry:
아래는 "#define 으로 시작하는 여러줄" 을 찾을 수 있습니다 OTL
/\(^#define.*\n\)\+\_^\_$/e

훗, 못 믿겠나?

irondog의 이미지

아~ e옵션을 쓰셨군요. 헌데 e옵션을 쓰더라도 perl과는 달리
"." - any character - 가 "\n"를 포함하지 않아서 이래저래 불편하네요.

그래서 제가 하려던 것이 e를 썼음에도 안되었던 것이었네요. ㅋㅋㅋ
원래 안되는 것이려니 했는데...
"."대신에 "[0-9a-zA-Z_ \n\t]"처럼 \n을 집어 넣으니까 되네요.

감사~ ^^

elien의 이미지

Quote:
"." - any character - 가 "\n"를 포함하지 않아서

이것이라면 원하시는 것과 같지 않을까 싶습니다 :)
:help \_.
하지만 vi 가 search pattern 의 ending point 를 파일의 끝에서부터 찾아올라오는건지,
'\_.' 을 쓰면 원하는 패턴을 걸러내기가 쉽지 않더라구요 :(
으음

훗, 못 믿겠나?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.