Greetings, you're new to WSL2/Linux and decided to change your username inside WSL Ubuntu. You followed all the necessary steps, yet you found out that old stuff doesn't work as expected, specifically with Vim. You might encounter issues like Vim complaining about the wrong username when accessing certain files.
Context: Understanding the VIM Runtime Path
Vim, a popular text editor, stores its configuration files and plugins in the runtime path. When Vim is installed system-wide, its runtime path usually points to a system account. The runtime path can be found in Vim by typing :echo &runtimepath in the editor.
The Problem: Runtime Path Points to the Old Username
After changing the WSL2/Linux username, you may notice that Vim still refers to files using the old username in the runtime path. This can cause issues when accessing or executing these files due to improper permissions.
Symptoms
- Vim Errors on startup
- Difficulty accessing Vim configuration files
- Issues while using plugins
The Solution: Updating the VIM Runtime Path
The following steps will update the Vim runtime path, reflecting your new username.
Identify your system-wide VIM configuration location
The system-wide Vim configuration usually resides in the /etc/vim directory in most Linux distributions.
Backup and edit the system-wide Vim configuration file
sudo cp /etc/vim/vimrc /etc/vim/vimrc.backup
sudo nano /etc/vim/vimrc
Replace the content of the /etc/vim/vimrc file with the current user's Vim configuration, ensuring to keep the previous contents as comments for future reference.
Update plugin paths in Vim configuration if necessary
If you have Vim plugins installed, ensure paths in the config reflect the new username. Typically, plugin managers like Vundle, Pathogen, and Vim-Plug allow you to specify plugin paths agnostic to usernames.
Summary - Wrapping it up
Fixing the Vim runtime path after changing usernames in WSL2/Linux requires updating your system-wide Vim configuration. By editing the /etc/vim/vimrc file and reflecting the new user's config, access to files and plugins will no long invoke errors related to the old username.
References
-
Vim Online Resources:
Vim Official Website
Effective Vim - Documentation and Cheat Sheet