Notepad ++にこの機能があり、タグをクリックすると(たとえば)、終了タグ()も自動的に強調表示されることをご存知ですか?それは何と呼ばれていますか?また、Vimをどのように調整してこの機能も使用できるようにしますか?
そして、Vimを強力で効率的なHTMLエディターに変える方法は他にありますか?
私はすべての HTML 編集を vim で行っています。vim で HTML と XML を編集するのに最も役立つ 3 つのプラグインは、matchit、sround、およびallmlです。
Matchit では、'%' を使用して開始/終了タグにジャンプできます。サラウンドを使用すると、周囲のタグを簡単に追加、削除、および変更できます。Allml は、(X)HTML および XML を編集するための優れたマッピング セットを提供します。
選択したテキストをタグでラップ:
function! VisualTagsWrap()
if !exists('g:tags_to_wrap')
let g:tags_to_wrap=[]
endif
let g:tags_to_wrap=split(input('space separated tags to wrap block: ', join(g:tags_to_wrap, ' ')), '\s\+')
if len(g:tags_to_wrap)>0
execute 'normal! `>a</'.join(reverse(g:tags_to_wrap), '></').'>'
execute 'normal! `<i<'.join(reverse(g:tags_to_wrap), '><').'>'
endif
endfunction
vnoremap <silent>,w <ESC>:call VisualTagsWrap()<CR>
タグの閉じ括弧をハイライトします:
set matchpairs+=<:>
ダミーテキスト (挿入モードで「lorem」と入力):
inoreabbrev lorem Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
タグを一致させるには:
matchitプラグインを見てください。Vim 6 以降の matchit.vim は標準配布にパッケージ化されています。matchit をインストールするには、 をお読みください:help matchit-install。
filetype plugin onがvimrcにあることを確認してください。
インストールしたら%、開始/終了タグを一致させるために使用します。:help matchit-introさらにヘルプが必要です。
Fedora 15にはパッケージmatchit.vimが付属しています。vim-common次に、これをあなたに追加して機能させます~/.vimrc。
source /usr/share/vim/vim73/macros/matchit.vim
Shift+5次に(aka ) を押すだけ%で、一致するタグにジャンプします。
.html サフィックスのない html ファイルを編集する場合は、次のコマンドを使用します。
:set filetype=html
matchit マクロを有効にします。