I'm trying to create a mapping based on the file type. (as explained in this chapter https://learnvimscriptthehardway.stevelosh.com/chapters/12.htm)
:autocmd FileType javascript nnoremap <buffer> <localleader>c I//<esc>
To test this mapping, I open a new buffer (through :vsplit
) containing a javascript file but the mapping does not work at all and I don't understand why.
When I hit ,
and c
simultaneously I expect vim to add //
in the left of my line.
The relevant settings:
let mapleader=, set ft? --> filetype=javascript
Any ideas?
UPDATE
This is what I get when I hit :nmap
n ,c *@I//<Esc>
n % <Plug>(MatchitNormalForward)
n ( [
n ) ]
n ,ts * :PHPUnitSwitchFile<CR>
n ,tf * :PHPUnitRunCurrentFile<CR>
n ,ta * :PHPUnitRunAll<CR>
n ,da * :call PhpDocAll()<CR>
n ,cog * :call PhpCreateGetters()<CR>
n ,sg * :call PhpCreateSettersAndGetters()<CR>
n ,du * :call PhpDetectUnusedUseStatements()<CR>
n ,np * :call PhpCreateProperty()<CR>
n ,ep * :call PhpExtractClassProperty()<CR>
n ,rm * :call PhpRenameMethod()<CR>
n ,eu * :call PhpExtractUse()<CR>
n ,rcv * :call PhpRenameClassVariable()<CR>
n ,rlv * :call PhpRenameLocalVariable()<CR>
n ,r <Plug>(FerretAcks)
n ,l <Plug>(FerretLack)
n ,sv * :source $MYVIMRC<CR>
n ,ev * :vsplit $MYVIMRC<CR>G
n ,bs :CtrlPMRU<CR>
n ,bm :CtrlPMixed<CR>
n ,bb :CtrlPBuffer<CR>
n ,p :CtrlP<CR>
n ,A * :exec "Rg ".expand("<cword>")<CR>
n ,a * :Rg<Space>
n ,f :NERDTreeFind<CR>
n ,t :NERDTreeToggle<CR>
n ,s * :%s/\<<C-R><C-W>\>/
n <p & :<C-U>call <SNR>52_putline(v:count1 . ']p', 'Below')<CR><']
n <P & :<C-U>call <SNR>52_putline(v:count1 . '[p', 'Above')<CR><']
n <leader-o> * :CtrlPTag<CR>
n =p & :<C-U>call <SNR>52_putline(v:count1 . ']p', 'Below')<CR>=']
n =P & :<C-U>call <SNR>52_putline(v:count1 . '[p', 'Above')<CR>=']
n =op * <Nop>
n =o <SNR>52_legacy_option_map(nr2char(getchar()))
n >p & :<C-U>call <SNR>52_putline(v:count1 . ']p', 'Below')<CR>>']
n >P & :<C-U>call <SNR>52_putline(v:count1 . '[p', 'Above')<CR>>']
n [C 9999[c
n [c <Plug>(signify-prev-hunk)
n [xx <Plug>unimpaired_line_xml_encode
n [x <Plug>unimpaired_xml_encode
n [uu <Plug>unimpaired_line_url_encode
n [u <Plug>unimpaired_url_encode
n [yy <Plug>unimpaired_line_string_encode
n [y <Plug>unimpaired_string_encode
n [P <Plug>unimpairedPutAbove
-- Plus --
<LocalLeader>
so that would be what:let maplocalleader
is set to, perhaps` which is the default? Does
\c` work here? Use:nmap
to inspect the mappings that are set... Also double check that:set ft?
confirms it'sft=javascript
. – filbranden♦ Aug 9 '20 at 17:38set hidden
and such) you won't get anotherFileType
event just because you did a split. – Matt Aug 9 '20 at 17:57<localleader>c
as a prefix? So Vim is waiting to see if you're going to type more characters to trigger the longer mapping. Take a look at the output of:nmap
to see if that's the case. – filbranden♦ Aug 9 '20 at 19:34