5

I have mapped [] and {} on my German keyboard with:

nmap Ö {
nmap Ä }
nmap ö [
nmap ä ]

but if I try, for example, to delete inside {} with di} it won't delete. It also fails with f and t (for example, f} and t}).

Can someone tell me if there is an additional map command for such operations?

  • 1
    Very closely related: Can't map German 'umlaut' keys in .vimrc. Perhaps not entirely a duplicate though, since that question deals with <C-ö> mappings, and this is without the Control key... – Martin Tournoij Mar 9 '16 at 21:57
  • @Carpetsmoker This is actually a different issue and has to do with the relationship between keystrokes and characters sent to the terminal. – Philipp Moers Mar 10 '16 at 0:41
  • @PhilippMoers Okay, thanks ;-) I thought it was the same problem at first, but then I wasn't sure, and didn't have time to look into it. – Martin Tournoij Mar 10 '16 at 0:43
  • I think it's obvious that f{ won't work by just mapping stuff - doesn't f want the actual character it sees in the searched text? You will probably have to map to f] and so on, to get that type of functionality. At this point, I'd solve the problem at OS level, by adding a US layout and switch (maybe automatically) between DE and US as need arises. OTOH, it's entirely possible I'm missing something with Vim (this always happens) :) – VanLaser Mar 10 '16 at 11:28
  • Actually, since you seem to want to edit source code, I'd say switch to US layout and create Vim inoremaps such as inoremap aa ä and so on, to insert your specific characters. – VanLaser Mar 10 '16 at 12:12
4

As Philipp has pointed out in his previous answer, :lmap can be used to get f and the likes to work with your mappings. However, this will most likely not work out of the box for you since the 'iminsert' option needs to be set to 1 while the default is 0 or 2. Unfortunately, this will result in the mapping being applied in every mode, e.g. typing Ö in insert mode will result in a { being inserted in the text.

To prevent this, you need to disable :lmap mappings in insert mode. This can be done in two ways:

  • typing <C-^> to toggle between disabling an enabling :lmap mappings. This solution has the additional drawback (aside from being rather tedious) that this key combination might not work on your keyboard (it didn't work on my german one). Remapping other keys to this combination solves the issue, though.
  • using auto commands to always disable them in insert mode using the InsertEnter and InsertLeave events. In your case, the solution might look like this, using 'lmap' to make things work in cases like diÖ:

    autocmd InsertEnter * set iminsert=2
    autocmd InsertLeave * set iminsert=1
    lmap Ö {
    lmap Ä }
    lmap ö [
    lmap ä ]
    set lmap=Ö{Ä}ö[ä]
    
  • 'iminsert' was the missing thing to get this config much easier. And I want this in insertmode too, because I write at hte moment LaTex documents in english, so no need for the umlauts. I adset the ü key and mapped it to \ for the LaTeX too. Thanks @ingo for pointing me to a better solution. `set iminsert=1 imap \ \ lmap { { lmap } } lmap \ \ lmap [ [ lmap ] ] lmap \ : set lmap={{,}},[[,]],\\\,\: autocmd InsertEnter * imap \ \ autocmd InsertLeave * imap \ : map! { { map! } } map! [ [ map! ] ] map! \ : map! \ \ noremap! Ö { noremap! Ä } noremap! ö [ noremap! ä ] noremap! ü \ noremap! Ü ` – ffabi Mar 22 '16 at 11:04
  • Sorry I don't got the formatting right in the comment! – ffabi Mar 22 '16 at 11:05
5

I think you will be glad to have a look at :help omap-info. You can specify mappings for exactly this case, when a text object or movement is expected.

Since you want text-objects, rather than movements, i guess you have to use these:

onoremap iö i[
vnoremap iö i[
onoremap aö a[
vnoremap aö a[

onoremap iä i[
vnoremap iä i[
onoremap aä a[
vnoremap aä a[

onoremap iÖ i{
vnoremap iÖ i{
onoremap aÖ a{
vnoremap aÖ a{

onoremap iÄ i{
vnoremap iÄ i{
onoremap aÄ a{
vnoremap aÄ a{

As @VanLaser pointed out, the f and t take commands take characters, not movements or text objects. I just learned about :lmap and language-mapping myself, but could not get it to work. A brainless workaround would be this:

nnoremap tö t[
nnoremap fö f[
nnoremap tä t]
nnoremap fä f]

nnoremap Tö T[
nnoremap Fö F[
nnoremap Tä T]
nnoremap Fä F]

nnoremap tÖ t{
nnoremap fÖ f{
nnoremap tÄ t}
nnoremap fÄ f}

nnoremap TÖ T{
nnoremap FÖ F{
nnoremap TÄ T}
nnoremap FÄ F}
  • Thanks for answering I looked in the help and omap seem to bee the right option. But it don’t work for me. I testet it in with vim started with the -u NONE option to see that its not a Problem of my .vimrc or a Plugin. I used the command :onoremap ä ] and to see if its a Problem with the umlaut key :onoremap z ] but it didn’t work. I fond lmap in the heat and with :set lmap=ä] It work for things like di but not for the f and t with this the keys are treated as there originals. But the help says „|:lmap| mappings apply to {char}“ Any Ideas how I can get it work for this keys too. – ffabi Mar 10 '16 at 7:05
  • I will let you know when I get lmap to work for the f command eventually. – Philipp Moers Mar 13 '16 at 0:09
  • Anyway, you may be interested in this handy plugin that allows you to specify a kind of wildcard character to match any special sign like braces or parens. – Philipp Moers Mar 13 '16 at 0:11
  • Adding the remapping the combined versions like 'nnoremap tö t]' is the best solution for me, Thanks. – ffabi Mar 14 '16 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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