summaryrefslogtreecommitdiff
path: root/home/.config/nvim/init.lua
blob: d3ca6dc791756ae96b072e7c4c56996f766f03eb (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
vim.opt.tabstop		= 4     	-- Number of spaces that a <Tab> in the file counts for.
vim.opt.shiftwidth 	= 0    		-- Number of spaces to use for each step of (auto)indent.
vim.opt.expandtab 	= false 	-- Do not use the appropriate number of spaces to insert a <Tab>.
vim.opt.showmatch	= true  	-- When a bracket is inserted, briefly jump to the matching
vim.opt.ignorecase	= true      -- Ignore case in search patterns.
vim.opt.smartcase	= true      -- Override 'ignorecase' if the pattern contains upper case

vim.opt.background	= dark
vim.opt.mouse = ""				-- Disable mouse

vim.opt.number		= true

if vim.fn.has('nvim-0.10.0') == 1 then
	vim.cmd("colorscheme vim")
end

vim.keymap.set('', '<M-Up>', ':move-2<CR>', { silent = true })
vim.keymap.set('', '<M-Down>', ':move+1<CR>', { silent = true })
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>', { silent = true })

--auto decrypt/encrypt with gpg

local gpgGroup = vim.api.nvim_create_augroup('customGpg', { clear = true })

-- autocmds execute in the order in which they were defined.
-- https://neovim.io/doc/user/autocmd.html#autocmd-define

vim.api.nvim_create_autocmd({ 'BufReadPre', 'FileReadPre' }, {
    pattern = '*.gpg',
    group = gpgGroup,
    callback = function ()
        -- Make sure nothing is written to shada file while editing an encrypted file.
        vim.opt_local.shada = nil
        -- We don't want a swap file, as it writes unencrypted data to disk
        vim.opt_local.swapfile = false
        -- Switch to binary mode to read the encrypted file
        vim.opt_local.bin = true

        vim.cmd("let ch_save = &ch|set ch=2")
    end
})

vim.api.nvim_create_autocmd({ 'BufReadPost', 'FileReadPost' }, {
    pattern = '*.gpg',
    group = gpgGroup,
    callback = function ()
        vim.cmd("'[,']!gpg --decrypt 2> /dev/null")

        -- Switch to normal mode for editing
        vim.opt_local.bin = false

        vim.cmd('let &ch = ch_save|unlet ch_save')
        vim.cmd(":doautocmd BufReadPost " .. vim.fn.expand("%:r"))
    end
})

-- Convert all text to encrypted text before writing
vim.api.nvim_create_autocmd({ 'BufWritePre', 'FileWritePre' }, {
    pattern = '*.gpg',
    group = gpgGroup,
    command = "'[,']!gpg --default-recipient-self -ae 2>/dev/null",
})
-- Undo the encryption so we are back in the normal text, directly
-- after the file has been written.
vim.api.nvim_create_autocmd({ 'BufWritePost', 'FileWritePost' }, {
    pattern = '*.gpg',
    group = gpgGroup,
    command = 'u'
})