Setting up Vim on Fedora · uwot.eu
another meaningless subtitle

Setting up Vim on Fedora

· by fabio · Read in about 3 min · (548 Words)
Autocompletion fedora poweline Vim vim-enhanced

Since every time I am about to install Vim I forgot how to set it up, set it as default system wide text editor and so on I figure I’ll write it down once and for all.
First of all let’s install Vim, specifically the so called “enhanced” version which is capable of loading plugins and colorschemes:

[root@Fedora ~]# dnf install vim
### powerline plugin
[user@Fedora ~]# sudo dnf install vim-plugin-powerline

I personally really like molokay colorscheme from tomasr; putting it in the default colorscheme directory does the trick if we want to use it for every user.

[user@Fedora ~]# git clone https://github.com/tomasr/molokai.git
[user@Fedora ~]# sudo cp molokai/colors/molokai.vim /usr/share/vim/vim74/colors/
[user@Fedora ~]# rm -rf molokai

There are multiple plugins for text auto completion, the one I use is Valloric/YouCompleteMe.

[user@Fedora ~]# mkdir ~/.vim/bundle
[user@Fedora ~]# cd ~/.vim/bundle
[user@Fedora bundle]# git clone https://github.com/VundleVim/Vundle.vim.git
[user@Fedora bundle]# git clone https://github.com/Valloric/YouCompleteMe.git
[user@Fedora bundle]# sudo dnf install automake gcc gcc-c++ kernel-devel cmake python-devel
[user@Fedora bundle]# cd ~/.vim/bundle/YouCompleteMe
[user@Fedora YouCompleteMe]# git submodule update --init --recursive
[user@Fedora YouCompleteMe]# ./install.py --clang-completer
[user@Fedora YouCompleteMe]# vim +PluginInstall +qall

Create a .vimrc file to customize Vim (copy this file in every user home directory or edit /etc/vimrc instead of ~/.vimrc).

[user@Fedora ~]# cat .vimrc
---
" COLOR SCHEMA "
syntax enable
colorscheme molokai

" POWERLINE "
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
set laststatus=2         " Always show statusline

" TAB AND SPACING "
set tabstop=4           " number of visual spaces per TAB
set softtabstop=4       " number of spaces in tab when editing
set shiftwidth=4        " insert 4 spaces when pressing tab

" UI CONFIG "
"set number              " show line numbers
"set showcmd             " show command in bottom bar - useless if using
"powerline
set cursorline          " highlight current line
set wildmenu            " visual autocomplete for command menu
set showmatch           " highlight matching [{()}]
if has("gui_running")   " set custom window dimension for GVIM
    set lines=47 columns=137
endif

" SEARCH "
set incsearch           " search as characters are entered
set hlsearch            " highlight matches
nnoremap <silent><space> :nohlsearch<CR>       " turn off search highlight

" PLUGIN "
" Vundle initialization "
set nocompatible        " be iMproved, required
filetype off            " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on
---

Create a symbolic link to the plugins directory and set Vim as alias for vi in /root/.bashrc:

[user@Fedora ~]# su -c "mkdir /root/.vim && ln -s ~/.vim/bundle /root/.vim"
[user@Fedora ~]# sudo vi /root/.bashrc
---
### ADD THE FOLLOWING LINE
alias vi=vim
---

Another alias is needed to be able to load Vim custom configuration in combination with sudo command (not needed in /root/.bashrc for obvious reason).
The expression sudo=’sudo ‘ tells bash to check if the command following the space is also an alias.

[user@Fedora ~]# vi .bashrc 
---
### ADD THE FOLLOWING LINE
alias sudo='sudo '
---

All this manual configuration is needed because for some obscure reason vim-minimal is marked as dependency of sudo command.
A more sane approach would be sudo to ditch vim-minimal dependency when vim-enhanced is installed but Fedora’s people are not of the same thinking.