Saving key mappings

32 views
Skip to first unread message

Guido Milanese

unread,
Dec 30, 2017, 9:59:35 AM12/30/17
to vim_use
I know that macros and mappings are one of the most frequently discussed topics, so I do apologise if it is a question posed (n = n + 1) times.
I have written a program that, obviously among other tasks, calls (g)vim and opens a given file. I would like to instruct my program to call (g)vim with a given set of key mappings (the ones saved with 'q', as '@a', for example). Would this be possible?
Example: '@c' write '[', pasts the content of system clipboard using "*p and closes ']'.
I know that I can write all :map and :set settings using :mk. I see two options:
* if I cannot save key mappings, I could map the functions to a key, save them to a file: how can I read from this file?
* could marvim be a good solution? In order to publish my program, I would not like to use functions not provided by standard gvim.

The ideal would be something like:

gvim -u file-with-keypmapping textfile

but this would probably ignore the vimrc of the user!


Thank you!
guido, from Northern Italy

Tony Mechelynck

unread,
Dec 30, 2017, 10:48:30 AM12/30/17
to vim...@googlegroups.com
There are several possibilities, but first, how do I save macros
created by q + letter? Answer: They are in the register by that
letter. If your 'viminfo' setting is non-empty, these registers are
saved when Vim exits and restored at next startup. By default, up to
50 lines are saved for all registers, but you can increase or decrease
that number of lines to anything between zero and infinity.
see
:help viminfo-<
:help :registers

Mappings can be saved in a Vim script:
• Any mappings which you always want available should be defined in your vimrc.
see :help vimrc
• Mappings which you want defined only for files of a certain filetype
should be defined in a filetype-plugin for that filetype: for
instance, if you want certain mappings to be defined when you edit
html sources, you should define them with the <buffer> modifier in a
script named (on Windows) %HOME%\vimfiles\after\ftplugin\html.vim or
(on Unix-like systems, including Mac OS X IIUC)
~/.vim/after/ftplugin/html.vim — the "after" subdirectory serves to
define them "after" anything defined by the filetype-plugins
distributed with Vim, so the latter won't override your own mappings
see
:help :map-<buffer>
:help after-directory
:help ftplugin
• Mappings which you want defined only on demand can be defined in a
script placed anywhere Vim normally *won't* look for it. For instance
in .../macros/... instead of .../after/ftplugin/... Then you enable it
by reading that script with a :source statement. Use <buffer> or not
in the :map (or :map!, :imap, nnoremap, etc.) statement, depending on
whether you want these macros to be buffer-local or global.
see :help :source

Similarly, user-defined functions and commands can also be defined in
the same kinds of Vim scripts (including, for those you always want
available, in your vimrc)
see
:help :function
and in particular :help E124
:help :command
and in particular :help E174

To source a certain script at startup *in addition* to your vimrc, use
a -S {filename} argument on your Vim command-line. (If the script is
named Session.vim in the current directory, then its name can be
omitted provided that -S comes last on the command-line.)
see :help -S


Best regards,
Tony.

Bailey Stoner

unread,
Dec 31, 2017, 5:10:21 AM12/31/17
to vim...@googlegroups.com
Hi Guido,

Apologies if this is tagnential or not helpful, but some more details of the specific use-case could be helpful! Is it something that you may be able to do with a filetype plugin or similar? If not, is it possible that you could install a plugin which needs manually called to be activated? That way, you could do something similar to `gvim '+MyPluginFunction' to execute MyPluginFunction when it loads.

I think that there are a number of ways to do this, and it's hard to know what the right way is without more details. I get the sense that what you're doing may be accomplished with a tiletype plugin, though!

Hopefully this is helpful,
Bailey


 30. Dec 2017 06:59 by guido.m...@gmail.com:

--
--
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Guido Milanese

unread,
Jan 2, 2018, 5:58:19 PM1/2/18
to vim_use digest subscribers
Many thanks indeed. I think that a plugin could not work in my case: it's a single program, not a filetype. Probably saving a series of maps and "-S" (source) the file (as explained in Tony Mechelynck's message) could be the best approach. I'll let you know, and thanks again!

guido (an Italian classicist with an insane love for programming...)

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.

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/hm6L5hfU3UA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Guido Milanese - Professor of Classics - Docteur H.C. Paris ICP
Universita' Cattolica d.S.C., Milano - Brescia
http://docenti.unicatt.it/ita/guido_fabrizio_milanese

731943170

unread,
Jan 2, 2018, 7:21:21 PM1/2/18
to guido.m...@gmail.com, vim...@googlegroups.com
Is there the Python Guido??!!!



发自我的小米手机
在 Guido Milanese <guido.m...@gmail.com>,2018年1月3日 上午6:58写道:
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/hm6L5hfU3UA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Guido Milanese - Professor of Classics - Docteur H.C. Paris ICP
Universita' Cattolica d.S.C., Milano - Brescia
http://docenti.unicatt.it/ita/guido_fabrizio_milanese

--
--
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+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages