Skip to content

Instantly share code, notes, and snippets.

@lf-araujo
Created July 17, 2022 14:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lf-araujo/4656c89dcd14f04dced76deb41f145fd to your computer and use it in GitHub Desktop.
Save lf-araujo/4656c89dcd14f04dced76deb41f145fd to your computer and use it in GitHub Desktop.
Lunarvim settings for R and Nim

Lunarvim R-IDE

Lunarvim settings for R statistics with neovim as an IDE.

--[[
lvim is the global options object

Linters should be
filled in as strings with either
a global executable or a path to
an executable
]]

vim.o.guifont="Iosevka:h12"
-- vim.o.neovide_transparence=0.5
-- vim.o.neovide_remember_window_size = true

-- general
lvim.log.level = "warn"
lvim.format_on_save = false
vim.o.background = "dark"
lvim.colorscheme = "monokai"
lvim.builtin.bufferline.active = false
vim.cmd [[ set showtabline=0 ]]
-- 
-- keymappings [view all the defaults by pressing <leader>Lk]
lvim.leader = "space"
-- add your own keymapping
lvim.keys.normal_mode["<C-s>"] = ":w<cr>"
vim.cmd("xnoremap iz [zo]z")
-- lvim.keys.normal_mode["t"] = "<Plug>(iron-send-movement)"
-- unmap a default keymapping
-- lvim.keys.normal_mode["<C-Up>"] = false
-- edit a default keymapping
-- lvim.keys.normal_mode["<C-q>"] = ":q<cr>"
-- lvim.keys.normal_mode["gx"] = ":execute 'silent! !xdg-open ' . shellescape(expand('<cfile>'), 1)<CR>"

vim.g.asyncrun_open = 6
-- vim.g.rout_follow_colorscheme = 1 
-- vim.g.Rout_more_colors = 1 
vim.g.R_pdfviewer="evince"
vim.g.R_objbr_opendf = 0
-- vim.g.R_external_term = "IronFocus"
vim.g.jupytext_fmt = 'Rmd'
vim.cmd [[ let g:jupytext_filetype_map = {'Rmd': 'rmd'}]]

vim.g.copilot_no_tab_map = true
vim.g.copilot_assume_mapped = true
vim.g.copilot_tab_fallback = ""
local cmp = require "cmp"
lvim.builtin.cmp.mapping["<C-Enter>"] = function(fallback)
  cmp.mapping.abort()
  local copilot_keys = vim.fn["copilot#Accept"]()
  if copilot_keys ~= "" then
    vim.api.nvim_feedkeys(copilot_keys, "i", true)
  else
    fallback()
  end
end
cmp.setup({experimental = {ghost_text = false}})


-- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode.
-- we use protected-mode (pcall) just in case the plugin wasn't loaded yet.
local _, actions = pcall(require, "telescope.actions")
lvim.builtin.telescope.defaults.mappings = {
  -- for input mode
  i = {
    ["<C-j>"] = actions.move_selection_next,
    ["<C-k>"] = actions.move_selection_previous,
    ["<C-n>"] = actions.cycle_history_next,
    ["<C-p>"] = actions.cycle_history_prev,
  },
  -- for normal mode
  n = {
    ["<C-j>"] = actions.move_selection_next,
    ["<C-k>"] = actions.move_selection_previous,
  },
}

-- Use which-key to add extra bindings with the leader-key prefix
lvim.builtin.which_key.mappings["P"] = { "<cmd>Telescope projects<CR>", "Projects" }
lvim.builtin.which_key.mappings["r"] = { "<cmd>call feedkeys('\\')<CR>", "Work with R" }
lvim.builtin.which_key.vmappings["s"] = { "<Plug>REDSendSelection", "Send to Nvim-R" }
lvim.builtin.which_key.vmappings["d"] = { "<Plug>(iron-visual-send)", "Send visual to REPL" }


lvim.builtin.which_key.mappings["A"] = {
  name = "+Tasks",
  l = { "<cmd>AsyncTaskList<cr>", "List" },
  r = { "<cmd>AsyncTask render<cr>", "Render Rmd" },
  c = { "<cmd>e .tasks<cr>", "Edit" },
}

lvim.builtin.which_key.mappings["R"] = {
  name = "+REPL",
  r = { "<cmd>IronRepl<CR>", "Start REPL" },
  d = { "<Plug>(iron-send-line)", "Send line" },
  f = { "<cmd>IronFocus<CR>", "Refocus" },
}


-- lvim.builtin.which_key.mappings["t"] = {
--   name = "+Trouble",
--   r = { "<cmd>Trouble lsp_references<cr>", "References" },
--   f = { "<cmd>Trouble lsp_definitions<cr>", "Definitions" },
--   d = { "<cmd>Trouble lsp_document_diagnostics<cr>", "Diagnostics" },
--   q = { "<cmd>Trouble quickfix<cr>", "QuickFix" },
--   l = { "<cmd>Trouble loclist<cr>", "LocationList" },
--   w = { "<cmd>Trouble lsp_workspace_diagnostics<cr>", "Diagnostics" },
-- }

-- TODO: User Config for predefined plugins
-- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile
lvim.builtin.dashboard.active = true
lvim.builtin.notify.active = true
lvim.builtin.terminal.active = true
lvim.builtin.nvimtree.setup.view.side = "left"
lvim.builtin.nvimtree.show_icons.git = 0

vim.opt.undodir = vim.fn.stdpath "cache" .. "/undo"
vim.opt.undofile = true -- enable persistent undo
vim.opt.smartindent = true
vim.opt.wrap = true 

-- if you don't want all the parsers change this to a table of the ones you want
lvim.builtin.treesitter.ensure_installed = {
  "bash",
  "c",
  "javascript",
  "json",
  "lua",
  "python",
  "typescript",
  "tsx",
  "css",
  "rust",
  "java",
  "yaml",
  "r",
}

lvim.builtin.treesitter.ignore_install = { "haskell" }
lvim.builtin.treesitter.highlight.enabled = true

-- generic LSP settings

---@usage disable automatic installation of servers
-- lvim.lsp.automatic_servers_installation = false

---@usage Select which servers should be configured manually. Requires `:LvimCacheReset` to take effect.
-- See the full default list `:lua print(vim.inspect(lvim.lsp.override))`
-- vim.list_extend(lvim.lsp.override, { "pyright" })

---@usage setup a server -- see: https://www.lunarvim.org/languages/#overriding-the-default-configuration
-- local opts = {} -- check the lspconfig documentation for a list of all possible options
-- require("lvim.lsp.manager").setup("pylsp", opts)

require'lspconfig'.r_language_server.setup{}
require'lspconfig'.nimls.setup{}

vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    virtual_text = false,
    signs = true,
    underline = true
  }
)

-- you can set a custom on_attach function that will be used for all the language servers
-- See <https://github.com/neovim/nvim-lspconfig#keybindings-and-completion>
lvim.lsp.on_attach_callback = function(client, bufnr)
  local function buf_set_option(...)
    vim.api.nvim_buf_set_option(bufnr, ...)
  end
  --Enable completion triggered by <c-x><c-o>
  buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
end

-- -- set a formatter, this will override the language server formatting capabilities (if it exists)
-- local formatters = require "lvim.lsp.null-ls.formatters"
-- formatters.setup {
--   { command = "black", filetypes = { "python" } },
--   { command = "isort", filetypes = { "python" } },
--   {
--     -- each formatter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
--     command = "prettier",
--     ---@usage arguments to to the formatter
--     -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
--     extra_args = { "--print-with", "100" },
--     ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
--     filetypes = { "typescript", "typescriptreact" },
--   },
-- }

-- -- set additional linters
-- local linters = require "lvim.lsp.null-ls.linters"
-- linters.setup {
--   { command = "flake8", filetypes = { "python" } },
--   {
--     -- each linter accepts a list of options identical to https://github.com/jose-elias-alvarez/null-ls.nvim/blob/main/doc/BUILTINS.md#Configuration
--     command = "shellcheck",
--     ---@usage arguments to pass to the formatter
--     -- these cannot contain whitespaces, options such as `--line-width 80` become either `{'--line-width', '80'}` or `{'--line-width=80'}`
--     extra_args = { "--severity", "warning" },
--   },
--   {
--     command = "codespell",
--     ---@usage specify which filetypes to enable. By default a providers will attach to all the filetypes it supports.
--     filetypes = { "javascript", "python" },
--   },
-- 

-- Additional Plugins
lvim.plugins = {
    {"alaviss/nim.nvim"},
    {"jalvesaq/Nvim-R"},
    {"github/copilot.vim"},
    {"EdenEast/nightfox.nvim"},
    {"savq/melange"},
    {"skywind3000/asyncrun.vim"},
    {"skywind3000/asynctasks.vim"},
    {"hkupty/iron.nvim"},
{"https://github.com/savq/melange"},
  {"https://github.com/tanvirtin/monokai.nvim"},
{'GCBallesteros/jupytext.vim'},
}

-- Autocommands (https://neovim.io/doc/user/autocmd.html)
lvim.autocommands.custom_groups = {
  { "VimLeave", "*", "if exists(g:SendCmdToR) && string(g:SendCmdToR) != 'function(SendCmdToR_fake)' | call RQuit('nosave') | endif" },
  { "FileType", "rmd", "set foldmarker=```{,```" },
  { "FileType", "rmd", "setlocal foldmethod=marker" },
}

-- require'nvim-tree'.setup {
--   disable_netrw       = false,
--   hijack_netrw        = false,
--   update_to_buf_dir    = {
--     enable = false
--   }
-- }

-- vim.g.loaded_netrw = true -- or 1
-- vim.g.loaded_netrwPlugin = true -- or 1
lvim.builtin.nvimtree.setup.disable_netrw = false -- or false
lvim.builtin.nvimtree.setup.hijack_netrw = false -- or false

local iron = require('iron')

iron.core.add_repl_definitions {
  r = {
    over_ssh = {
      command = {"ssh", "login@university.org", "R", "--no-save"} },
    boulder = {
      command = {"zsh"}},
    here = {
      command = {"R", "--no-save"}}},
  rmd = {
    over_ssh = {
      command = {"ssh", "login@university.org", "R", "--no-save"}},
    here = {
      command = {"R", "--no-save"}}},
  nim = {
    inim = {
      command = {"inim"}}},
  text = {
    bash = {
      command = {"zsh"}}},
}

iron.core.set_config {
  preferred = {
    r = "boulder",
    rmd = "here",
    nim = "inim",
    text = "bash"
  },
  repl_open_cmd = "botright vertical split"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment