简体   繁体   中英

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 enter it into the command line in Vim. This is the mapping:
map <buffer> <Se> :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 <St> 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:

  1. Never use map where can use noremap instead.
  2. You probably don't want this mapping to be defined for visual (at least without <Cu> before w ) and select modes, and definitely don't want it to be defined for operator-pending modes, so use nnoremap .
  3. <Se> and E are equivalent.
  4. You can combine w and !... in one command using pipe symbol: :w | !/usr/bin/env python %<CR> :w | !/usr/bin/env python %<CR> .
  5. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM