-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroot_init.lua
More file actions
157 lines (128 loc) · 3.92 KB
/
Copy pathroot_init.lua
File metadata and controls
157 lines (128 loc) · 3.92 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
-- root init.lua
-- @leaders and debug
-- @Options
-- @Keymaps
-- @Statusline
-- @Terminal
-- @Leaders
vim.g.mapleader = ";"
vim.g.localmapleader = ";"
-- Debug
-- <Leader>e to edit $MYVIMRC
vim.cmd("set autochdir")
vim.o.visualbell = true
vim.keymap.set("n", "<Leader>e", ":e $MYVIMRC<CR>", { desc = "Edits init file of the config"} )
vim.keymap.set("n", "<Leader>s", ":source<CR>", { desc = "Sources current lua file" })
-- @Options
vim.o.timeoutlen = 1000
vim.o.backup = true
vim.o.number = true
vim.o.wrap = true
vim.o.incsearch = true
vim.o.hlsearch = false
vim.o.signcolumn = "number"
vim.o.autoindent = true
vim.o.tabstop = 2
vim.o.shiftwidth = 2
vim.o.expandtab = true
vim.o.wildmenu = true
vim.o.mouse = "a"
vim.o.clipboard = "unnamedplus"
vim.o.cursorline = true
vim.o.scrolloff = 10
vim.opt.fileformats = { "unix", "dos" }
vim.cmd [[
filetype indent plugin on
syntax on
]]
vim.o.encoding = "utf-8"
-- vim.o.backupdir = vim.fn.expand("~/.neovim/backups/")
-- vim.o.undodir = vim.fn.expand("~/.neovim/undo/")
-- vim.o.directory = vim.fn.expand("~/.neovim/swp/")
-- @Keymaps
keymaps = {
-- jj to escape
{"i", "jj", "<Esc>", { desc = "Escapes to normal mode" }},
-- <Leader>w and q to save and quit respectively
{"n", "<Leader>w", ":w!<CR>", { desc = "Saves buffer" } },
{"n", "<Leader>q", ":q<CR>", { desc = "Closes buffer" } },
{"n", "<Leader>Q", ":quitall<CR>", { desc = "Quits neovim" } },
-- Tab controls
{"n", ",,", ":tabnew<CR>", { desc = "Opens a new tab" } },
{"n", "+", ":tablast<CR>", { desc = "Goes to last tab" } },
{"n", "_", ":tabfirst<CR>", { desc = "Goes to first tab" } },
{"n", "-", ":tabprevious<CR>", { desc = "Goes to previous tab" } },
{"n", "=", ":tabnext<CR>", { desc = "Goes to next tab" } },
-- Resize splits with Ctrl + arrows,
{"n", "<C-Up>", ":resize +1<CR>", { desc = "Resize vsplit +1" } },
{"n", "<C-Down>", ":resize -1<CR>", { desc = "Resize vsplit -1" } },
{"n", "<C-Right>", ":vertical resize +1<CR>", { desc = "Resize hsplit +1"}},
{"n", "<C-Left>", ":vertical resize -1<CR>", { desc = "Resize hsplit -1"} },
{"n", "<Leader>bd", "bufdo bd!", { desc = "Close all buffers except current one" }}
}
for _, keymap in ipairs(keymaps) do
vim.keymap.set(unpack(keymap))
end
-- @Statusline
Statusline = {}
Statusline.format = {
padding = "",
user = vim.fn.expand("$USER"),
file = "%F",
filetype = "%Y",
modified = "%m",
splitter = "%=",
lines = "(%l/%L)",
mode = function() return vim.fn.mode() end
}
Statusline.short = function()
return table.concat({
Statusline.format.padding,
Statusline.format.mode(),
Statusline.format.file,
Statusline.format.filetype,
Statusline.format.padding,
}, " ")
end
Statusline.default = function()
return table.concat({
Statusline.format.padding,
Statusline.format.user,
Statusline.format.mode(),
Statusline.format.file,
Statusline.format.filetype,
Statusline.format.lines,
Statusline.format.modified,
Statusline.format.splitter,
os.date('%c'),
Statusline.format.padding,
}, " ")
end
vim.o.laststatus = 2
vim.o.showmode = false
vim.api.nvim_create_autocmd({"BufEnter", "WinEnter"}, {
pattern = "*",
callback = function()
vim.opt_local.statusline = "%!v:lua.Statusline.default()"
end
})
vim.api.nvim_create_autocmd({"TermEnter", "TermOpen"}, {
pattern = "*",
callback = function()
vim.opt_local.statusline = "%!v:lua.Statusline.short()"
end
})
-- @Terminal
-- Set shell as pwsh if on windows
-- Terminal mode escape
vim.keymap.set("t", "<Esc>", "<C-\\><C-n>", { desc = "Terminal mode escape" } )
vim.keymap.set("n", "<Leader>T", ":term<CR>", { desc = "Opens terminal" })
vim.api.nvim_create_autocmd({"TermOpen","TermEnter"},{
pattern = "*",
command = "setlocal nonumber norelativenumber"
})
-- Reset statusline when exiting terminal
vim.api.nvim_create_autocmd({"TermClose","TermLeave"},{
pattern = "*",
command = "set statusline=%!v:lua.Statusline.default()"
})