Sunday, October 23, 2016

Re: Load one key- map

On Mon, Oct 24, 2016 at 1:50 AM, Nikolay Aleksandrovich Pavlov
<zyx.vim@gmail.com> wrote:
> 2016-10-24 2:03 GMT+03:00 Tony Mechelynck <antoine.mechelynck@gmail.com>:
>> On Mon, Oct 24, 2016 at 12:15 AM, Guido Milanese
>> <guido.milanese@gmail.com> wrote:
>>> Dear all,
>>> I'm probably making a mountain out of a molehill, but I'm lost in a (probably) very simple problem.
>>>
>>> I have written a simple bash script that performs some transformations in a file, calls (g)vim, waits for the user to edit the file, and exits. The problem is:
>>>
>>> * I have defined one simple key map of the kind
>>>
>>> map <F11> do-this-and-this
>>>
>>> * I would like to save this mapping to a file, in order to add this particular key-map to other mapping(s) defined by users; I would like to load the mapping from an external file, in order for this mapping to be unloaded after the current session. Such as:
>>>
>>> (g)vim FILE-WITH-MAPPING FILE-TO-WORK
>>>
>>> I tried to use *mkexrc* but I did not obtain what I want, i.e. to save in a file *only* the particular mapping I need for this particular script.
>>>
>>> Could you please help me?
>>>
>>> Thank you!
>>> guido (Italy)
>>
>> Well, you could write your mapping to a file, and source that file
>> when needed; but unless it is a rather complex "do this and that" it
>> might be simpler to simply type the :map command at the command line,
>> or as argument to the -c command-line switch.
>>
>> For a complex mappinf (written to ./mymapping.vim)
>>
>> (g)vim -c "source ./mymapping.vim"
>>
>> would, I suppose, do the trick. (Vim accepts forward slashes as path
>> separators on all platforms including Windows, or backslashes on
>> Windows only.)
>
> vim -S ./mymapping.vim
>
> is a shortcut to `-c 'so ./mymapping.vim'`. Note: implementation used
> so far *literally* joins `so<space>` and a file name, saving this in a
> location where `-c` commads are saved, so `vim -S './$FOO'` is not
> going to open file `./$FOO` like you probably expected. You need to
> know this in case you happen to know your file name contains special
> characters (e.g. space), or in case you don't know which characters
> your temporary file name can contain in advance, so the safest way
> which does not require you messing with escaping should be something
> like
>
> _MYMAPPING=./mymapping.vim vim -c 'source $_MYMAPPING'
>

... which unless things have changed a lot since I left Windows, would
work on Mac, Linux or Unix, or even in Cygwin bash, but not in
"vanilla" Windows and not in CMD.EXE.

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: