Riza Khan
Riza Khan

Reputation: 3158

Creating HTML Tags in VIM

I am trying to keep my VIM plugin use to a minimum (call me crazy) and I came across a great VIM script that does what I need quite well.

imap <C-t> <></><Esc>5hdiw3lpT>i

It works great for creating a <div></div> however, I am currently working in Vuetify and there are tags like <v-img></v-img> and the letters before the dash gets missed. I get something like: v-<img></img>.

Any idea what adjustments I can make to my script that will use the letter before the dash as part of the tag?

Thank you,

Upvotes: 0

Views: 437

Answers (1)

romainl
romainl

Reputation: 196876

You can change a few things…

If you add - to :help 'isfname' the diw part of your mapping will cover the whole v-img.

Here is a version of your mapping that doesn't rely on counting characters:

inoremap <C-t> <C-o>diw<<C-r>"></<C-r>"><C-o>T>
  • <C-o> leaves insert mode only for one normal mode command, without triggering autocomands,
  • diw cuts the word under the cursor to the unnamed register, ",
  • < inserts <,
  • <C-r>" inserts the content of register ",
  • ></ inserts ></,
  • <C-r>" inserts the content of register ",
  • > inserts >,
  • <C-o> leaves insert mode only for one normal mode command, without triggering autocomands,
  • T> moves the cursor between the opening and closing tags.

Reference:

:help i_ctrl-o
:help i_ctrl-r
:help ""
:help T

Upvotes: 1

Related Questions