ncm-r


Ⅰ. 插件描述

R autocompletion for Neovim and vim 8 :memo: :bar_chart: :zap:

Ⅱ. 基本信息

创建日期:  2017-11-22
使用用户:  44
Github星:  82
插件作者:  gaalcaras

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'gaalcaras/ncm-r'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'gaalcaras/ncm-r'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'gaalcaras/ncm-r'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/gaalcaras/ncm-r

Ⅳ. 文档说明

:purple_heart: for #rstats, my favorite editor and a nice completion framework

Asynchronous R completion for Neovim and vim 8

R completion for Neovim and vim 8 with ncm-R

ncm-R provides asynchronous, as-you-type completion for the R language, as well
as R documents such as RMarkdown.

It relies on the great plugin
nvim-R to get the completion data and
extends
ncm2
for the completion.

Table of contents:
<!-- vim-markdown-toc GFM -->

<!-- vim-markdown-toc -->

Features

Completion

  • Objects from the global R environment
  • Variables of a dataframe when selecting columns inside brackets
    (dataframe[,]) or after a $
  • Functions from loaded packages or from specific package with package::
  • Packages inside library() and require()
  • Datasets inside data()
  • Arguments inside functions
  • Variables inside data transformation pipelines (%>%) and building ggplots (+)

Snippets

If UltiSnips and its [ncm2
module](https://github.com/ncm2/ncm2-ultisnips) is installed, pressing
Tab after selecting a completion suggestion will **expand syntax
snippets**. Snippets in ncm-R are designed to help you save a few keystrokes by
writing some code for you. I find it particularly useful with function
arguments.

You can see when a snippet is available for a suggestion when a [+] appears
in the pop-up menu.

Here's a list of all available snippets:

  • dataframe -> dataframe %>%|
  • variable -> "variable"| (only when inside selecting columns of
    a dataframe inside brackets)
  • function -> function([arg1], arg2) (expands only arguments with no
    default value, you can then Tab to go to the next argument)
  • package -> package::|
  • argument (use Tab to go after the end of expanded text):

    • By default -> argument = [DEFAULT_VALUE]
    • If default value is inside quotes -> argument = "[default]"
    • If default value is a boolean, then use its negation. For instance, if
      TRUE by default then it will expand to argument = [FALSE]

| stands for the cursor position and [] shows the cursor selection after snippet
expansion.

R Markdown and Rnoweb

  • R completion available in R code chunks
  • Completion for chunk options

Who should use this plugin?

You'll probably enjoy ncm-R:

  • If you like how RStudio does completion but won't use
  1. editor other than Neovim
  • If you use a lot of data pipelines (%>%)
  • If you want a "suggest as you type" completion behavior

It should be noted that Nvim-R already
comes with OmniCompletion. It's lightweight and it works well, but you need to
ask for completion (<C-x><C-o>) and it
doesn't support pipelines.

ncm-R is built on top of Nvim-R completion data to offer more features, while
remaining as fast and as lightweight as possible.

Installation

Use your favorite plugin manager. For instance, with
vim-plug :

Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'jalvesaq/Nvim-R'
Plug 'gaalcaras/ncm-R'

" Vim 8 only
if !has('nvim')
    Plug 'roxma/vim-hug-neovim-rpc'
endif

" Optional: for snippet support
" Further configuration might be required, read below
Plug 'sirver/UltiSnips'
Plug 'ncm2/ncm2-ultisnips'

" Optional: better Rnoweb support (LaTeX completion)
Plug 'lervag/vimtex'

Please make sure that you fulfill all [ncm2
requirements](https://github.com/ncm2/ncm2#requirements),
especially if you use vim 8.

If snippet completion does not work out of the box, [read
below](#getting-the-snippets-to-work).

Usage

General behavior

When you open an R file, first start an R session with nvim-R (default
mapping is <localleader>rf, see :help Nvim-R-use). That's because
completion suggestions only include objects from your global environment and
functions from loaded packages (although Nvim-R loads some packages by default,
see :help R_start_libs).

If you're familiar with completion in RStudio,
you will feel at home with ncm-R. For instance, you won't see suggestions for
your data.frames and their variables before you run the proper command in the
R console to load them in the global environment. Likewise, you won't see
dplyr functions if you forgot to run library(dplyr) first.

Pop-up menu configuration

The default pop-up menu follows a 3 column layout:

TypeColumn 1Column 2Column 3
Argumentargument= DEFAULT_VALUE
Dataset{package}Type of dataset (e.g. tibble)Short dataset description
Functions{package}functionShort function description
PackagepackageShort package description
VariablevariableType of variable (e.g. integer)

The length of the two first columns can be changed in your .vimrc. Choosing
a value below the minimum length will remove the column altogether:

ColumnMinimum lengthDefault lengthGlobal variable
Column #1713g:ncm_r_column1_length
Column #2711g:ncm_r_column2_length

Finally, if you don't want the columns to be aligned, you can disable all
column padding:

let g:ncm_r_column_layout = 0

Getting the snippets to work

ncm2-ultisnips might not work out of
the box with your UltiSnips
configuration, whether you want to [use
Enter](https://github.com/ncm2/ncm2-ultisnips#vimrc-example) or
use
Tab
instead.

Contributing to ncm-R

Overview

Nvim-R is in charge of generating and updating the completion data:

Completion dataStored in
objects in the Global EnvironmentGlobalEnvList_* file in the g:rplugin_tmpdir directory
loaded packagesg:rplugin_loaded_libs
objects from packagespack_descriptions and omnils_* files in g:rplugin_compldir

ncm-R then retrieves the completion data, parses the buffer and feeds candidate
matches to ncm2's API. For more information, please check out [this section of
Nvim-R's
README](https://github.com/jalvesaq/Nvim-R#the-communication-between-r-and-either-vim-or-neovim)
and :help ncm2-API.

Debugging

You can run NVIM_PYTHON_LOG_FILE=/tmp/log NVIM_PYTHON_LOG_LEVEL=INFO nvim
then look at nvim.log_py3_ncm_r. You can also `tail -f nvim.log_py3_*
| grep --color "[ncmR]"` to get only ncm-R messages.

Some tests can be run. The idea is to have two windows side to side (using
tmux, i3 or whatever you like). In one window, run ./test/nvim_init and monitor
what happens in Neovim. On the other window, run python test/test_ncmr.py: it
will guide you through the different test cases.

Contributors

Special thanks to @jalvesaq for making several
improvements to Nvim-R's API.

添加新评论