vim - installation and configuration
Installation
In Redhat Linux, gVim can be installed using this : sudo yum install vim-X11
In Ubuntu, to install Vim and gVim, use this: sudo apt install vim-gtk3
Arch Linux, sudo pacman -S gvim
vimrc file
- In Linux, the system vimrc file is in
/etc
- However, if we want to change vim settings, do not mess with the system vimrc.
- Instead, do all the customizations to user vimrc
- which is located at
/home/user/.vimrc
- If it is not already available, create it manually.
To create and edit our .vimrc, open terminal and run this : vim ~/.vimrc
" Note the system vimrc file and user vimrc file paths displayed by the :version command. The system vimrc file can be created by an administrator to customize Vim for all users. In addition, each user can have his or her own user vimrc. " Tip: Do not create a system vimrc file. Use a user vimrc file instead. " Especially, if you are going to need administrator access to do anything in the computer.
" After making changes to the .vimrc file, " if we want to make them effective immediately (called sourcing them), " :source % (from within vim) " If you do not know where vimrc is located, running this command would help. " `:e $MYVIMRC`
For a clean start
- To remove the .vim directory, open terminal and run this :
rm -rf ~/.vim
- To remove the .vimrc file, open terminal and run this :
rm ~/.vimrc
Vim Settings File On Windows
On Windows systems, the best way to find the value of $HOME is from within Vim, as follows. These commands are useful to see what directories your Vim is using:
:version
:echo expand('~')
:echo $HOME
:echo $VIM
:echo $VIMRUNTIME
Packages and plugins
Where are the plugins installed?
The plugins also go into the .vim
directory located here : /home/user/.vim
Vim’s official plugin install method
https://github.com/vim/vim/blob/master/runtime/doc/repeat.txt#L597
Manual installation of packages in Windows
Create the folder \[your-name]\start
if it doesn’t exist and clone the git repositories into it or manually copy the repositories into this folder.
C:\Program Files\Vim\vim82\pack\[your-name]\start
Protip: To learn more about any plugin, simply prepend https://github.com/
to any plugin name. So if you see this line in a .vimrc file:
Plug 'pechorin/any-jump.vim'
Change it to this to get the plugin’s URL:
https://github.com/pechorin/any-jump.vim
Using vim-plug
https://github.com/junegunn/vim-plug
Before using Plugin
in vimrc to install plug-ins, we need to install it in the machine.
Look at the githut repo for the plugin manager “plug” for details about installing it.
After making changes to the list of plugins in the .vimrc
file, if we want to make them effective immediately, run this :PlugInstall
(from within vim)
Troubleshooting issues when installing plugins and running Vim
When installing vim plugins using Plug (:PlugInstall
) or launching Vim after installing the plugins, sometimes, we may see errors like this:
Error detected while processing /home/lee/.vim/plugin/refactor.vim:
line 45:
E492: Not an editor command: ^M
That’s caused by Vimscript files that have Windows-style CR-LF line endings when used on Linux.
One way to fix the issue is to open each of the the corresponding file(s) in Vim and convert them to Unix-style endings using this.
:w ++ff=unix
A better way to fix the issue is: Simple option in linux. Goto the bundle folder (or the plugged folder) ~/.vim/bundle or the specific package dir execute
find . | xargs dos2unix
You may have to install the dos2unix package before running this.
Plugins
Installing vim plug in a corporate environment
Download the git project and manually copy plug.vim
file into vim/autoload
directory.
How to install the plugins manually if they are blocked in a corporate environment?
Download the github projects and manually move them into vim/plugged
directory.
Setting path in Windows machines
In Windows machines, sometimes, we may see errors like this:
vim is not recognized as an internal or external command
The fix is to install vim
and add the path to Vim to Windows Path
.
C:\Program Files\Vim\vim91