==============================================================================
*05.3* Simple mappings
A mapping enables you to bind a set of Vim commands to a single key. Suppose,
for example, that you need to surround certain words with curly braces. In
other words, you need to change a word such as "amount" into "{amount}". With
the :map command, you can tell Vim that the F5 key does this job. The command
is as follows: >
:map <F5> i{<Esc>ea}<Esc>
<
Note:
When entering this command, you must enter <F5> by typing four
characters. Similarly, <Esc> is not entered by pressing the <Esc>
key, but by typing five characters. Watch out for this difference
when reading the manual!
Let's break this down:
<F5> The F5 function key. This is the trigger key that causes the
command to be executed as the key is pressed.
i{<Esc> Insert the { character. The <Esc> key ends Insert mode.
e Move to the end of the word.
a}<Esc> Append the } to the word.
After you execute the ":map" command, all you have to do to put {} around a
word is to put the cursor on the first character and press F5.
In this example, the trigger is a single key; it can be any string. But when
you use an existing Vim command, that command will no longer be available.
You better avoid that.
One key that can be used with mappings is the backslash. Since you
probably want to define more than one mapping, add another character. You
could map "\p" to add parentheses around a word, and "\c" to add curly braces,
for example: >
:map \p i(<Esc>ea)<Esc>
:map \c i{<Esc>ea}<Esc>
You need to type the \ and the p quickly after another, so that Vim knows they
belong together.
The ":map" command (with no arguments) lists your current mappings. At
least the ones for Normal mode. More about mappings in section |40.1|.
==============================================================================
*05.4* Adding a package *add-package*
You may use |:packadd| to enable packages on demand. This is useful for plugins
you want to enable only sometimes. To enable `example_package`, use the
following command: >
packadd example_package
That's all! Now you can find help about this plugin: >
:help example_package
This works, because when `:packadd` loaded the plugin it also added the
package directory in 'runtimepath', so that the help file can be found.
A package is a set of files that you can add to Vim. There are two kinds of
packages: optional and automatically loaded on startup.
You can find packages on the Internet in various places. It usually comes as
an archive or as a repository. For an archive you can follow these steps:
1. create the package directory: >
mkdir -p ~/.local/share/nvim/site/pack/fancy
< "fancy" can be any name of your liking. Use one that describes the
package.
2. unpack the archive in that directory. This assumes the top
directory in the archive is "start": >
cd ~/.local/share/nvim/site/pack/fancy
unzip /tmp/fancy.zip
< If the archive layout is different make sure that you end up with a
path like this:
~/.local/share/nvim/site/pack/fancy/start/fancytext/plugin/fancy.vim ~
Here "fancytext" is the name of the package, it can be anything
else.
Adding nohlsearch package *nohlsearch-install* *package-nohlsearch*
Load the plugin with this command: >
packadd nohlsearch
<
Automatically execute |:nohlsearch| after 'updatetime' or getting into
|Insert| mode.
Thus assuming default updatetime, hlsearch would be suspended/turned off after
4 seconds of idle time.
To disable the effect of the plugin after it has been loaded: >
au! nohlsearch
<
More information about packages can be found here: |packages|.
==============================================================================
*05.5* Adding a plugin *add-plugin* *plugin*
Vim's functionality can be extended by adding plugins. A plugin is nothing
more than a Vim script file that is loaded automatically when