-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·178 lines (141 loc) · 4.17 KB
/
Copy pathinit.lua
File metadata and controls
executable file
·178 lines (141 loc) · 4.17 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
-- Basic settings
vim.o.rnu = true
vim.o.tabstop = 4
vim.o.autoindent = true
-- C-like indentation
grp = vim.api.nvim_create_augroup("c_like_indent", { clear = true })
vim.api.nvim_create_autocmd({"BufRead", "BufNewFile"}, {
group = grp,
pattern = {"*.c", "*.h", "*.cpp", "*.cu", ".cuh", "*.asm"},
callback = function()
vim.bo.cindent = true
vim.bo.shiftwidth = 4
vim.bo.tabstop = 4
vim.bo.softtabstop = 4
vim.bo.expandtab = true
end,
})
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
pattern = { "*.cu", "*.cuh" },
callback = function()
vim.bo.filetype = "cpp"
end,
})
require("config.lazy")
-- Keymaps
local map = vim.keymap.set
map('n', '<Tab>', ':bnext<CR>')
map('n', '<S-Tab>', ':bprevious<CR>')
map('n', '<C-d>', '<C-d>zz')
map('n', '<C-u>', '<C-u>zz')
map('n', '[u', '?^\\S<CR>')
map('n', ']u', '/^\\S<CR>')
map('n', '<C-y>', '"+yy<CR>')
map('v', '<C-y>', '"+y<CR>')
map('v', '<C-y>', '"+y<CR>')
map("n", "<C-;>", "gcc", { remap = true })
map("v", "<C-;>", "gc", { remap = true })
map('n', '<Delete>', '"_dd')
map('n', 'x', '"_x')
map('n', 'n', 'nzz')
map('n', 'N', 'Nzz')
map('n', '<C-u>', '<C-u>zz')
map('n', '<C-d>', '<C-d>zz')
vim.keymap.set({'n', 'v', 'i'}, '<S-Left>', '<Nop>')
vim.keymap.set({'n', 'v', 'i'}, '<S-Right>', '<Nop>')
vim.keymap.set({'n', 'v', 'i'}, '<S-Up>', '<Nop>')
vim.keymap.set({'n', 'v', 'i'}, '<S-Down>', '<Nop>')
vim.keymap.set('v', 'u', '<Nop>')
vim.keymap.set('v', 'U', '<Nop>')
vim.keymap.set('v', '~', '<Nop>')
vim.keymap.set('n', 'gu', '<Nop>')
vim.keymap.set('n', 'gU', '<Nop>')
vim.keymap.set('n', '~', '<Nop>')
-- Insert mode: auto braces
vim.cmd [[inoremap { {<CR>}<up><end><CR>]]
-- Session on exit
vim.api.nvim_create_autocmd("VimLeavePre", {
callback = function() vim.cmd('mksession! ~/.vim_session') end
})
vim.o.hlsearch = false
-- Swap upper-case markers --
local mark_file = vim.fn.stdpath("data") .. "/my_global_marks.json"
local MyMarks = {}
local function load_marks()
local f = io.open(mark_file, "r")
if not f then return end
local data = f:read("*a")
f:close()
local ok, decoded = pcall(vim.json.decode, data)
if ok and type(decoded) == "table" then
MyMarks = decoded
end
end
load_marks()
local function save_marks()
local f = io.open(mark_file, "w")
if not f then return end
f:write(vim.json.encode(MyMarks))
f:close()
end
local function set_global_mark()
local c = vim.fn.nr2char(vim.fn.getchar())
if not c:match("%a") then return end
local pos = vim.api.nvim_win_get_cursor(0)
MyMarks[c] = {
file = vim.api.nvim_buf_get_name(0),
lnum = pos[1],
col = pos[2],
}
save_marks()
end
local function jump_global_mark()
local c = vim.fn.nr2char(vim.fn.getchar())
local m = MyMarks[c]
if not m or m.file == "" then return end
vim.schedule(function()
vim.cmd("edit " .. vim.fn.fnameescape(m.file))
vim.api.nvim_win_set_cursor(0, {m.lnum, m.col})
end)
end
vim.keymap.set('n', 'm', set_global_mark, { noremap = true })
vim.keymap.set('n', "'", jump_global_mark, { noremap = true })
vim.keymap.set('n', '`', jump_global_mark, { noremap = true })
vim.keymap.set('n', '~', jump_global_mark, { noremap = true })
--
-- Session options
vim.o.sessionoptions = 'blank,buffers,curdir,folds,help,options,tabpages,winsize'
-- Colorscheme
vim.cmd('colorscheme ghdark')
-- Transparency toggle
vim.g.t_is_transparent = 0
function Toggle_transparent()
if vim.g.t_is_transparent == 0 then
vim.cmd('hi Normal guibg=NONE ctermbg=NONE')
vim.g.t_is_transparent = 1
else
vim.cmd('set background=dark')
vim.g.t_is_transparent = 0
end
end
map('n', '<C-t>', Toggle_transparent)
-- Transparent by default
grp2 = vim.api.nvim_create_augroup("TransparentBG", { clear = true })
vim.api.nvim_create_autocmd("VimEnter", {
group = grp2,
callback = function()
vim.cmd('hi Normal guibg=NONE ctermbg=NONE')
end,
})
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", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)