program story

Vim의 내용이 아닌 HTML 태그를 삭제하는 방법

inputbox 2020. 11. 26. 08:15
반응형

Vim의 내용이 아닌 HTML 태그를 삭제하는 방법


내가 연 파일에 다음 코드가 있습니다 Vim.

<p>Hello stackoverflow!</p>

<p></p>태그를 삭제 하고 그 사이에 콘텐츠를 유지 하려면 어떻게 해야합니까? 즉, 무엇을 눌러 끝내야합니까?

Hello stackoverflow!

나는 누르는 d i t것이 그 반대 임을 압니다 .

저는 Janus를 사용하고 있습니다.


surround.vim 플러그인 설치를 눌러 d s tD elete urrounding t AG.

유사한 단축키 :

  • d s ( -주변 괄호 삭제 ()
  • d s " -둘러싼 큰 따옴표 삭제 ""
  • d s ' -주변의 작은 따옴표 삭제 ''

등등...


간단한 해결책은 다음과 같습니다 (태그 안에 커서가 있음).

yitvatp

이것이하는 일은 :

  • y -양크
  • it -태그 내부
  • vat -전체 태그 선택
  • p -이전에 잡아 당긴 텍스트를 그 위에 붙여 넣습니다.

Randy의 (+1) 답변을 좋아하고 방금 태그 블록에 대해 배웠습니다! 이것은 단지 보충 답변입니다.

그래서 YIT 수단과 VAT 수단 "비주얼 모드로 이동하고 '내부 태그 블록 꺼낼" (전체) 태그 블록 ".

이것은 도움말 파일을 읽기에 너무 게으른 사람들을위한 것입니다.

Tag blocks                      *tag-blocks*

For the "it" and "at" text objects an attempt is done to select blocks between
matching tags for HTML and XML.  But since these are not completely compatible
there are a few restrictions.

The normal method is to select a <tag> until the matching </tag>.  For "at"
the tags are included, for "it" they are excluded.  But when "it" is repeated
the tags will be included (otherwise nothing would change).  Also, "it" used
on a tag block with no contents will select the leading tag.

"<aaa/>" items are skipped.  Case is ignored, also for XML where case does
matter.

In HTML it is possible to have a tag like <br> or <meta ...> without a
matching end tag.  These are ignored.

The text objects are tolerant about mistakes.  Stray end tags are ignored.

이것을 선택한 키에 매핑하십시오.

vat<Esc>da>`<da>

http://vim.wikia.com/wiki/Delete_a_pair_of_XML/HTML_tags 에서 가져옴


더 큰 html 블록에 서라운드 .vim을 사용하여 dst 솔루션을 시도했습니다. 작동하지만 모든 하위 태그를 동일한 수준으로 들여 씁니다. 들여 쓰기를 변경해서는 안되며 모든 것을 엉망으로 만듭니다.

yitvatp를 사용한 Randys 솔루션도 작동하지만 붙여 넣은 태그 앞뒤에 빈 줄이 남습니다.

완벽한 솔루션이 있습니까?

참고URL : https://stackoverflow.com/questions/6264012/how-to-delete-html-tags-not-the-contents-in-vim

반응형