Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have been working through the examples and exercises in Steve Losh's book Learn Vimscript the Hard Way, and I have hit some serious trouble in chapter 12 on Auto Commands. I am running MacVim on Snow Leopard, with filetype on in my .gvimrc. My leader and local leader keys are bound to , and . respectively, as shown the book.

Everything is good until I get to the section on FileType events, which begins with the following commands:

:autocmd FileType javascript nnoremap <buffer> <localleader>c I//<esc>
:autocmd FileType python     nnoremap <buffer> <localleader>c I#<esc>

These commands, as written, simply do not work. My first suspicion after reading through :help autocmd was that the autocmd event was missing, and that all that was provided was the pattern and command. So I changed the command to:

:autocmd BufRead FileType javascript nnoremap <buffer> <localleader>c I//<esc>

Still no luck. No luck either when I try <leader> instead of <localleader> with the event included. The only way I can get it to work is by replacing FileType javascript with *.js and using <leader> instead of <localleader>, or altogether:

:autocmd BufRead *.js nnoremap <buffer> <leader>c I//

I am wondering what is wrong here. From my reading of the Vim documentation, the FileType pattern should work. The . as <localleader> works fine in other instances.

share|improve this question
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.