Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
132 lines (109 loc) · 3.34 KB
/
Copy pathinit.lua
File metadata and controls
132 lines (109 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
-- Speed up plugin loading
vim.loader.enable()
-- Disable unneeded providers
vim.g.loaded_node_provider = 0
vim.g.loaded_perl_provider = 0
vim.g.loaded_python3_provider = 0
vim.g.loaded_ruby_provider = 0
-- Set a line number
vim.opt.number = true
-- Show commands when typing
vim.opt.showcmd = true
-- Automatically choose the appropriate line endings
vim.opt.fileformats = { "unix", "dos", "mac" }
-- Set tab length to 4 spaces, and convert tabs into spaces
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
-- Create a group so autocommands don't duplicate
local tab_adjustments = vim.api.nvim_create_augroup("TabAdjustments", { clear = true })
-- Web Development (2 spaces), soft tab
vim.api.nvim_create_autocmd("FileType", {
group = tab_adjustments,
pattern = {
"html", "css", "javascript", "typescript",
"javascriptreact", "typescriptreact",
"lua", "ruby", "yml", "yaml", "xml",
"json"
},
callback = function()
vim.bo.tabstop = 2
vim.bo.shiftwidth = 2
vim.bo.softtabstop = 2
vim.bo.expandtab = true
end,
})
-- Map jj to close insert mode
vim.keymap.set('i', 'jj', '<Esc>', { noremap = true })
-- Restore last cursor position when opening a file
local cursor_group = vim.api.nvim_create_augroup('remember_cursor', { clear = true })
vim.api.nvim_create_autocmd('BufReadPost', {
group = cursor_group,
callback = function()
local line = vim.fn.line('\'"')
if line > 0 and line <= vim.fn.line('$') then
vim.cmd('normal! g`"')
end
end,
})
-- Visual tweaks
vim.api.nvim_set_hl(0, "Normal", { bg = "NONE" })
vim.api.nvim_set_hl(0, 'LineNr', { fg = '#FFFF00' })
vim.api.nvim_set_hl(0, 'NonText', { fg = '#0000FF' })
vim.opt.termguicolors = true
-- Bootstrap Lazy and enable plugins
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup("plugins", {
rocks = {
enabled = false,
},
})
-- reduce visual noise
vim.opt.fillchars = { eob = " " }
-- Easy method for commenting multiple lines in python
vim.keymap.set("v", "<leader>/", ":s/^/#/<CR>", {
desc = "Comment selected lines"
})
-- Create a function for running currently open scripts in neovim
local function run_in_terminal(cmd)
vim.cmd("rightbelow vsplit")
local terminal_buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_win_set_buf(0, terminal_buf)
vim.fn.termopen(cmd, {
buffer = terminal_buf,
})
vim.cmd("startinsert")
end
-- Remap leader r to trigger the run scripts function
-- Best effort: each command only works if its binary is on the system,
-- otherwise the split terminal simply shows the error.
vim.keymap.set("n", "<leader>r", function()
vim.cmd("write")
local ft = vim.bo.filetype
local file = vim.fn.expand("%:p")
local bin = "/tmp/nvim-run-" .. vim.fn.getpid()
local commands = {
cpp = { "bash", "-c", "g++ '" .. file .. "' -o '" .. bin .. "' && '" .. bin .. "'" },
python = { "python3", file },
javascript = { "node", file },
typescript = { "tsx", file },
html = { "xdg-open", file },
}
local cmd = commands[ft]
if cmd then
run_in_terminal(cmd)
else
print("No runner configured for filetype: " .. ft)
end
end)