3

I wrote a custom software using its own configuration files under /etc. The software is built in a Debian package and delivered by a custom repository.

In order to provide a nice syntax highlighting in vim I wrote all the necessary files to nicely highlight my own config files. If I place them under ~/.vim/syntax and add a line to ~/.vim/filetype.vim everything works fine.

Now my question is: How can I package my vim extension inside my Debian package so that during installation the vim syntax highlighting is installed system wide and not only for the installing user (root)?

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
ChrisNbg
  • 145
  • 1
  • 7
  • 1
    there's probably a dir in /usr/lib or whatever that has the system-wide files. find it, and put your file there. – Marc B Jun 30 '15 at 18:07
  • vim stores its syntax files under /usr/share/vim/vim74/syntax but I thought it is not good style to write inside anothers package directories, but maybe this is the only way... – ChrisNbg Jun 30 '15 at 18:09
  • Don't forget to add `vim` to your dependencies. If you want to have a list of folders and files installed by the `vim` package use `dpkg -S vim`. – hek2mgl Jun 30 '15 at 18:10
  • maybe there's /usr/local/share then, which'd be for local mods and whatnot. – Marc B Jun 30 '15 at 18:10
  • I'll give it a try whether vim recognizes syntax files in /usr/local/share/vim... Thats a good point – ChrisNbg Jun 30 '15 at 18:12
  • dist packages *must not* work in `/usr/local`. This is for the local administrator. But I see the problem.. Thinking ... – hek2mgl Jun 30 '15 at 18:13
  • 1
    @ChrisNbg Try `dpkg -S vim | awk '/addons\/syntax/&&!/vim-runtime/'` ... Other packages also using `/usr/share/vim/addons` . IMHO, as long as your package requires `vim`, it is ok to do so. – hek2mgl Jun 30 '15 at 18:21
  • @hek2mgl Ok thanks for that input, then I will go that way even so iit feels a little dirty :) – ChrisNbg Jun 30 '15 at 18:27
  • @ChrisNbg IMHO you'll always need to do it like this if your package provides a plugin for another package. How will you otherwise tell that package that it should look for your package's files? But that's exactly where dependencies are made for. Isn't it? The base package exposes an interface which depending packages can use. Take the php extensions for example. They always get installed into `/usr/lib/php5/..../ext_name.so` – hek2mgl Jun 30 '15 at 18:30
  • Its not the dependency of my package that fears me, but wrinting into anothers package directory structure. Until now I only provided patches for existing packages or created completly new one - its the first time I wirte an extension for another package... But your path /usr/share/vim/addon pointed me now to the correct direction and I finally found a documentation of vim: https://pkg-vim.alioth.debian.org/vim-policy.html/x113.html – ChrisNbg Jun 30 '15 at 18:33
  • @hek2mgl: please post your anwser about the /usr/share/vim/addons directory probably with my documentation link so I can credit your answer – ChrisNbg Jun 30 '15 at 18:36

2 Answers2

3

As ChrisNbg pointed out there is a document called Packaging of Vim Addons.


imo it is ok if a package installs files into a folder exposed by another package on which it depends on. Actually it is quite commonly used, for example by software package which can be extended with plugins, like vim.

On Ubuntu, vim expects plugin packages to install their syntax files into /usr/share/vim/addons/syntax/.

The following command has been used to find this out:

dpkg -S vim | awk '/addons\/syntax/&&!/vim-runtime/'

Note: The above command may show nothing if you don't have plugin packages installed.

On my system the output was:

systemtap-common: /usr/share/vim/addons/syntax/stp.vim
python-jinja2: /usr/share/vim/addons/syntax/jinja.vim
apparmor-utils, systemtap-common, python-jinja2: /usr/share/vim/addons/syntax
apparmor-utils: /usr/share/vim/addons/syntax/apparmor.vim
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 1
    Thanks for your help. Additional vVim documentation for packaging addons can be found at https://pkg-vim.alioth.debian.org/vim-policy.html/x113.html – ChrisNbg Jun 30 '15 at 18:52
  • why are you afraid of using other packages directories? the only problem occurs, if you are providing the *same files* as another package (but even then Debian provides the `Conflicts:` relationship) – umläute Jun 30 '15 at 21:37
  • @umläute Actually, the `Conflicts` is not for the case where you could smash files. If your package has a file that exists in another package, then it will fail to install unless you `--force-overwrite` (see `man dpkg` and search on `--force` for details). So it's quite safe. – Alexis Wilke Jan 08 '22 at 17:07
  • This shows how to install the syntax files, how about the `filetype.vim`. How is that one handled? – Alexis Wilke Jan 08 '22 at 17:33
  • On Debian I suggest to put it at `/usr/share/addons/plugin/your-plugin-filetype.vim` (see: https://vim-team.pages.debian.net/vim/x126.html) – hek2mgl Jan 08 '22 at 17:49
0

Another possibility on most Unices is to install your files under /etc/skel. This is where default user files are found. The one glitch with this method is that only new users get those defaults. For existing users, you'd have to gently copy them (i.e. copy only if the destination doesn't already exist) for each existing user.

So you would place your files under:

/etc/skel/.vim/plugin/my-config.vim
/etc/skel/.vim/syntax/my-config.vim

WARNING: The filetype.vim file needs to be a plugin instead. This is because there can be only one filetype.vim file and you would have to edit it if you wanted to support additional plugins. This is not quite viable.

The copy to existing users requires a debian/<package>.postinst script:

#!/bin/sh -e
#
# Finish up the installation

#DEBHELPER#

# Source debconf library.
. /usr/share/debconf/confmodule

if [ "$1" = "configure" ]
then
    # Install files in user folders
    #
    for u in /root /home/*
    do
        name="`basename ${u}`"

        mkdir -p "${u}/.vim/syntax"
        cfg="${u}/.vim/syntax/my-config.vim"
        if ! test -f "${cfg}"
        then
            cp "/etc/skel/.vim/syntax/my-config.vim" "${cfg}"
            chmod 700 "${cfg}"
            chown "${name}" "${cfg}"
        fi

        mkdir -p "${u}/.vim/plugin"
        plg="${u}/.vim/syntax/my-config.vim"
        if ! test -f "${plg}"
        then
            cp "/etc/skel/.vim/plugin/my-config.vim" "${plg}"
            chmod 700 "${plg}"
            chown "${name}" "${plg}"
        fi
    done
fi

One advantage to this method is that the user will then be able to edit the files to their liking.

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156