简体   繁体   English

如何将非ASCII密钥与utf-8编码的.vimrc绑定?

[英]How can I bind non-ascii keys with a utf-8-encoded .vimrc?

The problem 问题

I have a Scandinavian keyboard, and I want to bind my Æ , Ø and Å keys . 我有一个斯堪的纳维亚键盘,我想绑定我的ÆØÅ For example, I use Ø as leader : 例如, 我将Ø用作领导者

" ok, works:
let mapleader = "ø"

When the .vimrc is encoded in latin1 , this works like a charm. .vimrclatin1编码时,这就像一个latin1 However, I want to use :set enc=utf8 in my .vimrc , and then the mappings stop working: 但是,我想在.vimrc使用:set enc=utf8 ,然后映射停止工作:

" whoops, doesn't work:
let mapleader = "ø"
set encoding=utf-8

I presume this is because the .vimrc is written as utf-8, and that Vim is unable to parse or map the multi-byte characters. 认为这是因为.vimrc是用utf-8编写的,并且Vim无法解析或映射多字节字符。

What I want is to be able to use my non-ascii keymappings while still defaulting to utf-8 for all files other than .vimrc . 我想要的是能够使用我的非ascii键盘映射,同时仍然对.vimrc以外的所有其他文件默认使用utf-8。 (Storing .vimrc as latin1 would be an acceptable solution, but I haven't figured out a way to do it.) (将.vimrc存储为latin1是可以接受的解决方案,但我还没有找到一种方法来实现。)

Approaches that don't work 无效的方法

I have tried all kinds of things, and none of the following work: 我已经尝试过各种方法,但没有以下工作:

  • Modelines that set encoding and/or fileencoding for .vimrc . 模式行该设置encoding和/或fileencoding.vimrc
  • Mapping the keys to "\ø" and similar values instead. 将键映射到"\ø"和类似的值。
  • Putting non-valid utf-8 sequences in .vimrc to force defaulting to latin1 . 将无效的utf-8序列放入.vimrc以强制默认为latin1
  • Various autocommands to set encoding and/or fileencoding for .vimrc . 各种自动命令来设置encoding和/或fileencoding.vimrc
  • Opening Vim with --cmd "set encoding=latin1" , because I edit my .vimrc too frequently for that to be feasible. --cmd "set encoding=latin1"打开Vim,因为我编辑.vimrc太频繁了,以至于不可行。

How can I use both set encoding=utf-8 and map my non-ascii keys? 如何同时使用 set encoding=utf-8 映射我的非ascii键?

The problem is caused by the ultisnips plugin. 该问题是由ultisnips插件引起的。 Disabling ultisnips will resolve the issue. 禁用ultisnips将解决此问题。

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

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