vim에서 버퍼의 내용을 문자열로 얻는 방법은 무엇입니까?

vim에서 버퍼의 내용을 문자열로 얻는 방법은 무엇입니까?

버퍼 내용을 다양한 기능으로 활용하려고 합니다.

답변1

join및 을 사용할 수 있습니다 getline. ~에서:h join

join({list} [, {sep}])                  *join()*
        Join the items in {list} together into one String.
        When {sep} is specified it is put in between the items.  If
        {sep} is omitted a single space is used.
        Note that {sep} is not added at the end.  You might want to
        add it there too: >
            let lines = join(mylist, "\n") . "\n"
<       String items are used as-is.  |Lists| and |Dictionaries| are
        converted into a string like with |string()|.
        The opposite function is |split()|.

그리고로부터:h getline

getline({lnum} [, {end}])
        Without {end} the result is a String, which is line {lnum}
        from the current buffer.  Example: >
            getline(1)

...

        When {end} is given the result is a |List| where each item is
        a line from the current buffer in the range {lnum} to {end},
        including line {end}.
        {end} is used in the same way as {lnum}.
        Non-existing lines are silently omitted.
        When {end} is before {lnum} an empty |List| is returned.
        Example: >
            :let start = line('.')
            :let end = search("^$") - 1
            :let lines = getline(start, end)

이를 모두 종합하면 유용한 예가 됩니다.

:let buff=join(getline(1, '$'), "\n")

관련 정보