Yes, this block looks fine.
When you use autocmd's, put them in an
augroup block with a unique name and start that block with an
autocmd!, which will erase all autocmd's in that group. This way, if your Vimscript file is reloaded, the autocmd's will not be duplicated. (If you define them more than once, the commands will run multiple times.)
Regarding the mapping, you should use a
<buffer> mapping in filetype autocmd's, so that these mappings apply only to files of that type. So that's correct too. It's also good that the mapping is non-recursive, you should typically write your mappings to be non-recursive, by default, except on the few cases where you really need them to be recursive.
It's a bit unusual to use
<Leader> on an
<Leader> is typically a printable character,
\ by default, but often set to
; or even
<Space>. This might make the insert-mode mapping a little awkward, particularly when you actually want to insert the
<Leader> character, or some possible settings for
<Leader> might make this mapping fully unusable... The map leader is typically meant for normal, visual or operator-pending mappings, not really for insert mode.
Your mapping will only be set on
htmldjango filetypes... However, there's one case where they might "leak" into other filetypes, which is the case where you have a file take one of these filetypes, but then you switch the filetype to something else. In that case, the mapping will not be removed.
A better solution for adding a mapping for HTML filetypes is to create a
~/.vim/after/ftplugin/html.vim file and add the mapping there.
As a bonus, you don't need to worry about filetypes such as
ftplugin/html.vim and that will include your custom extension
There are actually other languages which source HTML as well, so by defining your own ftplugin, all those others will be indirectly affected too. For example,
One final advantage of writing an ftplugin worth mentioning is that it offers a mechanism to undo the mapping when switching filetype of an existing buffer, through the
Putting it all together, and using
<C-Space> for the mapping (assuming that mapping works in your setup), you can handle this by creating file
~/.vim/after/ftplugin/html.vim with the following contents:
let b:undo_ftplugin = ""
let b:undo_ftplugin .= "|iunmap <buffer> <C-Space>"
inoremap <buffer> <C-Space>