Vim은 빈 줄을 삭제합니다.
Vim에서 빈 줄을 제거하려면 어떤 명령을 실행할 수 있습니까?
:g/^$/d
:g
정규식과 일치하는 줄에서 명령을 실행합니다. 정규식은 '빈 줄'이고 명령은 :d
(삭제)입니다.
찾았습니다.
g/^\s*$/d
출처 : Vim Wiki의 Power of g
간략한 설명
:g
:[range]g/pattern/cmd
이는 각 행 일치 패턴 에 대해 Ex 명령 cmd 를 실행 하여 지정된 [범위] (기본 전체 파일)에서 작동합니다 (Ex 명령은 삭제 와 같이 콜론으로 시작하는 명령입니다 ). cmd를 실행하기 전에 " "이 현재 행으로 설정됩니다.
:d
.
:v/./d
또는
:g/^$/d
또는
:%!cat -s
다음을 사용하여 여러 개의 빈 줄만 제거하고 (단일 빈 줄로 줄임) 단일 빈 줄은 그대로 둘 수 있습니다.
:g/^\_$\n\_^$/d
모든 공백 줄을 제거하는 방법
:%s,\n\n,^M,g
(모든 빈 줄이 사라 졌다는 것을 여러 번 수행하십시오)
하나의 빈 줄을 남기고 모든 빈 줄을 제거하는 방법
:%s,\n\n\n,^M^M,g
(여러 번 수행)
최대 두 개의 빈 줄을 남기고 모든 빈 줄을 제거하는 방법,
:%s,\n\n\n\n,^M^M^M,g
(여러 번 수행)
^ M을 입력하려면 Windows에서 Ctrl-Q와 Ctrl-M을 눌러야합니다
어때 :
:g/^[ \t]*$/d
vim에서 perl로 작업 :
:%!perl -pi -e s/^\s*$//g
이것은 나를 위해 작동합니다
:%s/^\s*$\n//gc
이 함수는 두 개 이상의 빈 줄만 제거하고 vimrc에 아래 줄을 넣은 다음 \ d를 사용하여 함수를 호출합니다.
fun! DelBlank()
let _s=@/
let l = line(".")
let c = col(".")
:g/^\n\{2,}/d
let @/=_s
call cursor(l, c)
endfun
map <special> <leader>d :keepjumps call DelBlank()<cr>
이 페이지에서 몇 가지 답변을 시도했지만 많은 답변이 작동하지 않았습니다. Windows 7에서 Vim을 사용하고 있기 때문일 수 있습니다 (조롱하지 말고 저를 동정하십시오 : p)?
Windows 7의 Vim에서 작동하는 가장 쉬운 방법은 다음과 같습니다.
:v/\S/d
Vim Wikia에 대한 더 긴 답변은 다음과 같습니다. http://vim.wikia.com/wiki/Remove_unwanted_empty_lines
:g/^\s*$/d
^ begin of a line
\s* at least 0 spaces and as many as possible (greedy)
$ end of a line
풀
:command -range=% DBL :<line1>,<line2>g/^\s*$/d
in your .vimrc,then restart your vim. if you use command :5,12DBL it will delete all blank lines between 5th row and 12th row. I think my answer is the best answer!
Press delete key in insert mode to remove blank lines.
If something has double linespaced your text then this command will remove the double spacing and merge pre-existing repeating blank lines into a single blank line. It uses a temporary delimiter of ^^^ at the start of a line so if this clashes with your content choose something else. Lines containing only whitespace are treated as blank.
%s/^\s*\n\n\+/^^^\r/g | g/^\s*$/d | %s/^^^^.*
This worked for me:
:%s/^[^a-zA-Z0-9]$\n//ig
It basically deletes all the lines that don't have a number or letter. Since all the items in my list had letters, it deleted all the blank lines.
참고URL : https://stackoverflow.com/questions/706076/vim-delete-blank-lines
'Programing' 카테고리의 다른 글
페이지로드 후 JavaScript를 실행하는 방법은 무엇입니까? (0) | 2020.10.02 |
---|---|
가능한 모든 배열 초기화 구문 (0) | 2020.10.02 |
CR LF, LF 및 CR 줄 바꿈 유형의 차이점은 무엇입니까? (0) | 2020.10.02 |
Windows cmd stdout 및 stderr을 단일 파일로 리디렉션 (0) | 2020.10.02 |
파일의 전체 경로를 얻는 방법은 무엇입니까? (0) | 2020.10.02 |