Add more R functionalities
This commit is contained in:
parent
3d6a296e8c
commit
dec46f1e13
@ -1,4 +1,3 @@
|
|||||||
-- Alternatively, using a Lua function
|
|
||||||
local function lines_with_preview()
|
local function lines_with_preview()
|
||||||
local current_file = vim.fn.fnameescape(vim.fn.expand('%'))
|
local current_file = vim.fn.fnameescape(vim.fn.expand('%'))
|
||||||
local rg_command = string.format("rg --with-filename --column --line-number --no-heading --color=always --smart-case . %s", current_file)
|
local rg_command = string.format("rg --with-filename --column --line-number --no-heading --color=always --smart-case . %s", current_file)
|
||||||
@ -6,4 +5,44 @@ local function lines_with_preview()
|
|||||||
vim.cmd(fzf_command)
|
vim.cmd(fzf_command)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function DevtoolsPath()
|
||||||
|
local devPath = vim.fn.trim(vim.fn.system('ls ' .. vim.fn.expand("%:p:h") .. ' | grep DESCRIPTION'))
|
||||||
|
|
||||||
|
if devPath == "" then
|
||||||
|
devPath = vim.fn.trim(vim.fn.system('realpath ' .. vim.fn.expand("%:p:h") .. '/../'))
|
||||||
|
return devPath
|
||||||
|
else
|
||||||
|
devPath = vim.fn.expand('%:p:h')
|
||||||
|
return devPath
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_user_command('LinesWithPreview', lines_with_preview, {})
|
vim.api.nvim_create_user_command('LinesWithPreview', lines_with_preview, {})
|
||||||
|
vim.api.nvim_create_autocmd({"BufNewFile", "BufRead"}, {
|
||||||
|
pattern = "DESCRIPTION",
|
||||||
|
command = "set filetype=r"
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Map <C-c>wd to send devtools::document command in R
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "r",
|
||||||
|
callback = function()
|
||||||
|
vim.api.nvim_set_keymap('n', '<C-c>wd', ':RSend devtools::document("' .. DevtoolsPath() .. '")<CR>', { noremap = true, silent = true })
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Map <C-c>wi to send devtools::install command in R
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "r",
|
||||||
|
callback = function()
|
||||||
|
vim.api.nvim_set_keymap('n', '<C-c>wi', ':RSend devtools::install("' .. DevtoolsPath() .. '", quick = TRUE, keepSource=TRUE, upgrade = "never")<CR>', { noremap = true, silent = true })
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "r",
|
||||||
|
callback = function()
|
||||||
|
vim.api.nvim_set_keymap('n', '<C-c>i', ':RSend install.packages("")<Left><Left>', { noremap = true, silent = true })
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user