Vim Tips Wiki

Ctrl-N completion for XML/XSLT attributes

Revision as of 06:05, September 28, 2008 by (Talk)

1,619pages on
this wiki
Tip 1469 Printable Monobook Previous Next

created January 12, 2007 · complexity basic · author Erik Falor · version n/a

I found myself switching back into lisp mode just to get Ctrl-N to complete really long attribute names containing hyphens. However, that has the undesirable side-effect of goofing up my indentation. I decided to dig in a little deeper and fix Ctrl-N such that it wouldn't take a hyphen to be a word boundary. As an added bonus, it'll include XSL namespace prefixes in its list of words.

Add this to your vimrc:

if has("autocmd")
  autocmd FileType {xml,xslt} setlocal iskeyword=@,-,\:,48-57,_,128-167,224-235
endif "has("autocmd")


  • This does not rely on extensions; instead it works on any file which the filetype detection identifies correctly.
  • It only changes the 'iskeyword' value for that buffer, not globally.



Shouldn't those word character settings rather be put into the appropriate filetype plugin?

In fact all you need is one line in your vimrc script, the following enables completion of hyphenated words for me:

autocmd FileType xml,html setlocal iskeyword+=-

Around Wikia's network

Random Wiki