aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/10-options.lua
blob: 588a6e99b4e87940d52d7e79042dc11b283a91c5 (plain)
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
--[[ 10-options.lua — the global editor options.

Sets every editor-wide option, grouped into themed sections with the rationale for each group.
The low numeric prefix loads it before the `50-*` feature files;
machine-local overrides belong in the untracked `plugin/99-local.lua`, which loads last.
]]

----------------------------------------------------------------------------------------------------
-- General -----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Core behavior: bash as the shell, confirm prompts, shared clipboard, fast `CursorHold`.
`shell` pins shell commands to bash regardless of the login shell.
`confirm` asks instead of failing when a command would discard unsaved changes.
`clipboard` syncs the unnamed register with the system clipboard.
`updatetime` shortens the swap-file write interval and the `CursorHold` delay to one second.
Removing `B` from `cpoptions` makes `\` escape like `CTRL-V` in mappings, abbreviations and user
commands — useful for matching mappings that start with space: `:map \ `. ]]
vim.opt.shell = "/usr/bin/bash"
vim.opt.confirm = true
vim.opt.clipboard = "unnamed"
vim.opt.updatetime = 1000
vim.opt.cpoptions:remove("B")

----------------------------------------------------------------------------------------------------
-- Search & navigation -----------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Searching: smart-cased matches, ripgrep behind `:grep`, `:find` across the whole tree.
`ignorecase` + `smartcase` keep a search case-insensitive until the pattern contains an uppercase
character.
`grepprg` routes `:grep` through ripgrep, which respects `.gitignore` and skips hidden and binary
files by default; `:grep {args}` appends to it, so widen a single invocation with:
  `-.`    also search hidden files (e.g. dotfiles), still skipping `.gitignore`d paths
  `-uu`   also search hidden and `.gitignore`d files (descends into `.git/` too)
  `-uuu`  `-uu` plus binary files
Appending `**` to `path` lets `:find` and `gf` resolve a filename anywhere below the cwd — the
default `.,,` searches the current file's directory and the cwd, `**` adds every directory beneath
it. ]]
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.grepprg = "rg --vimgrep --smart-case"
vim.opt.grepformat = "%f:%l:%c:%m"
vim.opt.path:append("**")
vim.opt.wrapscan = false -- searches don't wrap around eof

----------------------------------------------------------------------------------------------------
-- UI ----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Chrome: capped popup, cursor line, permanent tabline, rounded floats, visible non-printables.
`pumheight` caps the completion popup at 16 lines;
`pumborder` rounds the completion popup's border and `pumwidth` sets its minimum width.
`splitbelow`/`splitright` stay off so new splits open above and to the left.
`cursorline` highlights the cursor's line;
`scrolloff` keeps two screen lines visible above and below it.
`conceallevel` hides text carrying the "conceal" syntax attribute.
`showtabline` always shows the tabline;
`winborder` rounds the outline of floating windows.
`list` shows non-printables with the `listchars` markers: trailing spaces as `-`, non-breakable
spaces as `+`, and `→`/`←` where text continues past the window edge when `wrap` is off (the blank
`tab` value keeps tabs invisible).
`netrw_banner` removes the netrw banner. ]]
vim.opt.pumheight = 16
vim.opt.pumborder = "rounded"
vim.opt.pumwidth = 25
vim.opt.splitbelow = false
vim.opt.splitright = false
vim.opt.cursorline = true
vim.opt.scrolloff = 2
vim.opt.conceallevel = 2
vim.opt.showtabline = 2
vim.opt.winborder = "rounded"
vim.opt.list = true
vim.opt.listchars = {
	tab = "  ",
	trail = "-",
	nbsp = "+",
	extends = "→",
	precedes = "←",
}
vim.g.netrw_banner = 0

----------------------------------------------------------------------------------------------------
-- Bell --------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Bell: emit visual bell events; foot flashes them (`belloff` cleared from its `all` default). ]]
vim.opt.belloff = ""

----------------------------------------------------------------------------------------------------
-- Backup ------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Persistence: swap files, undo history across sessions, and a backup of every overwritten file.
`swapfile` stores a swap file (<nvim-help://swap-file>).
`undofile` saves the undo history so it survives closing the buffer.
`backup` + `writebackup` back a file up before it is overwritten and keep the copy in `backupdir`
(the trailing `//` builds the backup's name from the file's full path, avoiding collisions). ]]
vim.opt.swapfile = true
vim.opt.undofile = true
vim.opt.backup = true
vim.opt.backupdir = { vim.fn.stdpath("state") .. "/backup//" }
vim.opt.writebackup = true

----------------------------------------------------------------------------------------------------
-- Gutter ------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Gutter: hybrid line numbers and always-on sign and fold columns.
`number` + `relativenumber` show the absolute number on the cursor line and relative numbers
elsewhere, and `numberwidth` reserves four columns for them.
`signcolumn` and `foldcolumn` stay visible at a fixed width so the text doesn't shift when signs or
folds appear. ]]
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.numberwidth = 4
vim.opt.signcolumn = "yes"
vim.opt.foldcolumn = "1"

----------------------------------------------------------------------------------------------------
-- Wrapping ----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Wrapping: off by default, readable when toggled on.
`wrap` starts off and is toggled per-window with `<Leader>bw`.
When on, lines break at the characters in `breakat` (`linebreak`), keep their indent
(`breakindent`), and continuations are flagged with `showbreak`'s `+++ `. ]]
vim.opt.wrap = false
vim.opt.showbreak = "+++ "
vim.opt.linebreak = true
vim.opt.breakindent = true

----------------------------------------------------------------------------------------------------
-- Tabs & indentation ------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------

--[[ Indentation: real tab characters, four columns wide, driven by the single `tabstop` knob.
`shiftwidth = 0` makes indent commands follow `tabstop` and `softtabstop = -1` makes `<Tab>`/`<BS>`
follow `shiftwidth`, so changing `tabstop` adjusts everything at once;
`expandtab` stays off to keep real tabs.
See <nvim-help://30.5>. ]]
vim.opt.tabstop = 4
vim.opt.shiftwidth = 0
vim.opt.softtabstop = -1
vim.opt.expandtab = false