[update]How to turn vim into a perfect, better R IDE and Rmarkdown writer than Rstudio (part I)

  • objects at the center window
  • view dataframe by using csv.vim (powerful plugin too)
Plug 'jalvesaq/Nvim-R' " swissknife for vim and R communicationPlug 'Shougo/unite.vim' " for citation using citation.vimPlug 'jalvesaq/zotcite'   " for citation integration with zotero used in rmarkdownPlug 'rafaqz/citation.vim' " for citation used anywhere in md or rmd files" snippet framework beginningPlug 'ncm2/ncm2'  " snippet enginePlug 'roxma/nvi-yarp' " dependencyPlug 'gaalcaras/ncm-R' " snippetsPlug 'ncm2/ncm2-ultisnips' " ncm and ultisnips integrationPlug 'SirVer/ultisnips'  " snippet engine" snippets framework endPlug 'chrisbra/csv.vim' "for viewing data directly in vim R (Nvim-R)Plug 'junegunn/goyo.vim' "for nice zoom effet when editing, see screenshot belowPlug 'ferrine/md-img-paste.vim' "paste directly image in system clipboard to rmarkdown by putting images in an /img folder (created automatically

Filetype

filetype plugin indent on" set rmarkdown file type for safetyau BufNewFile,BufRead *.Rmd set filetype=rmd

Ability to paste directly image in system clipboard to rmarkdown by putting images in an /img folder (created automatically)

" here i’m using leader+p to paste image to markdown and rmarkdownautocmd FileType markdown nmap p :call mdip#MarkdownClipboardImage()autocmd FileType rmd nmap p :call mdip#MarkdownClipboardImage()

Autocompletion

This is the tricky part, I’ll explain step by step

" First use tab and shift tab to browse the popup menu and use enter to expand:inoremap ncm2_ultisnips#expand_or("<CR>”, 'n')inoremap pumvisible() ? "<C-n>" : "<Tab>"inoremap pumvisible() ? "<C-p>" : "<S-Tab>"" However the previous lines alone won’t work, we must disable the UltiSnips Expand Trigger, I set it to ctrl-0let g:UltiSnipsExpandTrigger="<c-0>"
let maplocalleader = ","" the default is , you can also set it to <\space> if you don’t like my setting" make R starts automatically when .R or .Rmd file open and only starts one timeautocmd FileType r if string(g:SendCmdToR) == “function(‘SendCmdToR_fake’)” | call StartR(“R”) | endifautocmd FileType rmd if string(g:SendCmdToR) == “function(‘SendCmdToR_fake’)” | call StartR(“R”) | endif" make R vertical split at startlet R_rconsole_width = 57let R_min_editor_width = 18" some nice keybindding, D = cursor down one line when finished the code
" localleader+rv = view data, +rg = plot(graphic), +rs = summary, all without sending lines to R buffer, very useful
" Other useful features like Rformat and R RBuildTags aren’t covered here, see Nvim-R for more info." useful when in Rmarkdown, send chunknmap sc RDSendChunk" directly send line to R buffer when nothing selectednmap ss RDSendLine" st = send test, this function shows the output in comment, since it’s in vim we can simply press u to make the output disappearnmap st RDSendLineAndInsertOutput" send selection in visual modevmap ss REDSendSelection" rq would be mapped to RClose so we replace RClearConsole by some random stringsvmap test RClearConsole nmap test RClearConsole "idemnmap rr RStart "rr is easier than rfvmap rr RStart "idemnmap rq RClose "rq = rquit, easier to remembervmap rq RClose "idem" map ctrl a (all screen) to goyo to have a fullscreen R editing and Rmarkdown writing experience

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store