2021-12-24 21:00:00 +00:00
|
|
|
local M = {}
|
|
|
|
|
2021-11-06 09:28:29 +00:00
|
|
|
local function set_autocmd()
|
2022-01-09 00:07:35 +00:00
|
|
|
vim.cmd [[
|
2021-11-06 09:28:29 +00:00
|
|
|
autocmd BufRead,BufNewFile *.test set filetype=php
|
2021-11-17 18:31:08 +00:00
|
|
|
|
2021-11-06 09:28:29 +00:00
|
|
|
autocmd FileType gitcommit highlight ColorColumn ctermbg=8
|
|
|
|
autocmd FileType gitcommit setlocal colorcolumn=50,72
|
|
|
|
autocmd FileType gitcommit setlocal spell
|
|
|
|
autocmd FileType gitcommit setlocal textwidth=72
|
|
|
|
]]
|
2022-06-21 22:52:24 +01:00
|
|
|
|
2022-07-12 09:29:04 +01:00
|
|
|
-- Cursorline highlighting control.
|
|
|
|
-- Only have it on in the current buffer.
|
|
|
|
local group = vim.api.nvim_create_augroup("CursorLineControl", { clear = true })
|
|
|
|
local set_cursorline = function(event, value, pattern)
|
|
|
|
vim.api.nvim_create_autocmd(event, {
|
|
|
|
group = group,
|
|
|
|
pattern = pattern,
|
|
|
|
callback = function()
|
|
|
|
vim.opt_local.cursorline = value
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
set_cursorline("WinLeave", false)
|
|
|
|
set_cursorline("WinEnter", true)
|
|
|
|
set_cursorline("FileType", false, "TelescopePrompt")
|
2023-01-30 21:59:16 +00:00
|
|
|
|
|
|
|
vim.api.nvim_create_autocmd("TermOpen", {
|
|
|
|
callback = function()
|
|
|
|
vim.cmd.set "filetype=term"
|
|
|
|
end,
|
|
|
|
})
|
2021-11-06 09:28:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function set_filetypes()
|
2022-01-09 00:07:35 +00:00
|
|
|
vim.cmd [[
|
2021-11-06 09:28:29 +00:00
|
|
|
filetype indent on
|
|
|
|
filetype on
|
|
|
|
filetype plugin on
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_key_mappings()
|
|
|
|
local map = vim.api.nvim_set_keymap
|
|
|
|
|
|
|
|
local options = { noremap = true }
|
|
|
|
|
2022-01-09 23:22:04 +00:00
|
|
|
map("n", "<Leader>so", ":call opdavies#save_and_exec()<CR>", options)
|
2021-11-06 09:28:29 +00:00
|
|
|
|
2022-01-02 10:26:14 +00:00
|
|
|
-- Format paragraphs to an 80 character line length.
|
2022-01-09 00:07:35 +00:00
|
|
|
map("n", "<Leader>g", "gqap", options)
|
|
|
|
map("x", "<Leader>g", "gqa", options)
|
2022-01-02 10:26:14 +00:00
|
|
|
|
2021-11-06 09:28:29 +00:00
|
|
|
-- Make the current file executable
|
2022-01-09 00:07:35 +00:00
|
|
|
map("n", "<Leader>x", ":!chmod +x %<Cr>", options)
|
2021-11-06 09:28:29 +00:00
|
|
|
|
|
|
|
-- Yank from the current column to the end of the line
|
2022-01-09 00:07:35 +00:00
|
|
|
map("n", "Y", "yg$", options)
|
2021-11-06 09:28:29 +00:00
|
|
|
|
|
|
|
-- Keep things centred
|
2022-01-09 00:07:35 +00:00
|
|
|
map("n", "n", "nzzzv", options)
|
|
|
|
map("n", "N", "Nzzzv", options)
|
2021-11-06 09:28:29 +00:00
|
|
|
|
|
|
|
-- Remove arrow keys
|
2022-01-09 00:07:35 +00:00
|
|
|
map("v", "<down>", "<nop>", options)
|
|
|
|
map("v", "<left>", "<nop>", options)
|
|
|
|
map("v", "<right>", "<nop>", options)
|
|
|
|
map("v", "<up>", "<nop>", options)
|
2021-11-06 09:28:29 +00:00
|
|
|
|
|
|
|
-- Clears hlsearch after doing a search, otherwise just does normal <CR> stuff
|
2022-01-09 00:07:35 +00:00
|
|
|
vim.cmd [[ nnoremap <expr> <CR> {-> v:hlsearch ? ":nohl\<CR>" : "\<CR>"}() ]]
|
|
|
|
|
|
|
|
map("n", "<C-f>", ":silent !tmux neww tmux-sessioniser<CR>", { noremap = true, silent = true })
|
2022-08-16 13:37:01 +01:00
|
|
|
|
2022-06-21 22:52:24 +01:00
|
|
|
local keymap = require "opdavies.keymap"
|
|
|
|
local imap = keymap.imap
|
|
|
|
local nmap = keymap.nmap
|
2022-08-09 15:24:04 +01:00
|
|
|
local vmap = keymap.vmap
|
2022-06-21 22:52:24 +01:00
|
|
|
local xmap = keymap.xmap
|
2022-08-16 13:37:01 +01:00
|
|
|
|
2022-03-30 14:11:30 +01:00
|
|
|
-- Easy insertion of a trailing ; or , from insert mode
|
2022-05-03 08:56:44 +01:00
|
|
|
imap { ",,", "<Esc>A,<Esc>" }
|
|
|
|
imap { ";;", "<Esc>A;<Esc>" }
|
2022-06-08 08:50:26 +01:00
|
|
|
|
|
|
|
nmap { "ga", "<Plug>(EasyAlign)" }
|
|
|
|
xmap { "ga", "<Plug>(EasyAlign)" }
|
2022-06-21 22:52:24 +01:00
|
|
|
|
|
|
|
-- Focus on the current buffer.
|
2022-08-16 13:37:01 +01:00
|
|
|
nmap { "<leader>-", ":wincmd _<cr>:wincmd |<cr>", { noremap = true, silent = true } }
|
2022-06-21 22:52:24 +01:00
|
|
|
|
|
|
|
-- Automatically resize buffers.
|
2022-08-16 13:37:01 +01:00
|
|
|
nmap { "<leader>=", ":wincmd =<cr>", { noremap = true, silent = true } }
|
2022-08-09 15:24:04 +01:00
|
|
|
|
|
|
|
-- Move line(s) up and down.
|
|
|
|
local opts = { noremap = true, silent = true }
|
|
|
|
imap { "<M-j>", "<Esc>:m .+1<CR>==gi", opts }
|
|
|
|
imap { "<M-k>", "<Esc>:m .-2<CR>==gi", opts }
|
|
|
|
nmap { "<M-j>", ":m .+1<CR>==", opts }
|
|
|
|
nmap { "<M-k>", ":m .-2<CR>==", opts }
|
|
|
|
vmap { "<M-j>", ":m '>+1<CR>gv=gv", opts }
|
|
|
|
vmap { "<M-k>", ":m '<-2<CR>gv=gv", opts }
|
2022-09-01 22:01:42 +01:00
|
|
|
|
|
|
|
-- Move half a screen up or down and re-center.
|
|
|
|
nmap { "<C-d>", "<C-d>zz" }
|
|
|
|
nmap { "<C-u>", "<C-u>zz" }
|
2021-11-06 09:28:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function set_highlights()
|
2022-01-09 00:07:35 +00:00
|
|
|
vim.cmd [[highlight Comment cterm=italic gui=italic]]
|
2021-11-06 09:28:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function set_vim_g()
|
2022-01-09 00:07:35 +00:00
|
|
|
vim.g.mapleader = " "
|
2021-11-06 09:28:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function set_vim_o()
|
|
|
|
local settings = {
|
|
|
|
autoindent = true,
|
2023-10-29 23:13:08 +00:00
|
|
|
backup = false,
|
2021-11-06 09:28:29 +00:00
|
|
|
breakindent = true,
|
2021-12-23 00:56:45 +00:00
|
|
|
conceallevel = 0,
|
2022-01-09 22:29:04 +00:00
|
|
|
cursorline = true,
|
2021-11-06 09:28:29 +00:00
|
|
|
expandtab = true,
|
2021-12-17 23:23:51 +00:00
|
|
|
foldlevel = 1,
|
2022-01-29 00:50:33 +00:00
|
|
|
foldlevelstart = 99,
|
2022-01-09 00:07:35 +00:00
|
|
|
foldmethod = "indent",
|
|
|
|
formatoptions = "lm",
|
2022-03-02 19:41:17 +00:00
|
|
|
hidden = false,
|
2023-06-04 14:04:08 +01:00
|
|
|
inccommand = "split",
|
2021-11-06 09:28:29 +00:00
|
|
|
linebreak = true,
|
2024-01-14 17:15:41 +00:00
|
|
|
list = true,
|
2022-01-09 00:07:35 +00:00
|
|
|
mouse = "n",
|
2021-11-06 09:28:29 +00:00
|
|
|
number = true,
|
2021-11-09 08:25:06 +00:00
|
|
|
pumblend = 10,
|
2021-12-23 00:56:45 +00:00
|
|
|
pumheight = 10,
|
2021-11-06 09:28:29 +00:00
|
|
|
relativenumber = true,
|
|
|
|
scrolloff = 10,
|
|
|
|
shiftwidth = 2,
|
2021-12-23 00:56:45 +00:00
|
|
|
showmode = false,
|
2023-04-30 10:52:47 +01:00
|
|
|
signcolumn = "yes:1",
|
2021-11-06 09:28:29 +00:00
|
|
|
smartindent = true,
|
|
|
|
softtabstop = 2,
|
2023-12-21 08:26:21 +00:00
|
|
|
splitbelow = false,
|
2021-12-23 00:56:45 +00:00
|
|
|
splitright = true,
|
2021-11-06 09:28:29 +00:00
|
|
|
swapfile = false,
|
2022-01-09 00:07:35 +00:00
|
|
|
syntax = "on",
|
2021-11-06 09:28:29 +00:00
|
|
|
tabstop = 2,
|
|
|
|
termguicolors = true,
|
2022-01-02 10:26:14 +00:00
|
|
|
textwidth = 0,
|
2023-10-29 23:13:08 +00:00
|
|
|
undodir = os.getenv("HOME") .. "/.vim/undodir",
|
|
|
|
undofile = true,
|
2021-11-06 09:28:29 +00:00
|
|
|
updatetime = 1000,
|
2022-01-29 00:48:55 +00:00
|
|
|
wrap = false,
|
2021-11-06 09:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for key, value in pairs(settings) do
|
|
|
|
vim.o[key] = value
|
|
|
|
end
|
|
|
|
|
2023-09-04 11:05:13 +01:00
|
|
|
vim.opt.backupdir:remove "." -- keep backups out of the current directory
|
2022-01-09 00:07:35 +00:00
|
|
|
vim.opt.clipboard:append "unnamedplus"
|
2024-01-14 17:15:41 +00:00
|
|
|
vim.opt.listchars:append {
|
|
|
|
trail = "·",
|
|
|
|
}
|
2022-03-22 21:27:38 +00:00
|
|
|
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
2022-03-23 19:36:19 +00:00
|
|
|
vim.opt.laststatus = 3
|
2021-11-06 09:28:29 +00:00
|
|
|
end
|
|
|
|
|
2021-12-24 21:00:00 +00:00
|
|
|
M.setup = function()
|
2021-11-17 18:46:51 +00:00
|
|
|
set_vim_g()
|
|
|
|
set_vim_o()
|
|
|
|
set_key_mappings()
|
2021-11-06 09:28:29 +00:00
|
|
|
set_autocmd()
|
|
|
|
set_filetypes()
|
|
|
|
set_highlights()
|
2022-01-08 18:08:41 +00:00
|
|
|
|
|
|
|
vim.g.snippets = "luasnip"
|
2021-11-06 09:28:29 +00:00
|
|
|
end
|
|
|
|
|
2021-12-24 21:00:00 +00:00
|
|
|
return M
|