Note: This tutorial is written for Linux based systems.
To install the latest version of R please flollow the download and install instructions at https://cloud.r-project.org/
Neovim (nvim) is the continuation and extension of Vim editor with the aim to keep the good parts of Vim and add more features. In this tutorial I will be using Neovim (nvim), however, most of the steps are equally applicable to Vim also. Please follow download and installation instructions on nvim's GitHub wiki https://github.com/neovim/neovim/wiki/Installing-Neovim.
OR
Vim usually comes installed in most of the Linux based operating system. However, it may not be the latest one. Therefore, to install the latest version please download and install it from Vim's GitHub repository as mentioned below or a method that is more confortable to you.
git clone https://github.com/vim/vim.git
make -C vim/
sudo make install -C vim/
There are more than one plugin manager's available for Vim that can be used to install the required plugins. In this tutorial I will be using vim-plug pluggin manager.
In the end below are the plugins that we would need to convert Vim editor into a fully functional IDE for R.
- Nvim-R: https://github.com/jalvesaq/Nvim-R
- Nvim-R is the main plugin that will add the functionality to execute R code from within the Vim editor.
- Ncm-R: https://github.com/gaalcaras/ncm-R
- Nerd Tree: https://github.com/preservim/nerdtree
- Nerd Tree will be used to toggle file explorer in the side panel.
- Lightline.vim: https://github.com/itchyny/lightline.vim
- Lineline.vim adds asthetic enhancements to Vim's statusline/tabline.
- Make sure that you have
R >=3.0.0installed. - Make sure that you have
Neovim >= 0.2.0installed. - Install the
vim-plugplugin manager.
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- Install the required plugins.
First, create an init.vim file in ~/.config/nvim folder (create the folder if it doesn't exist). This file is equivalent to a .vimrc file in the traditional Vim environment. To init.vim file start adding:
" Specify a directory for plugins
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
" List of plugins.
" Make sure you use single quotes
" Shorthand notation
Plug 'jalvesaq/Nvim-R'
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'gaalcaras/ncm-R'
Plug 'preservim/nerdtree'
Plug 'itchyny/lightline.vim'
" Initialize plugin system
call plug#end()
- Update and add more features to the
init.vimfile.
" Set a Local Leader
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader = ","
let g:mapleader = ","
" Plugin Related Settings
" NCM2
autocmd BufEnter * call ncm2#enable_for_buffer() " To enable ncm2 for all buffers.
set completeopt=noinsert,menuone,noselect " :help Ncm2PopupOpen for more
" information.
" NERD Tree
map <leader>nn :NERDTreeToggle<CR> " Toggle NERD tree.
" LightLine.vim
set laststatus=2 " To tell Vim we want to see the statusline.
" General NVIM/VIM Settings
" Tabs & Navigation
map <leader>tnew :tabnew<cr> " To create a new tab.
map <leader>to :tabonly<cr> " To close all other tabs (show only the current tab).
map <leader>tc :tabclose<cr> " To close the current tab.
map <leader>tm :tabmove<cr> " To move the current tab to next position.
map <leader>tn :tabn<cr> " To swtich to next tab.
map <leader>tp :tabp<cr> " To switch to previous tab.
" Line Numbers & Indentation
set backspace=indent,eol,start " To make backscape work in all conditions.
set ma " To set mark a at current cursor location.
set number " To switch the line numbers on.
set expandtab " To enter spaces when tab is pressed.
set smarttab " To use smart tabs.
set autoindent " To copy indentation from current line
" when starting a new line.
set si " To switch on smart indentation.
" Search
set ignorecase " To ignore case when searching.
set smartcase " When searching try to be smart about cases.
set hlsearch " To highlight search results.
set incsearch " To make search act like search in modern browsers.
set magic " For regular expressions turn magic on.
" Brackets
set showmatch " To show matching brackets when text indicator
" is over them.
set mat=2 " How many tenths of a second to blink
" when matching brackets.
" Errors
set noerrorbells " No annoying sound on errors.
" Color & Fonts
syntax enable " Enable syntax highlighting.
" Return to last edit position when opening files
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif