Pushing System-Wide Vim Configuration Changes Across Multiple VMs/Desktops

While setting up my Debian Linux container, I needed to make changes to Vim system-wide instead of per-user. So I went ahead and removed everything from /etc/vim/vimrc and add my own settings:

set mouse-=

I saved and reopened the same file and I still get the mouse pointer. Inside vim, I can do set mouse-=a which tells Vim not to interact with my mouse, however, I want to make it permanent regardless of the user. So set mouse-= does nothing. I then tried:

set mouse-=a

…and that won’t do it either.

set mouse=

…still won’t do it either, so I was out of luck until I found this thread in Github:

I scrolled down to the third post made by “djddjd” and I came across the setting, which is let skip_defaults_vim = 1

So I added that to the top of the file.

let skip_defaults_vim = 1
set mouse=

And now I get the insertion cursor instead of the mouse pointer so that I can select text without triggering Vim’s visual mode. If I remove set mouse= line from the /etc/vimrc file, the behavior is the same with the insertion cursor still over the terminal. Of course, inserting set mouse=a is the same as removing the let skip_defaults_vim = 1 line from the vimrc file.

let skip_defaults_vim = 1
set mouse=a

Because I do not need the visual mode, I can just delete the set mouse= line.

Now here’s the problem. Once I add let skip-defaults_vim = 1, Vim started to behave similar to Vi.

  • A = Down
  • B = Up
  • C = Right
  • D = Left
  • Backspace = Nothing. Vim won’t erase text.

As the thread is about how to push my own default settings system-wide across multiple virtual machines, here’s my question: how do I get it so that I can erase text and use arrow keys so that Vim won’t behave like Vi?

And now here’s my main question: what would be the good way of pushing changes to Vim across multiple virtual machines regardless of users?

I’m not concerned with overriding users’ .vimrc behavior as I want the changes to be global across all Linux VMs. This includes Debian, Ubuntu, Arch, Fedora, and several other Linux distributions, so I want my changes to be distro-agnostic.

I am handy with Linux as I have Ansible setup and ready to go; however, I have not written a playbook yet. I have watched Ansible videos from LearnLinuxTV’s YouTube channel since 2 years ago, but I will have to rewatch it again as my knowledge of it has gotten rusty.

Should I use Ansible or Git for pushing vimrc changes? Some distributions put vimrc in /etc/ while others put vimrc in /etc/vim/ directory, so I do not know how that would work with Git.

Anyway, please pardon me if my thread has gotten too long with a wall of text. Basically, I need to push my own Vim settings regardless of which Linux distribution is running in a virtual machine.

Update: I also lost syntax highlighting by telling Vim to skip the entire default configuration. If I don’t tell Vim to skip default configuration, the set mouse command will still get overridden by the defaults. I do not like this behavior.

Update 2: Okay, with the exception of pushing changes for Vim across multiple VMs automatically, here are the settings that will restore syntax highlighting, use of backspace, and arrow keys:

let skip_defaults_vim = 1
set mouse=
syntax on
set backspace=indent,eol,start
set nocompatible

I’ll just leave it there in case others might find useful, although this could have been a separate topic. I just had to do a couple of Google searches in the Internet.

Good find, thanks for sharing.

1 Like

Solved!

Okay. In order to refresh my memory regarding Ansible, I had to watch the Ansible tutorials by @jay even though I did play with Ansible last year (thanks for the tutorial regarding Ansible). This is what I have so far.

~/ansible/inventory

[debian]
172.20.1.3:[REDACTED]
172.20.1.4:[REDACTED]
172.20.30.4:[REDACTED]
localhost ansible_connection=local

[archlinux]
172.20.1.8:[REDACTED]

~/ansible/ansible.cfg

[defaults]
inventory = inventory
private_key_file = ~/.ssh/ansible

~/ansible/update_vim.yml

---

- hosts: archlinux
  become: true
  tasks:
  - name: install vim in Arch Linux if not installed
    pacman:
      name: vim
      state: present
  - name: update vim file as root in Arch Linux desktop.
    copy:
      src: ~/ansible/files/vimrc
      dest: /etc/vimrc

- hosts: debian
  become: true
  tasks:
  - name: install vim if not installed in Debian.
    apt:
      name: vim
  - name: update vim file as root in Debian servers.
    copy:
      src: ~/ansible/files/vimrc
      dest: /etc/vim/vimrc

~/ansible/files/vimrc

let skip_defaults_vim = 1
set mouse=
syntax on
set backspace=indent,eol,start
set nocompatible

Result and Summary

And now everything should work.

Oh, and I forgot to mention for those who came across this thread and are curious about the copy module. You can assign owner, group, and mode to a destination file you want to copy to. The mode is the file permission such as 0644 (“0” is no special permissions such as sticky or setuid/setgid, “644” is for read/write for user, read for group, and read for “other.” “1” is execute for the last three digits and “2” is for write.

Hope that helps!

1 Like