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
|
function map(mode, shortcut, command)
vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
end
function nmap(shortcut, command)
map('n', shortcut, command)
end
function imap(shortcut, command)
map('i', shortcut, command)
end
---------------------------------------------------
-- General
---------------------------------------------------
-- Set the amount of lines of history to remember.
vim.opt.history = 100
-- Set a mapleader key. This is used for extra key combinations.
vim.g.mapleader = "\\"
nmap("<Space>", "<leader>")
-- Better command line completion.
vim.opt.wildmenu = true
vim.opt.wildmode = "list:longest,full"
-- Ignore compiled and binary files.
vim.opt.wildignore = "*.o,*~,*.pyc,*.png,*.pdf"
-- Filetypes
vim.api.nvim_create_autocmd(
{
"BufNewFile",
"BufRead",
},
{
pattern = "*.irst",
callback = function()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_vim.opt_option(buf, "filetype", "rst")
end
}
)
vim.api.nvim_create_autocmd(
{
"BufNewFile",
"BufRead",
},
{
pattern = "*.puml",
callback = function()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_vim.opt_option(buf, "filetype", "plantuml")
end
}
)
vim.api.nvim_create_autocmd(
{
"BufNewFile",
"BufRead",
},
{
pattern = "*.tikz",
callback = function()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_vim.opt_option(buf, "filetype", "tex")
end
}
)
vim.api.nvim_create_autocmd(
{
"BufNewFile",
"BufRead",
},
{
pattern = "*.tpp",
callback = function()
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_vim.opt_option(buf, "filetype", "cpp")
end
}
)
-- TODO: Restore last known cursor position, see https://github.com/neovim/neovim/issues/16339.
-- Set the swap directory to ~/.cache/nvim/swap.
local cache = vim.env.XDG_CACHE_HOME or vim.fn.expand("~/.cache")
local swap = cache .. "/nvim/swap"
if vim.fn.isdirectory(swap) == 0 then
vim.fn.mkdir(swap, 'p', 0700)
end
-- The extra '/' suffix is required to make vim create unique filenames.
-- XXX: Not sure if this is required in neovim however.
vim.opt.dir = { swap .. "//" }
-- Use system clipboard by default.
vim.opt.clipboard = "unnamedplus"
---------------------------------------------------
-- User interface
---------------------------------------------------
-- Display line numbers.
vim.opt.number = true
vim.opt.relativenumber = true
-- Show the (partial) command in status line.
vim.opt.showcmd = true
-- Always display the status line, even if only one window is displayed.
vim.opt.laststatus = 2
-- Shows a dialogue asking if the file has to be saved, instead of raising an
-- error.
vim.opt.confirm = true
-- Keep the cursor in the centre of the buffer if possible.
vim.opt.scrolloff = 10000
-- Disable automatic folding.
-- vim.opt.nofoldenable = true
-- Delete the current buffer without closing the windows
nmap("<leader>bd", ":Bdelete<CR>")
-- Close window
nmap("<leader>wd", ":q<CR>")
-- Vertical split
nmap("<leader>wv", ":vsplit<CR>")
-- Horizontal split
nmap("<leader>wh", ":split<CR>")
-- Exit vim
nmap("<leader>qq", ":qa<CR>")
-- Easy vertical terminal split opening (why is this not built-in?)
-- cnoreabbrev vterm vert term
-- Set filetype.
vim.opt.ffs = "unix"
vim.opt.termguicolors = true
vim.opt.colorcolumn = "80"
vim.opt.splitbelow = true
vim.opt.splitright = true
---------------------------------------------------
-- Search
--------------------------------------------------
vim.opt.ignorecase = true
vim.opt.smartcase = true
nmap("<C-L>", ":nohl<CR><C-L>")
vim.env.MANSECT = "3p:3:2:1:n:l:8:0:5:4:9:6:7"
---------------------------------------------------
-- Text (tab, spaces, indent)
---------------------------------------------------
vim.bo.softtabstop = 2
vim.opt.autoindent = true
vim.opt.expandtab = true
vim.opt.listchars = { tab = "»-", trail = "·" }
vim.opt.shiftwidth = 2
vim.opt.tabstop = 2
|