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
|
local misc = require("core.misc")
local auto = misc.auto
-- color stuff
if vim.fn.has("termguicolors") then
vim.opt.termguicolors = true
end
-- numbers
vim.opt.number = true
vim.opt.relativenumber = true
-- buffer
vim.opt.scrolloff = 5
vim.opt.wrap = true -- wraping lines
vim.opt.linebreak = true -- fix where line is wraped
vim.opt.cursorline = true
vim.opt.colorcolumn = { 80 }
-- indents + tabs
local tabwidth = 2
vim.opt.expandtab = true
vim.opt.smarttab = true
vim.opt.cindent = true
vim.opt.autoindent = true
vim.opt.tabstop = tabwidth
vim.opt.shiftwidth = tabwidth
vim.opt.softtabstop = tabwidth
-- Schedule the setting after `UiEnter` because it can increase startup-time.
-- (yoinked from kickstart.nvim)
vim.schedule(function()
vim.opt.clipboard = "unnamedplus" -- system clipboard
end)
vim.opt.updatetime = 200
-- file saving
vim.opt.swapfile = false
vim.opt.undofile = true
vim.opt.confirm = true
-- searching
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.wrapscan = true
vim.opt.showmatch = true
vim.opt.incsearch = true
-- wild menus
vim.opt.wildoptions = "pum"
vim.opt.pumblend = 3
vim.opt.pumheight = 20
vim.opt.wildignorecase = true
vim.opt.wildignore = "*.o"
-- netrw
vim.g.netrw_banner = 0
vim.g.netrw_winsize = 30
vim.g.netrw_liststyle = 1
vim.g.netrw_sizestyle = "H"
vim.g.netrw_hide = 1
-- border (this doesn't actually do anything within vim, I"m just setting it
-- here so it"s easy to find)
vim.g.border_style = "solid"
do -- folding
auto("FileType", {
callback = function()
-- use treesitter for folding
if require("nvim-treesitter.parsers").has_parser() then
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
else
vim.opt.foldmethod = "syntax"
end
end
})
vim.opt.foldlevelstart = 99
vim.opt.foldlevel = 99
vim.opt.foldenable = true
vim.o.fillchars = "fold: "
_G.Fold_text = require("core.folding")
vim.opt.foldtext = "v:lua.Fold_text()"
end
do -- statusline
local last_bufnr, i = 1, 1
--- status line
---@return string out formatted status line
function _G.Status()
--- get the percentage through the file
---@return string out the formatted percentage
local function percentage()
local percent, line, lines
-- get the current and total # of lines
line = vim.api.nvim_win_get_cursor(0)[1]
lines = vim.api.nvim_buf_line_count(0)
-- calculate the percentage through the file
percent = math.floor((line / lines) * 100)
if percent == 0 or line == 1 then
return "Top"
elseif percent == 100 or line == lines then
return "Bot"
end
return percent.."%%"
end
--- get the number of lsp servers
---@return string out the formatted number of servers
local function lsp_servers()
local out, nclients, hi
local hi_groups = { "@boolean", "@constant", "@keyword", "@number" }
-- get the number of clients
nclients = #vim.lsp.get_clients({ bufnr = 0 })
-- set the client display
out = "λ"..nclients
if nclients > 0 then
local bufnr = vim.api.nvim_win_get_buf(0)
if bufnr ~= last_bufnr then
last_bufnr = bufnr
i = i + 1
if i > #hi_groups then
i = 1
end
end
hi = "%#"..hi_groups[i].."#"
out = hi..out.."%#StatusLine#"
end
return out
end
return table.concat {
"%t", -- file name
" %h", -- help buffer tag
"%m", -- modify tag
"%r", -- readonly flag
"%=", -- seperate left and right side
-- print out the number of lsp clients attached with nice colors :)
lsp_servers(), " ",
"%<", -- we can start truncating here (I want to keep the file name)
"%l,%c%V", -- line, column-virtual column
"%<", -- we can start truncating here
" "..percentage() -- percentage through the buffer
}
end
vim.opt.statusline="%!v:lua.Status()"
vim.opt.laststatus = 3
end
|