imap key

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

imap key

Jorge Almeida
I'm having a _really frustating_ problem with the » key I use for maps.
(In my keyboard, this key is at a handy location, and is useless for
other purposes.)

:imap »a alpha

The 'alpha' string is here only as an illustration, of course.
Now, if the above mapping is in the file ~/.vim/ftplugin/tex/geral.vim,
it works, i.e., when I press »a in insert mode on a file a.tex I get the
string alpha.
The same mapping in the file ~/.vim/ftplugin/C/geral.vim doesn't work
(on a file a.c), i.e. I only get the string »a.
The file ~/.vim/ftplugin/C/geral.vim is being sourced, because other
mappings (without ») work. Moreover, substituting » by, say, x, yields a
working mapping!

So, what could be happening here?
--
Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Yakov Lerner
Jorge Almeida wrote:
> I'm having a _really frustating_ problem with the » key I use for maps...
>    :imap »a alpha
> ... The same mapping in the file ~/.vim/ftplugin/C/geral.vim doesn't work
> (on a file a.c), i.e. I only get the string »a. ...
> So, what could be happening here?

Jorge, and what happens if you put this imap into your ~/.vimrc ?

Yakov
--
 
  [hidden email]

--
http://www.fastmail.fm - The professional email service

Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
On Wed, 1 Feb 2006, [hidden email] wrote:

> Jorge Almeida wrote:
>> I'm having a _really frustating_ problem with the » key I use for maps...
>>    :imap »a alpha
>> ... The same mapping in the file ~/.vim/ftplugin/C/geral.vim doesn't work
>> (on a file a.c), i.e. I only get the string »a. ...
>> So, what could be happening here?
>
> Jorge, and what happens if you put this imap into your ~/.vimrc ?
>
It works. But it does not solve my problem, as I need mappings depending
on filetypes.

Jorge
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Charles E Campbell Jr
In reply to this post by Jorge Almeida
Jorge Almeida wrote:

> The same mapping in the file ~/.vim/ftplugin/C/geral.vim doesn't work
> (on a file a.c), i.e. I only get the string »a.
> The file ~/.vim/ftplugin/C/geral.vim is being sourced, because other
> mappings (without ») work. Moreover, substituting » by, say, x, yields a
> working mapping!


Hello!

What I find strange is that "other mappings work" -- because, for the C
language, the directory should be

    ~/.vim/ftplugin/c/geral.vim

and if you happened to be using c++ you'd want

    ~/.vim/ftplugin/cpp/geral.vim

Please check again that that file is being sourced.  May I suggest putting

:echomsg "Yep, its me!"

or something similar in that file.  Then, after editing a *.c file, type

:messages

to see if the "Yep, its me!" shows up.

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
On Wed, 1 Feb 2006, Charles E. Campbell, Jr. wrote:

>
> What I find strange is that "other mappings work" -- because, for the C
> language, the directory should be
>
>   ~/.vim/ftplugin/c/geral.vim
Since I didn't know whether the correct name is 'c' or 'C', I made one of the
directories and the other is a symlink to the former.

>
> Please check again that that file is being sourced.  May I suggest putting
>
> : echomsg "Yep, its me!"
>
> or something similar in that file.  Then, after editing a *.c file, type
>
> : messages
>
> to see if the "Yep, its me!" shows up.
>
Yep, it does.
> Regards,
> Chip Campbell
>
Thanks,

Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

RE: imap key

Halim, Salman
In reply to this post by Jorge Almeida
Initially, I thought that the ftplugin/C directory wasn't read at all
because the filetype might actually be 'c' (lower-case) and this seems
to be a Unix machine.  But the indication is that the file does seem to
be read.

> -----Original Message-----
> From: Charles E. Campbell, Jr. [mailto:[hidden email]]
> Sent: Wednesday, February 01, 2006 4:13 PM
> To: Jorge Almeida
> Cc: [hidden email]
> Subject: Re: imap key
>
> Jorge Almeida wrote:
>
> > The same mapping in the file ~/.vim/ftplugin/C/geral.vim
> doesn't work
> > (on a file a.c), i.e. I only get the string >a.
> > The file ~/.vim/ftplugin/C/geral.vim is being sourced,
> because other
> > mappings (without >) work. Moreover, substituting > by,
> say, x, yields
> > a working mapping!
>
>
> Hello!
>
> What I find strange is that "other mappings work" -- because,
> for the C language, the directory should be
>
>     ~/.vim/ftplugin/c/geral.vim
>
> and if you happened to be using c++ you'd want
>
>     ~/.vim/ftplugin/cpp/geral.vim
>
> Please check again that that file is being sourced.  May I
> suggest putting
>
> :echomsg "Yep, its me!"
>
> or something similar in that file.  Then, after editing a *.c
> file, type
>
> :messages
>
> to see if the "Yep, its me!" shows up.
>
> Regards,
> Chip Campbell
>
>
Reply | Threaded
Open this post in threaded view
|

RE: imap key

Jorge Almeida
On Wed, 1 Feb 2006, Halim, Salman wrote:

> Initially, I thought that the ftplugin/C directory wasn't read at all
> because the filetype might actually be 'c' (lower-case) and this seems
> to be a Unix machine.  But the indication is that the file does seem to
> be read.
>
Sorry about the entropy. I have 'c' and 'C'. One is a symlink to the
other. The machine does run linux.
--
Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Charles E Campbell Jr
In reply to this post by Jorge Almeida
Jorge Almeida wrote:

> I'm having a _really frustating_ problem with the » key I use for maps.

OK, time for the next stab in the dark.  Please try the following:

vim .vimrc
:echo "encoding=".&encoding." termencoding=".&termencoding." fencs=".&fencs
:q

and then try

vim ~/.vim/ftplugin/c/geral.vim
:echo "encoding=".&encoding." termencoding=".&termencoding." fencs=".&fencs
:q

Are these encodings the congruent?

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
On Wed, 1 Feb 2006, Charles E. Campbell, Jr. wrote:

> Jorge Almeida wrote:
>
>>  I'm having a _really frustating_ problem with the » key I use for maps.
>
> OK, time for the next stab in the dark.  Please try the following:
>
> vim .vimrc
> : echo "encoding=".&encoding." termencoding=".&termencoding." fencs=".&fencs
encoding=latin1 termencoding= fencs=ucs-bom,utf-8,default
> : q
>
> and then try
>
> vim ~/.vim/ftplugin/c/geral.vim
> : echo "encoding=".&encoding." termencoding=".&termencoding." fencs=".&fencs
encoding=latin1 termencoding= fencs=ucs-bom,utf-8,default
> : q
>
> Are these encodings the congruent?
>
Just in case, this is my ~/.vim/ftplugin/c/geral.vim:
  :set tabstop=4
  :vmap <C-X><C-D> :s/^/\/\//<CR>
  :vmap <C-X><C-U> :s/^\(\s*\)\(\/\/\)/\1<CR>
  :nmap <C-X><C-D> V:s/^/\/\//<CR>
  :nmap <C-X><C-U> V::s/^\(\s*\)\(\/\/\)/\1<CR>
  " anular »
  :imap »<Esc> <Esc>a
  " excesso de »'s, ou » literal...
  :imap »»» »
  " jump to ...
  :imap <C-J><C-J> <Esc>/®/e<CR>a<BS>
  :imap »/ <Esc>/®/e<CR>a<BS>
  :imap ».  <Esc>/®/e<CR>a<BS>
  :nmap ».  <Esc>/®/e<CR>a<BS>
  "parenteses....
  :imap »8 ()®<ESC>hi
  :imap »9 []®<ESC>hi
  :imap »0 {}®<ESC>hi
  :imap »\ {<ESC>o}<ESC>k$a
  :imap »; ""®<ESC>hi
  "abreviaturas
  :imap »a alfa

--
Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Charles E Campbell Jr
Jorge Almeida wrote:

> Just in case, this is my ~/.vim/ftplugin/c/geral.vim:
>     :set tabstop=4
>     :vmap <C-X><C-D> :s/^/\/\//<CR>
>     :vmap <C-X><C-U> :s/^\(\s*\)\(\/\/\)/\1<CR>
>     :nmap <C-X><C-D> V:s/^/\/\//<CR>
>     :nmap <C-X><C-U> V::s/^\(\s*\)\(\/\/\)/\1<CR>
>     " anular »
>     :imap »<Esc> <Esc>a
>     " excesso de »'s, ou » literal...
>     :imap »»» »
>     " jump to ...
>     :imap <C-J><C-J> <Esc>/®/e<CR>a<BS>
>     :imap »/ <Esc>/®/e<CR>a<BS>
>     :imap ».  <Esc>/®/e<CR>a<BS>
>     :nmap ».  <Esc>/®/e<CR>a<BS>
>     "parenteses....
>     :imap »8 ()®<ESC>hi
>     :imap »9 []®<ESC>hi
>     :imap »0 {}®<ESC>hi
>     :imap »\ {<ESC>o}<ESC>k$a
>     :imap »; ""®<ESC>hi
>     "abreviaturas
>     :imap »a alfa
>
Looks like your encodings are the same, so that's ok.  The <esc>s in the
left-hand-side of your
maps kind of worries me.  Please try commenting out all but the last
line (with imap...alfa).
Does it work yet?  I don't have a » key to try this out (and actually
I'll be gone for awhile so
you get a breather from my pestering you).

If it happens to work, then try uncommenting lines until it stops working.

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
On Wed, 1 Feb 2006, Charles E. Campbell, Jr. wrote:

>>
> Looks like your encodings are the same, so that's ok.  The <esc>s in the
> left-hand-side of your
> maps kind of worries me.  Please try commenting out all but the last line
> (with imap...alfa).
Did that. It still doesn't work.
> Does it work yet?  I don't have a » key to try this out (and actually I'll be
> gone for awhile so
> you get a breather from my pestering you).
>
Thanks for trying.

Regards,

Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Luc Hermitte
In reply to this post by Jorge Almeida
Hello,

* On Wed, Feb 01, 2006 at 09:56:35PM +0000, Jorge Almeida <[hidden email]> wrote:
> Just in case, this is my ~/.vim/ftplugin/c/geral.vim:
> :set tabstop=4
> :vmap <C-X><C-D> :s/^/\/\//<CR>
> [...]
> "abreviaturas
> :imap »a alfa

Just a few suggestions -- they may not solve anything you can see, yet.

-> %s:/\([ivn]\)map/\1noremap/
   To avoid recursive mappings
-> :h :map-<buffer>
   Because you are defining ftplugins. You do not want your mapping to
   pollute your other filetypes.
-> :h :setlocal
   Same reason.

Having global and recursive mappings defined in several places may be a
very good explanation to misbehaviors. But, I do not see any direct
link to what you experience.

What is echoed when you type from the command line:
   :imap »a
?
You should read exactly one response. Are there others ? None ?


HTH,

BTW, the filetype for C++ is 'cpp'

--
Luc Hermitte
http://hermitte.free.fr/vim/c.php
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Benji Fisher
In reply to this post by Charles E Campbell Jr
On Wed, Feb 01, 2006 at 04:53:12PM -0500, Charles E. Campbell, Jr. wrote:

> Jorge Almeida wrote:
>
> >I'm having a _really frustating_ problem with the » key I use for maps.
>
> OK, time for the next stab in the dark.  Please try the following:
>
> vim .vimrc
> :echo "encoding=".&encoding." termencoding=".&termencoding." fencs=".&fencs
> :q
>
> and then try
>
> vim ~/.vim/ftplugin/c/geral.vim
> :echo "encoding=".&encoding." termencoding=".&termencoding." fencs=".&fencs
> :q
>
> Are these encodings the congruent?

     I think this is the right line of questioning, but I wonder why you
did not suggest the simpler

:e ~/.vimrc
:redir @a
:verbose set enc? tenc? fenc?
:e ~/,vim/ftplugin/c/geral.vim
:verbose set enc? tenc? fenc?
:redir END
:e mail.txt
:put a

Now that I look more closely, I think you meant to write "fenc" (no "s")
instead of "fencs".  That is the most likely culprit, so let's try again!

     Another possibility:  does either file contain a :scriptencoding
command?  (Minimal form is :scripte .)

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
In reply to this post by Luc Hermitte
On Thu, 2 Feb 2006, Luc Hermitte wrote:

>
> Just a few suggestions -- they may not solve anything you can see, yet.
>
> -> %s:/\([ivn]\)map/\1noremap/
>   To avoid recursive mappings
OK (But there are no recursive mappings.)
And what would happen if a mapping ":imap ..." is sourced _first_ and
a conflicting mapping ":inoremap ..." is sourced later?
> -> :h :map-<buffer>
>   Because you are defining ftplugins. You do not want your mapping to
>   pollute your other filetypes.
> -> :h :setlocal
>   Same reason.
I don't understand. A file in ~/.vim.ftplugin/c/ would be sourced only
when editing a *.c file (right?). How could pollution arise?
>
> Having global and recursive mappings defined in several places may be a
> very good explanation to misbehaviors. But, I do not see any direct
> link to what you experience.
Aren't the files in ~/.vim.ftplugin/c/ sourced _after_ ~/.vimrc? And a
mapping in the former would not override a mapping in the latter?
>
> What is echoed when you type from the command line:
>   :imap »a
> ?
"No mapping found"


I noticed also the following behaviour:
In ~/.vim/ftplugin/c/geral.vim I have the mappings

1) :imap <C-J><C-J> <Esc>/®/e<CR>a<BS>
2) :imap »8 ()®<ESC>hi
3) :imap »a alfa

Now, 3) doesn't work. But 2) does work! And 1) doesn't work, echoing the
message:
E486: Pattern not found: ®


All this happens only with c files. All mappings work perfectly with tex
files.

Thanks,

Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
In reply to this post by Benji Fisher
On Wed, 1 Feb 2006, Benji Fisher wrote:

> On Wed, Feb 01, 2006 at 04:53:12PM -0500, Charles E. Campbell, Jr. wrote:
>> Are these encodings the congruent?
>
>     I think this is the right line of questioning, but I wonder why you
> did not suggest the simpler
>
> :e ~/.vimrc
> :redir @a
> :verbose set enc? tenc? fenc?
   encoding=latin1
   termencoding=
   fileencoding=

> :e ~/,vim/ftplugin/c/geral.vim
> :verbose set enc? tenc? fenc?
   encoding=latin1
   termencoding=
   fileencoding=utf-8

> :redir END
> :e mail.txt
> :put a
>
> Now that I look more closely, I think you meant to write "fenc" (no "s")
> instead of "fencs".  That is the most likely culprit, so let's try again!
>
OK:

  vim .vimrc
  :echo "encoding=".&encoding." termencoding=".&termencoding." fenc=".&fenc
  encoding=latin1 termencoding= fenc=

  vim ~/.vim/ftplugin/c/geral.vim
  :echo "encoding=".&encoding." termencoding=".&termencoding." fenc=".&fenc
  encoding=latin1 termencoding= fenc=utf-8

>     Another possibility:  does either file contain a :scriptencoding
> command?  (Minimal form is :scripte .)
No.

Thanks,

Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Yakov Lerner
In reply to this post by Jorge Almeida
"Jorge Almeida" <[hidden email]>:
> > What is echoed when you type from the command line:
> >   :imap »a
> > ?
> "No mapping found"

This "No mapping found" probably means that you'll want to find
which line in which script scauses removal of the mapping in question.
What if you add the following commands into script that
has ':imap »a alpha' right after this imap:

     :imap »a alpha
     " first, we want to check that mapping exists at the point of
     creation
     :imap »a
     :call input("did you see the mapping? ")
     " increase verbosity to the max
     :set verbose=20

If you're lucky, you'll spot iunmap :-) At any rate, you'll which
scripts are sourced.
Ideally, you'll want to insert commands
     :imap »a
     :call input("did you see the mapping? ")
after each line, but failing that, you could insert these into
various points of the scripts that are executed after geral.vim, and
then
dichotomy is your friend to find which line causes disappearance of the
mapping.

Yakov
--
 
  [hidden email]

--
http://www.fastmail.fm - One of many happy users:
  http://www.fastmail.fm/docs/quotes.html

Reply | Threaded
Open this post in threaded view
|

Re: imap key

A.J.Mechelynck
In reply to this post by Jorge Almeida
Jorge Almeida wrote:

> On Thu, 2 Feb 2006, Luc Hermitte wrote:
>
>>
>> Just a few suggestions -- they may not solve anything you can see, yet.
>>
>> -> %s:/\([ivn]\)map/\1noremap/
>>   To avoid recursive mappings
> OK (But there are no recursive mappings.)
> And what would happen if a mapping ":imap ..." is sourced _first_ and
> a conflicting mapping ":inoremap ..." is sourced later?
>> -> :h :map-<buffer>
>>   Because you are defining ftplugins. You do not want your mapping to
>>   pollute your other filetypes.
>> -> :h :setlocal
>>   Same reason.
> I don't understand. A file in ~/.vim.ftplugin/c/ would be sourced only
> when editing a *.c file (right?). How could pollution arise?
[...]

You could have a file of a different type (for instance, a help file) in
another (split) window. Or you could edit a file needing none of these
mappings just afterwards (for instance, a text file). Now if you use
":set" and "map" (without <buffer>) rather than the recommended
":setlocal" and ":map <buffer>", your options and mappings are set
across the board for all present and future files until you unset them.
That's unhealthy for settings set by a filetype-plugin. Mappings and
abbreviations set in a filetype-plugin should always include the
<buffer> restriction, and option settings set in filetype-plugins should
always be set by ":setlocal" (and concern options which are local or
global-local).


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: imap key

Jorge Almeida
On Thu, 2 Feb 2006, A. J. Mechelynck wrote:

>> I don't understand. A file in ~/.vim.ftplugin/c/ would be sourced only
>> when editing a *.c file (right?). How could pollution arise?
> [...]
>
> You could have a file of a different type (for instance, a help file) in
> another (split) window. Or you could edit a file needing none of these
> mappings just afterwards (for instance, a text file). Now if you use
> ":set" and "map" (without <buffer>) rather than the recommended
> ":setlocal" and ":map <buffer>", your options and mappings are set
> across the board for all present and future files until you unset them.
> That's unhealthy for settings set by a filetype-plugin. Mappings and
> abbreviations set in a filetype-plugin should always include the
> <buffer> restriction, and option settings set in filetype-plugins should
> always be set by ":setlocal" (and concern options which are local or
> global-local).
>
OK, got it.

Thank you,

Jorge Almeida
Reply | Threaded
Open this post in threaded view
|

Re: imap key

Benji Fisher
In reply to this post by Jorge Almeida
On Thu, Feb 02, 2006 at 10:10:35AM +0000, Jorge Almeida wrote:

> On Wed, 1 Feb 2006, Benji Fisher wrote:
>
> >Now that I look more closely, I think you meant to write "fenc" (no "s")
> >instead of "fencs".  That is the most likely culprit, so let's try again!
> >
> OK:
>
> vim .vimrc
> :echo "encoding=".&encoding." termencoding=".&termencoding."
> fenc=".&fenc
> encoding=latin1 termencoding= fenc=
>
> vim ~/.vim/ftplugin/c/geral.vim
> :echo "encoding=".&encoding." termencoding=".&termencoding."
> fenc=".&fenc
> encoding=latin1 termencoding= fenc=utf-8

     Yes, I thought that was the problem.  Now the details have been
snipped; remind me what the files were where it worked and where it did
not work.  There was also a tex plugin involved, right?  What is the
value of 'fenc' for that one, and which were the files where it worked
and did not work?

> >    Another possibility:  does either file contain a :scriptencoding
> >command?  (Minimal form is :scripte .)
> No.

     I did not expect that to be the problem, but :scriptencoding is the
solution.  

     The reason the map sometimes works and sometimes does not is that
the character you are using is sometimes read as latin1 and sometimes as
utf-8.  One way to fix it is to add something like this to the file
where the map is not working:

" Make sure the character ?? is interpreted properly:
scriptencoding latin1
imap ??a ...
scriptencoding " Return to the default, just to be on the safe side.

I may have this backwards:  if that does not work, try
"scriptencoding utf-8" instead of "scriptencoding latin1".

     There is an entirely different solution.  If you think that the
future is utf-8 and not latin1, add

set enc=utf-8

to your vimrc file.  (I think that the future *is* utf-8, but I defer to
others on this list on such points.)  This may fix the problem all by
itself, or it may break the mapping that currently works, or it may
switch which one works and which does not.  If you want to try this, do
it first; then fix remaining problems by adding :scriptencoding lines to
the appropriate files.

:help 'encoding'
:help 'fenc'

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

RE: imap key

Zdenek Sekera
In reply to this post by Jorge Almeida
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> Sent: 02 February 2006 13:17
> To: Jorge Almeida; [hidden email]
> Subject: Re: imap key
>
> "Jorge Almeida" <[hidden email]>:
> > > What is echoed when you type from the command line:
> > >   :imap >a
> > > ?
> > "No mapping found"
>
> This "No mapping found" probably means that you'll want to find
> which line in which script scauses removal of the mapping in question.
> What if you add the following commands into script that
> has ':imap >a alpha' right after this imap:
>
>      :imap >a alpha
>      " first, we want to check that mapping exists at the point of
>      creation
>      :imap >a
>      :call input("did you see the mapping? ")
>      " increase verbosity to the max
>      :set verbose=20
>
> If you're lucky, you'll spot iunmap :-) At any rate, you'll which
> scripts are sourced.
> Ideally, you'll want to insert commands
>      :imap >a
>      :call input("did you see the mapping? ")
> after each line, but failing that, you could insert these into
> various points of the scripts that are executed after geral.vim, and
> then
> dichotomy is your friend to find which line causes
> disappearance of the
> mapping.

I am following this thread for a while trying to find out
what *was* a similar problem I had some time ago, unfortunately
I am not able to figure that out. All I remember was that
the problem disappeared when I started using latin1 (not utf-8)
exclusively (and that's what I am still using).
Actually, I had to go as fas as setting LANG=c in ~/.i18n,
because just :set enconding=latin1 wouldn't help.
I am on Linux, xterm, console vim.

---Zdenek
12