简体   繁体   English

vimrc映射问题; 执行python脚本映射无法从vimrc工作

[英]vimrc mapping problem; execute python script mapping not working from vimrc

grr. GRR。 I'm struggling with Vim's learning curve. 我正在努力学习Vim的学习曲线。
And trying to get a simple mapping in my vimrc to execute the current buffer's python script. 并尝试在我的vimrc中获取一个简单的映射来执行当前缓冲区的python脚本。 The mapping is well-formed and works after I enter it into the command line in Vim. 映射格式正确,并在我将其输入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: 但它不会从我的vimrc加载:(我使用的是基本的.vimrc_sample,只附加了这个映射。有什么奇怪的是我可以从vimrc获得不同的映射:
map <St> itest <Esc>
This one works, but not the script executer? 这个可行,但不是脚本执行者吗? What gives? 是什么赋予了?
Ubuntu 10.10 Python 2.6 Vim 7.2 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. 我怀疑你在map之前有一些东西: <buffer>参数意味着只为当前缓冲区定义了映射,所以在没有类似autocmd FileType python类的东西之前将它添加到vimrc是很奇怪的。 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. 切勿使用可以使用noremap map
  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 . 您可能不希望为视觉定义此映射(至少在w之前没有<Cu> )和选择模式,并且绝对不希望为操作员挂起模式定义它,因此请使用nnoremap
  3. <Se> and E are equivalent. <Se>E是等价的。
  4. You can combine w and !... in one command using pipe symbol: :w | !/usr/bin/env python %<CR> 您可以使用管道符号:w | !/usr/bin/env python %<CR>在一个命令中组合w!... :w | !/usr/bin/env python %<CR> . :w | !/usr/bin/env python %<CR>
  5. You forgot slash before usr . 你在usr之前忘记了斜线。

Jesus, Murphy's Law. 耶稣,墨菲定律。
After searching for an answer for an hour, 1 min after posting this q I solved it. 在搜索了一个小时的答案后,发布此q后1分钟我解决了它。 The problem was <buffer> in the mapping. 问题是映射中的<buffer>
Removing it made the mapping work, thus: 删除它使映射工作,因此:
nnoremap E w: <CR> :!python % <CR>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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