On Sat, Dec 30, 2017 at 3:59 PM, Guido Milanese
<guido.milanese@gmail.com> wrote:
> 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
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.
--
--
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:
Post a Comment