dotfiles_vim/README.md
2024-12-17 11:55:35 +05:30

163 lines
5.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# System-wide `vimrc` Configuration with Vim-Plug
This guide outlines the steps to set up a system-wide configuration for `vim` and install plugins using the plugin manager [Vim-Plug](https://github.com/junegunn/vim-plug). For more details on using `vim-plug`, other plugin managers, or individual plugins, consult their respective documentation or browse [VimAwesome](https://vimawesome.com/).
If you want to skip the instructions and use my config as-is, just go to [this section](#shortcut).
---
### 1. Setting Up the Configuration Directories
First, ensure that the necessary directories for system-wide vim configuration exist. Create the main vim configuration directory if it doesn't exist:
```bash
mkdir -p /etc/vim
cd /etc/vim
```
Next, create the required subdirectories with appropriate permissions. Create directories for autoload, colors, plugins, session data, etc:
```bash
mkdir -p -m 755 autoload colors plugged session sessions
```
---
### 2. Installing Vim-Plug and Color Schemes
#### 2.1. Download Vim-Plug
Vim-Plug is the plugin manager that will be used to install and manage plugins. Download it to the `autoload` directory:
```bash
curl -fLo /etc/vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
```
Set the appropriate permissions for the downloaded file:
```bash
chmod o+r /etc/vim/autoload/*
```
#### 2.2. Install a Color Scheme (Optional)
You can pick a color scheme of your choice. Place it in the `colors/` directory. For this example, we'll use the **Molokai** color scheme.
```bash
curl -fLo /etc/vim/colors/molokai.vim https://raw.githubusercontent.com/tomasr/molokai/refs/heads/master/colors/molokai.vim
```
Ensure that the color scheme file has the correct permissions:
```bash
chmod o+r /etc/vim/colors/*
```
---
### 3. Configuring the `vimrc`
The system-wide `vimrc` file location might vary depending on your Linux distribution. On Ubuntu, it is typically found at `/etc/vim/vimrc`. If the file doesn't exist, create it with the required permissions.
```bash
touch /etc/vim/vimrc
chmod 755 /etc/vim/vimrc
vim /etc/vim/vimrc
```
#### 3.1. Set Runtime Paths
To ensure `vim` recognizes the autoload, plugin, and color scheme directories, add the following lines to your `vimrc`:
```vim
set runtimepath+=/etc/vim/autoload
set runtimepath+=/etc/vim/plugged
set runtimepath+=/etc/vim/colors
```
#### 3.2. Enable Vim-Plug and Install Plugins
To initialize `vim-plug` and install plugins, add the following configuration to your `vimrc`. This specifies the plugin directory and lists the plugins you'd like to use.
```vim
" Initialize Vim-Plug
call plug#begin('/etc/vim/plugged')
" List plugins here
Plug 'rust-lang/rust.vim' " Example plugin for Rust syntax highlighting
" Add more plugins as needed...
" End plugin section
call plug#end()
```
#### 3.3. Enable Filetype Plugins and Indentation
To enable filetype-specific plugins and proper indentation, add this line to your `vimrc`:
```vim
filetype plugin indent on " Enable filetype-based plugins and indentation
```
You can also add any other custom configurations such as tab size, line numbering, or key mappings. For a comprehensive example, refer to [my vimrc](https://git.candifloss.cc/candifloss/vim_config/src/branch/main/vimrc).
---
### 4. Installing the Plugins
Once you've updated your `vimrc`, its time to install the plugins.
#### 4.1. Source the `vimrc`
After saving the changes to the `vimrc`, source it to apply the changes:
```vim
:source %
```
#### 4.2. Install Plugins
Run the following command to install the plugins specified in your `vimrc`:
```vim
:PlugInstall " This command is specific to vim-plug
```
This will download and install all the listed plugins.
---
### 5. Done!
Once the installation is complete, your system-wide `vim` should be fully configured with the desired plugins and color schemes. You're now ready to enjoy a fully customized `vim` experience!
---
### Shortcut
To install my config as-is, just run this as root:
```bash
mkdir -p /etc/vim/
cd /etc/vim/
git clone https://git.candifloss.cc/candifloss/vim_config.git .
mkdir -p plugged session sessions
chmod 755 /etc/vim/*
chmod o+r /etc/vim/autoload/*
chmod o+r /etc/vim/colors/*
chmod o+r -R /etc/vim/plugged/*
chmod o+x /etc/vim/plugged/*
```
That should work.
### Troubleshooting
- **Permissions**: Ensure that the directories and files in `/etc/vim` have the correct read and execute permissions for all users who need access.
- **Plugin Conflicts**: If you encounter issues with specific plugins, check their documentation for configuration options or known issues.
### References
- Stack-Overflow: [File permissions for vimrc](https://stackoverflow.com/a/45018554)
- Vim docs: [Location of system-wide vimrc](https://vimdoc.sourceforge.net/htmldoc/starting.html#system-vimrc)
- [Vim-Plug](https://github.com/junegunn/vim-plug): Installation, syntax for specifying plugins, etc.
- [Vim-Awesome](https://vimawesome.com): Collection of plugins and installation guides.
- vimhelp.org: [Vim9-script syntax reference](https://vimhelp.org/vim9.txt.html) for vimrc config and vim scripting.