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.

Edit: Working version.

I've mapped [[ and ]] to my own functions:

nmap <silent> ]] :let &tabstop += 1 <CR> :echo 'tabstop =' &tabstop <CR>
nmap <silent> [[ :let &tabstop -= &tabstop > 1 ? 1 : 0 <CR> :echo 'tabstop =' &tabstop <CR>

However, according to :verbose map [[ these are overridden by /usr/share/vim/vim72/ftplugin/php.vim. How do I get rid of the PHP mappings while keeping my own? I've tried

autocmd FileType php unmap! [[
autocmd FileType php unmap! ]]

according to the tutorial, but then I get error messages at Vim startup:

Error detected while processing FileType Auto commands for "php":
E31: No such mapping
E31: No such mapping
Press ENTER or type command to continue

Using nnoremap instead of nmap doesn't help.

Putting the mappings in ~/.vim/after/ftplugin/php.vim also didn't work. vim -V shows:

...
finished sourcing /usr/share/vim/vim72/ftplugin/php.vim
...
finished sourcing /home/user/.vim/after/ftplugin/php/php.vim

So it does find the supposed override.

Combining nnoremap and the "after" script doesn't work either.

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

Specific definitions (filetype-specific, project-specific, ...) shall always be declared local to the current buffer. This is accomplished with the <buffer> qualifier for mappings and abbreviations (commands use -b, and menus need a specific plugin to emulate this, variables are prefixed by b:, and settings shall be set (sic) with :setlocal).

Moreover to declare it (i.e. a ft specific definition) local to the buffer, you can use autocommand as you seem to be doing, however I'd recommend instead to use ftplugins. It's much more maintenable, and all the rules regarding the overriding of the various definitions (mappings, etc.) are already taken into account.

" => ftplugin/php/php_my_stuff.vim
" headers guards...
...
:nnoremap <silent> <buffer> ]] :setlocal ts+=1<cr>:set ts?<cr>
:nnoremap <silent> <buffer> [[ :setlocal ts-=1<cr>:set ts?<cr>

PS: SO, or SU would have been a better fit for such a question.

share|improve this answer
    
This solution actually worked! Just added <buffer> to the mapping lines in ˜/.vim/after/ftplugin/php.vim and that was it. –  l0b0 Jul 2 '12 at 11:14
add comment

I'd try to use hints for overruling the default plugin checks described here. To sum it up: drop your mappings plugin file late in the runpath (e.g. ~/.vim/after/ftplugin/php.vim) to override the global mappings.

share|improve this answer
    
That didn't work; please see the updated question. –  l0b0 Jun 28 '12 at 7:54
add comment

did you try to use nnoremap instead of nmap in your .vimrc

nnoremap <silent> ]] :let &tabstop += 1 <CR> :echo 'tabstop =' &tabstop <CR>
nnoremap <silent> [[ :let &tabstop -= &tabstop > 1 ? 1 : 0 <CR> :echo 'tabstop =' &tabstop <CR>
share|improve this answer
    
Doesn't work. It still uses the PHP shortcuts. –  l0b0 Jun 28 '12 at 7:19
    
hmm - did you try to do it manually after the plugin was loaded. –  epsilonhalbe Jun 28 '12 at 9:01
    
Yep, tried copying them after : in a Vim session, and no change. –  l0b0 Jun 28 '12 at 9:22
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.