Programing

Vim에서 자동 줄 바꿈 (들여 쓰기 유지)

lottogame 2020. 9. 12. 11:20
반응형

Vim에서 자동 줄 바꿈 (들여 쓰기 유지)


나는 vim에서 전체 단어를 감싸는 방법을 설명하는 이 게시물보고있었습니다 . 허용 된 해결책은 다음과 같습니다.

:set formatoptions=l
:set lbr

이 텍스트를 사용합니다 (탭은 \ t로 표시됨).

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will wr|ap here                            
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

이렇게하면 다음과 같은 동작이 수행됩니다 (탭은 \ t로 표시됨).

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will   |
|wrap here                              |
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

그러나이 기능을 재정의하고 싶습니다. 줄 바꿈 된 줄 앞에는 위의 줄에 1을 더한 것과 같은 수의 탭이 있기를 바랍니다. 즉 :

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will   |
|\t\t\twrap here                        |
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

어떤 아이디어?


breakindent 패치가 당신을 위해 무엇을 찾고있다. 이 스레드에있는 지침을 사용하여 성공적으로 적용했습니다.

Homebrew를 사용하는 OS X에서 breakindent 패치로 Vim 패치

특히 echristopherson의 Homebrew 공식.

이 스레드는 오래되었지만 Google에서 인기가 있으며 해결책을 찾으려고 할 때 여러 번 발견했습니다.

편집 :이 패치는 이제 패치 7.4.338로 vim에 포함되어 있습니다. 참조 : https://retracile.net/blog/2014/07/18/18.00

Yosemite (Mac OS X)에서는 hombrew와 함께 snowbound의 명령을 사용했습니다.

brew install macvim --with-features=huge --override-system-vim --HEAD 

원래 질문을 받았을 때는 작동하지 않았지만 2014 년 6 월 25 일부터 작동합니다. (Vim을 해당 날짜보다 최신 버전으로 업데이트한다고 가정)

.vimrc에 추가하십시오.

" Indents word-wrapped lines as much as the 'parent' line
set breakindent
" Ensures word-wrap does not split words
set formatoptions=l
set lbr

그리고 그게 다야!

-

어떤 사람들 (나 자신도 포함)은 여러 컴퓨터에서 하나의 .vimrc를 공유합니다. 이 경우 성가신 오류 메시지를 방지하기 위해이 줄을 견고하게 만드는 것이 중요합니다. 이것은 조금 더 좋습니다.

if has("patch-7.4.354")
    " Indents word-wrapped lines as much as the 'parent' line
    set breakindent
    " Ensures word-wrap does not split words
    set formatoptions=l
    set lbr
endif

이렇게하면 이전 버전의 vim을 사용하는 경우 오류 메시지가 표시되지 않습니다.


당신이 얻을 수있는 최선 showbreak은 각 줄 바꿈 된 줄 앞에 고정 된 문자열을 넣는 옵션입니다 (을 사용합니다 set showbreak=...).


I agree with the answer that says 'showbreak' is the best option. Showbreak does not typically allow you to put nonprinting characters (e.g., spaces or tabs) into the showbreak string, so as typically used it will just give you an indicator along left margin, i.e., no real indent. This isn't great, since main goal of OP, I think, is to give wrapped lines an indent keep them from cluttering left margin area and looking like lines of their own.

So one way to add an (ugly) indent using showbreak is to just use a lot of characters, .e.g, ":set showbreak=>--------------->". This results in something that looks like this:

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will   |
|>--------------->wrap here             |
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

A better alternative might be to make use of nonbreaking space characters (assuming your instance of Vim is unicode enabled), each of which can be entered into the showbreak string using the key sequence of ctrl-v,160. That way you can enter a showbreak string that is blank at the left side and appear to be a true indent. E.g., ":set showbreak=. . . . . . . . . . >>" where each '.' in the command is actually a nonbreaking space character entered by pressing ctrl-V,160. That way you end up with a wrap that is nicely indented, like this:

 *Inside of window                        *Outside of window
|---------------------------------------|    
|\t\tthis is a like of text that will   |
|            >>wrap here                |
|\t\tcan you see the wrap               |
|                                       |
|---------------------------------------|

You still don't have any ability to vary the level of indent according to indent of previous line, but at least you get clean indent of wrapped lines without lots of visual clutter along left margin of window. There could still be confusion if indent of a wrapped line is less than that of the beginning of an actual line, but this could perhaps be avoided by making the showbreak "indent" quite large (i.e., greater than any indent commonly found in your code) but still small enough that it provides enough space for legible wrapping of the text. For many uses I think a showbreak indent of 40 or 50 spaces would do this pretty well.

참고URL : https://stackoverflow.com/questions/2828174/word-wrap-in-vim-preserving-indentation

반응형