Update options and keymaps
This commit is contained in:
parent
129a2dc990
commit
662ff52b9a
|
@ -2,7 +2,7 @@ pcall("require", impatient)
|
||||||
|
|
||||||
require "opdavies.globals"
|
require "opdavies.globals"
|
||||||
|
|
||||||
require("opdavies.options").setup()
|
require "opdavies.options"
|
||||||
|
|
||||||
require "opdavies.lsp"
|
require "opdavies.lsp"
|
||||||
|
|
||||||
|
@ -12,11 +12,3 @@ require "opdavies.telescope.mappings"
|
||||||
vim.api.nvim_create_user_command("GoToFile", function()
|
vim.api.nvim_create_user_command("GoToFile", function()
|
||||||
require("opdavies.telescope").git_files()
|
require("opdavies.telescope").git_files()
|
||||||
end, {})
|
end, {})
|
||||||
|
|
||||||
local imap = require("opdavies.keymap").imap
|
|
||||||
local nmap = require("opdavies.keymap").nmap
|
|
||||||
local xmap = require("opdavies.keymap").xmap
|
|
||||||
|
|
||||||
-- Quicker macro playback.
|
|
||||||
nmap { "Q", "@qj" }
|
|
||||||
xmap { "Q", ":norm @q<CR>" }
|
|
||||||
|
|
74
lua/opdavies/keymaps.lua
Normal file
74
lua/opdavies/keymaps.lua
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
local keymap = require "opdavies.keymap"
|
||||||
|
|
||||||
|
local imap = keymap.imap
|
||||||
|
local nmap = keymap.nmap
|
||||||
|
local vmap = keymap.vmap
|
||||||
|
local xmap = keymap.xmap
|
||||||
|
|
||||||
|
nmap { "<Leader>so", ":call opdavies#save_and_exec()<CR>" }
|
||||||
|
|
||||||
|
-- Format paragraphs to an 80 character line length.
|
||||||
|
nmap { "<Leader>g", "gqap" }
|
||||||
|
xmap { "<Leader>g", "gqa" }
|
||||||
|
|
||||||
|
-- Make the current file executable
|
||||||
|
nmap { "<Leader>x", ":!chmod +x %<Cr>" }
|
||||||
|
|
||||||
|
-- Yank from the current column to the end of the line
|
||||||
|
nmap { "Y", "yg$" }
|
||||||
|
|
||||||
|
-- Keep things centred
|
||||||
|
nmap { "n", "nzzzv" }
|
||||||
|
nmap { "N", "Nzzzv" }
|
||||||
|
|
||||||
|
-- Disable arrow keys
|
||||||
|
vmap { "<down>", "<nop>" }
|
||||||
|
vmap { "<left>", "<nop>" }
|
||||||
|
vmap { "<right>", "<nop>" }
|
||||||
|
vmap { "<up>", "<nop>" }
|
||||||
|
|
||||||
|
nmap { "<C-f>", ":silent !tmux neww t<CR>", { noremap = true, silent = true } }
|
||||||
|
|
||||||
|
-- Easy insertion of a trailing ; or , from insert mode
|
||||||
|
imap { ",,", "<Esc>A,<Esc>" }
|
||||||
|
imap { ";;", "<Esc>A;<Esc>" }
|
||||||
|
|
||||||
|
nmap { "ga", "<Plug>(EasyAlign)" }
|
||||||
|
xmap { "ga", "<Plug>(EasyAlign)" }
|
||||||
|
|
||||||
|
-- Focus on the current buffer.
|
||||||
|
nmap { "<leader>-", ":wincmd _<cr>:wincmd |<cr>", { noremap = true, silent = true } }
|
||||||
|
|
||||||
|
-- Automatically resize buffers.
|
||||||
|
nmap { "<leader>=", ":wincmd =<cr>", { noremap = true, silent = true } }
|
||||||
|
|
||||||
|
-- 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 }
|
||||||
|
|
||||||
|
-- Re-centre when navigating.
|
||||||
|
nmap { "#", "#zz", opts }
|
||||||
|
nmap { "%", "%zz", opts }
|
||||||
|
nmap { "*", "*zz", opts }
|
||||||
|
nmap { "<C-d>", "<C-d>zz", opts }
|
||||||
|
nmap { "<C-i>", "<C-i>zz", opts }
|
||||||
|
nmap { "<C-o>", "<C-o>zz", opts }
|
||||||
|
nmap { "<C-u>", "<C-u>zz", opts }
|
||||||
|
nmap { "G", "Gzz", opts }
|
||||||
|
nmap { "N", "Nzz", opts }
|
||||||
|
nmap { "gg", "ggzz", opts }
|
||||||
|
nmap { "n", "Nzz", opts }
|
||||||
|
nmap { "{", "{zz", opts }
|
||||||
|
nmap { "}", "}zz", opts }
|
||||||
|
|
||||||
|
-- Clears hlsearch after doing a search, otherwise just does normal <CR> stuff
|
||||||
|
vim.cmd [[ nnoremap <expr> <CR> {-> v:hlsearch ? ":nohl\<CR>" : "\<CR>"}() ]]
|
||||||
|
|
||||||
|
-- Quicker macro playback.
|
||||||
|
nmap { "Q", "@qj" }
|
||||||
|
xmap { "Q", ":norm @q<CR>" }
|
|
@ -1,175 +1,60 @@
|
||||||
local M = {}
|
vim.g.mapleader = " "
|
||||||
|
vim.g.snippets = "luasnip"
|
||||||
|
|
||||||
local function set_autocmd()
|
local settings = {
|
||||||
vim.cmd [[
|
autoindent = true,
|
||||||
autocmd BufRead,BufNewFile *.test set filetype=php
|
backup = false,
|
||||||
|
breakindent = true,
|
||||||
|
expandtab = true,
|
||||||
|
foldlevel = 1,
|
||||||
|
foldlevelstart = 99,
|
||||||
|
foldmethod = "indent",
|
||||||
|
formatoptions = "clqjp",
|
||||||
|
hidden = false,
|
||||||
|
inccommand = "split",
|
||||||
|
linebreak = true,
|
||||||
|
list = true,
|
||||||
|
mouse = "",
|
||||||
|
number = true,
|
||||||
|
pumblend = 10,
|
||||||
|
pumheight = 10,
|
||||||
|
relativenumber = true,
|
||||||
|
scrolloff = 5,
|
||||||
|
shiftwidth = 2,
|
||||||
|
showmode = false,
|
||||||
|
signcolumn = "yes:1",
|
||||||
|
smartindent = true,
|
||||||
|
softtabstop = 2,
|
||||||
|
swapfile = false,
|
||||||
|
syntax = "on",
|
||||||
|
tabstop = 2,
|
||||||
|
termguicolors = true,
|
||||||
|
textwidth = 0,
|
||||||
|
undodir = os.getenv("HOME") .. "/.vim/undodir",
|
||||||
|
undofile = true,
|
||||||
|
updatetime = 1000,
|
||||||
|
wrap = false,
|
||||||
|
}
|
||||||
|
|
||||||
autocmd FileType gitcommit highlight ColorColumn ctermbg=8
|
for key, value in pairs(settings) do
|
||||||
autocmd FileType gitcommit setlocal colorcolumn=50,72
|
vim.o[key] = value
|
||||||
autocmd FileType gitcommit setlocal spell
|
|
||||||
autocmd FileType gitcommit setlocal textwidth=72
|
|
||||||
]]
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("TermOpen", {
|
|
||||||
callback = function()
|
|
||||||
vim.cmd.set "filetype=term"
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_filetypes()
|
vim.opt.backupdir:remove "." -- keep backups out of the current directory
|
||||||
vim.cmd [[
|
vim.opt.clipboard:append "unnamedplus"
|
||||||
filetype indent on
|
vim.opt.completeopt = { "menu", "menuone", "noinsert", "noselect" }
|
||||||
filetype on
|
vim.opt.laststatus = 3
|
||||||
filetype plugin on
|
vim.opt.listchars:append {
|
||||||
]]
|
trail = "·",
|
||||||
end
|
}
|
||||||
|
|
||||||
local function set_key_mappings()
|
vim.cmd [[
|
||||||
local map = vim.api.nvim_set_keymap
|
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
|
||||||
|
|
||||||
local options = { noremap = true }
|
filetype indent on
|
||||||
|
filetype on
|
||||||
map("n", "<Leader>so", ":call opdavies#save_and_exec()<CR>", options)
|
filetype plugin on
|
||||||
|
]]
|
||||||
-- Format paragraphs to an 80 character line length.
|
|
||||||
map("n", "<Leader>g", "gqap", options)
|
|
||||||
map("x", "<Leader>g", "gqa", options)
|
|
||||||
|
|
||||||
-- Make the current file executable
|
|
||||||
map("n", "<Leader>x", ":!chmod +x %<Cr>", options)
|
|
||||||
|
|
||||||
-- Yank from the current column to the end of the line
|
|
||||||
map("n", "Y", "yg$", options)
|
|
||||||
|
|
||||||
-- Keep things centred
|
|
||||||
map("n", "n", "nzzzv", options)
|
|
||||||
map("n", "N", "Nzzzv", options)
|
|
||||||
|
|
||||||
-- Remove arrow keys
|
|
||||||
map("v", "<down>", "<nop>", options)
|
|
||||||
map("v", "<left>", "<nop>", options)
|
|
||||||
map("v", "<right>", "<nop>", options)
|
|
||||||
map("v", "<up>", "<nop>", options)
|
|
||||||
|
|
||||||
-- Clears hlsearch after doing a search, otherwise just does normal <CR> stuff
|
|
||||||
vim.cmd [[ nnoremap <expr> <CR> {-> v:hlsearch ? ":nohl\<CR>" : "\<CR>"}() ]]
|
|
||||||
|
|
||||||
map("n", "<C-f>", ":silent !tmux neww tmux-sessioniser<CR>", { noremap = true, silent = true })
|
|
||||||
|
|
||||||
local keymap = require "opdavies.keymap"
|
|
||||||
local imap = keymap.imap
|
|
||||||
local nmap = keymap.nmap
|
|
||||||
local vmap = keymap.vmap
|
|
||||||
local xmap = keymap.xmap
|
|
||||||
|
|
||||||
-- Easy insertion of a trailing ; or , from insert mode
|
|
||||||
imap { ",,", "<Esc>A,<Esc>" }
|
|
||||||
imap { ";;", "<Esc>A;<Esc>" }
|
|
||||||
|
|
||||||
nmap { "ga", "<Plug>(EasyAlign)" }
|
|
||||||
xmap { "ga", "<Plug>(EasyAlign)" }
|
|
||||||
|
|
||||||
-- Focus on the current buffer.
|
|
||||||
nmap { "<leader>-", ":wincmd _<cr>:wincmd |<cr>", { noremap = true, silent = true } }
|
|
||||||
|
|
||||||
-- Automatically resize buffers.
|
|
||||||
nmap { "<leader>=", ":wincmd =<cr>", { noremap = true, silent = true } }
|
|
||||||
|
|
||||||
-- 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 }
|
|
||||||
|
|
||||||
-- Re-centre when navigating.
|
|
||||||
vim.keymap.set("n", "#", "#zz", opts)
|
|
||||||
vim.keymap.set("n", "%", "%zz", opts)
|
|
||||||
vim.keymap.set("n", "*", "*zz", opts)
|
|
||||||
vim.keymap.set("n", "<C-u>", "<C-u>zz", opts)
|
|
||||||
vim.keymap.set("n", "<C-d>", "<C-d>zz", opts)
|
|
||||||
vim.keymap.set("n", "<C-i>", "<C-i>zz", opts)
|
|
||||||
vim.keymap.set("n", "<C-o>", "<C-o>zz", opts)
|
|
||||||
vim.keymap.set("n", "G", "Gzz", opts)
|
|
||||||
vim.keymap.set("n", "N", "Nzz", opts)
|
|
||||||
vim.keymap.set("n", "gg", "ggzz", opts)
|
|
||||||
vim.keymap.set("n", "n", "Nzz", opts)
|
|
||||||
vim.keymap.set("n", "{", "{zz", opts)
|
|
||||||
vim.keymap.set("n", "}", "}zz", opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function set_highlights()
|
|
||||||
vim.cmd [[highlight Comment cterm=italic gui=italic]]
|
|
||||||
end
|
|
||||||
|
|
||||||
local function set_vim_g()
|
|
||||||
vim.g.mapleader = " "
|
|
||||||
end
|
|
||||||
|
|
||||||
local function set_vim_o()
|
|
||||||
local settings = {
|
|
||||||
autoindent = true,
|
|
||||||
backup = false,
|
|
||||||
breakindent = true,
|
|
||||||
conceallevel = 0,
|
|
||||||
expandtab = true,
|
|
||||||
foldlevel = 1,
|
|
||||||
foldlevelstart = 99,
|
|
||||||
foldmethod = "indent",
|
|
||||||
formatoptions = "lm",
|
|
||||||
hidden = false,
|
|
||||||
inccommand = "split",
|
|
||||||
linebreak = true,
|
|
||||||
list = true,
|
|
||||||
mouse = "n",
|
|
||||||
number = true,
|
|
||||||
pumblend = 10,
|
|
||||||
pumheight = 10,
|
|
||||||
relativenumber = true,
|
|
||||||
scrolloff = 10,
|
|
||||||
shiftwidth = 2,
|
|
||||||
showmode = false,
|
|
||||||
signcolumn = "yes:1",
|
|
||||||
smartindent = true,
|
|
||||||
softtabstop = 2,
|
|
||||||
splitbelow = false,
|
|
||||||
splitright = true,
|
|
||||||
swapfile = false,
|
|
||||||
syntax = "on",
|
|
||||||
tabstop = 2,
|
|
||||||
termguicolors = true,
|
|
||||||
textwidth = 0,
|
|
||||||
undodir = os.getenv("HOME") .. "/.vim/undodir",
|
|
||||||
undofile = true,
|
|
||||||
updatetime = 1000,
|
|
||||||
wrap = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value in pairs(settings) do
|
|
||||||
vim.o[key] = value
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.opt.backupdir:remove "." -- keep backups out of the current directory
|
|
||||||
vim.opt.clipboard:append "unnamedplus"
|
|
||||||
vim.opt.listchars:append {
|
|
||||||
trail = "·",
|
|
||||||
}
|
|
||||||
vim.opt.completeopt = { "menu", "menuone", "noselect" }
|
|
||||||
vim.opt.laststatus = 3
|
|
||||||
end
|
|
||||||
|
|
||||||
M.setup = function()
|
|
||||||
set_vim_g()
|
|
||||||
set_vim_o()
|
|
||||||
set_key_mappings()
|
|
||||||
set_autocmd()
|
|
||||||
set_filetypes()
|
|
||||||
set_highlights()
|
|
||||||
|
|
||||||
vim.g.snippets = "luasnip"
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
|
|
Reference in a new issue