vimrc mapping problem; execute python script mapping not working from vimrc
grr. I'm struggling with Vim's learning curve.
And trying to get a simple mapping in my vimrc to execute the current buffer's python script. The mapping is well-formed and works after I ent开发者_运维问答er it into the command line in Vim. This is the mapping:
map <buffer>
<S-e>
:w<CR>
:!usr/bin/env python % <CR>
But it won't load from my vimrc :( I'm using the basic .vimrc_sample with only this mapping appended. What's weird is that I could get a different mapping working from the vimrc:
map <S-t>
itest<Esc>
This one works, but not the script executer? What gives?
Ubuntu 10.10 Python 2.6 Vim 7.2
Help is very appreciated!
I suspect that you have something before map
: <buffer>
argument means that mapping is defined for current buffer only, so adding it to vimrc without something like autocmd FileType python
before it is weird. Maybe it is the reason why it does not work: you somehow switch to another buffer before testing this mapping.
Some additional things to concern:
- Never use
map
where can usenoremap
instead. - You probably don't want this mapping to be defined for visual (at least without
<C-u>
beforew
) and select modes, and definitely don't want it to be defined for operator-pending modes, so usennoremap
. <S-e>
andE
are equivalent.- You can combine
w
and!...
in one command using pipe symbol::w | !/usr/bin/env python %<CR>
. - You forgot slash before
usr
.
Jesus, Murphy's Law.
After searching for an answer for an hour, 1 min after posting this q I solved it. The problem was <buffer>
in the mapping.
Removing it made the mapping work, thus:
nnoremap E w:
<CR>
:!python % <CR>
精彩评论