Skip to content

Commit 95345f6

Browse files
Create rstudio_clone.lua
AI generated template first, will tinker after
1 parent 3338d39 commit 95345f6

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
-- Enable filetype detection
2+
vim.cmd('filetype plugin on')
3+
4+
-- Function to setup RStudio-like layout
5+
local function setup_rstudio_layout()
6+
-- Close any existing buffers to start fresh
7+
vim.cmd('silent! %bdelete!')
8+
9+
-- Set up the main layout with 4 quadrants
10+
vim.cmd('vsplit') -- Vertical split (left/right)
11+
vim.cmd('split') -- Horizontal split in left pane (top-left/bottom-left)
12+
vim.cmd('wincmd l') -- Move to right pane
13+
vim.cmd('split') -- Horizontal split in right pane (top-right/bottom-right)
14+
15+
-- Navigate to each quadrant and set them up
16+
-- Top Left: Code/Text Editor (current buffer)
17+
vim.cmd('wincmd t') -- Move to top-left
18+
19+
-- Bottom Left: Terminal/Console
20+
vim.cmd('wincmd j') -- Move to bottom-left
21+
vim.cmd('resize 15') -- Set height for console
22+
vim.cmd('terminal') -- Open terminal
23+
vim.cmd('startinsert') -- Enter insert mode in terminal
24+
25+
-- Top Right: Various panels (Git, CSV, etc.)
26+
vim.cmd('wincmd l') -- Move to top-right
27+
vim.cmd('vsplit') -- Split top-right vertically for multiple tabs
28+
vim.cmd('wincmd h') -- Move to left side of top-right
29+
30+
-- Set up tabbed interface for top-right
31+
vim.cmd('tabnew') -- Create new tab for Git
32+
vim.cmd('Neotree git_status') -- Requires neo-tree.nvim
33+
34+
vim.cmd('tabnew') -- Create new tab for CSV/data
35+
vim.cmd('DBUI') -- Requires vim-dadbod-ui for database/CSV viewing
36+
37+
vim.cmd('tabfirst') -- Go back to first tab
38+
39+
-- Bottom Right: Plots, Directory, Help
40+
vim.cmd('wincmd j') -- Move to bottom-right
41+
vim.cmd('split') -- Split bottom-right
42+
vim.cmd('wincmd j') -- Move to lower part of bottom-right
43+
44+
-- Set up tabbed interface for bottom-right
45+
vim.cmd('tabnew') -- Tab for file explorer
46+
vim.cmd('Neotree filesystem') -- File tree
47+
48+
vim.cmd('tabnew') -- Tab for plots (image preview)
49+
vim.cmd('terminal') -- Terminal for displaying plots
50+
vim.cmd('startinsert')
51+
52+
vim.cmd('tabnew') -- Tab for help
53+
vim.cmd('help') -- Open help
54+
55+
vim.cmd('tabfirst') -- Go back to first tab
56+
57+
-- Return to main editor (top-left)
58+
vim.cmd('wincmd t') -- Back to top-left
59+
60+
-- Set window sizes
61+
vim.cmd('vertical resize 60') -- Set width for left panes
62+
end
63+
64+
-- Function to check if we should setup RStudio layout
65+
local function setup_filetype_layout()
66+
local ft = vim.bo.filetype
67+
if ft == 'r' or ft == 'rmd' or ft == 'quarto' then
68+
-- Only setup if we're in a GUI or fullscreen and not already setup
69+
if vim.fn.has('gui_running') == 1 then
70+
setup_rstudio_layout()
71+
end
72+
end
73+
end
74+
75+
-- Auto commands for R and Rmd files
76+
vim.api.nvim_create_autocmd({'BufWinEnter', 'FileType'}, {
77+
pattern = {'*.r', '*.R', '*.rmd', '*.Rmd', '*.RMD'},
78+
callback = function()
79+
vim.schedule(function()
80+
setup_filetype_layout()
81+
end)
82+
end
83+
})
84+
85+
-- Plugin configuration
86+
return require('packer').startup(function(use)
87+
-- Package manager
88+
use 'wbthomason/packer.nvim'
89+
90+
-- File tree and git status
91+
use {
92+
'nvim-neo-tree/neo-tree.nvim',
93+
requires = {
94+
'nvim-lua/plenary.nvim',
95+
'nvim-tree/nvim-web-devicons',
96+
'MunifTanjim/nui.nvim',
97+
},
98+
config = function()
99+
require('neo-tree').setup({
100+
filesystem = {
101+
hijack_netrw_behavior = "open_default"
102+
}
103+
})
104+
end
105+
}
106+
107+
-- Database/CSV viewer
108+
use {
109+
'kristijanhusak/vim-dadbod-ui',
110+
requires = {'tpope/vim-dadbod'}
111+
}
112+
113+
-- Terminal management
114+
use {'akinsho/toggleterm.nvim', tag = '*', config = function()
115+
require('toggleterm').setup()
116+
end}
117+
118+
-- R language support
119+
use 'jalvesaq/Nvim-R'
120+
121+
-- Markdown support for Rmd files
122+
use 'preservim/vim-markdown'
123+
124+
-- Image preview for plots
125+
use 'edluffy/hologram.nvim'
126+
127+
-- Better syntax highlighting
128+
use 'nvim-treesitter/nvim-treesitter'
129+
130+
end)

0 commit comments

Comments
 (0)