commit 8b30a279bf4dcd551d87784d08089bb86dabedcb
parent 08eb7e22a2d7e45df6cac855b4c4db0883e96559
Author: Chris Bracken <chris@bracken.jp>
Date: Sat, 24 Aug 2024 16:33:36 -0700
vim: break config up into modules
Splits out core options and keymappings. Keeps plugins separate.
Diffstat:
3 files changed, 113 insertions(+), 114 deletions(-)
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
@@ -20,118 +20,6 @@ Plug 'lewis6991/gitsigns.nvim'
call plug#end()
]]
--- Configure plugins.
+require('core.options')
+require('core.keymappings')
require('plugins')
-
--- Globals.
-vim.g.mouse = 0 -- Disable visual-mode mouse select.
-vim.g.mapleader=' ' -- Set <leader> key.
-
--- Basic options
-vim.opt.incsearch = true -- Turn on incremental searching.
-vim.opt.hlsearch = true -- Highlight search.
-vim.opt.visualbell = true -- Less noise.
-vim.opt.number = true -- Use line numbering.
-vim.opt.ruler = true -- Show row/col in status.
-vim.opt.laststatus = 2 -- Always show status line.
-vim.opt.showmatch = true -- Highlight matching bracket.
-vim.opt.history = 50 -- Keep 50 lines of cmdline history.
-vim.opt.wildmenu = true -- Nicer autocomplete.
-vim.opt.wildmode = {'longest', 'full'}
-vim.opt.wildignore = {'*.o', '*.pyc'} -- Ignore some filetypes during completion.
-vim.opt.spelllang = 'en_ca' -- Set the spelling language.
-vim.opt.completeopt:append('longest') -- Insert longest common prefix of options.
-vim.opt.autoindent = true -- Copy indent from current line when starting a new line.
-vim.opt.smartindent = true -- Attempt to autoindent when starting a new line.
-vim.opt.smarttab = true -- Use shiftwidth rather than tabstop at start of line.
-vim.opt.tabstop = 2 -- Number of spaces per tab.
-vim.opt.shiftwidth = 2 -- Number of spaces for each step of autoindent.
-vim.opt.softtabstop = 2 -- Number of spaces per tab when editing.
-vim.opt.expandtab = true -- Insert spaces in place of tabs.
-
--- Fix Python's indent overrides.
-vim.api.nvim_create_autocmd('FileType', {
- pattern = 'python',
- callback = function()
- vim.opt_local.tabstop = 2
- vim.opt_local.shiftwidth = 2
- vim.opt_local.softtabstop = 2
- vim.opt_local.expandtab = true
- end
-})
-
--- Configure colour scheme and syntax highlighting.
-vim.opt.background = 'dark'
-if vim.fn.has('termguicolors') == 1 then
- vim.opt.cursorline = true -- Highlight cursor line, max column.
- vim.opt.termguicolors = true -- Enable 24-bit colour.
- vim.cmd('colorscheme solarized-osaka')
-
- vim.api.nvim_create_autocmd({'WinLeave'}, {
- pattern = '*',
- command = 'setlocal nocursorline'
- })
- vim.api.nvim_create_autocmd({'WinEnter'}, {
- pattern = '*',
- command = 'setlocal cursorline'
- })
- vim.api.nvim_create_autocmd({'BufLeave'}, {
- pattern = '*',
- command = 'setlocal nocursorline'
- })
- vim.api.nvim_create_autocmd({'BufEnter'}, {
- pattern = '*',
- command = 'setlocal cursorline'
- })
-
- -- Highlight over-length lines.
- vim.api.nvim_create_autocmd({'BufEnter', 'InsertLeave'}, {
- pattern = '*',
- command = 'set colorcolumn=80'
- })
- vim.api.nvim_create_autocmd({'BufEnter', 'InsertLeave'}, {
- pattern = {'*.txt', '*.md'},
- command = 'set colorcolumn=80 | set textwidth=80'
- })
- vim.api.nvim_create_autocmd({'BufEnter', 'InsertLeave'}, {
- pattern = {'*.java', '*.m', '*.mm'},
- command = 'set colorcolumn=100 | set textwidth=100'
- })
-end
-
--- Kill arrow keys, for great justice.
-vim.keymap.set('n', '<Up>', '<NOP>')
-vim.keymap.set('n', '<Down>', '<NOP>')
-vim.keymap.set('n', '<Left>', '<NOP>')
-vim.keymap.set('n', '<Right>', '<NOP>')
-
--- In terminal, ESC returns to normal mode.
-vim.keymap.set('t', '<Esc>', '<C-\\><C-n>')
-
--- Retain selection on <,>.
-vim.keymap.set('v', '<', '<gv')
-vim.keymap.set('v', '>', '>gv')
-
--- Configure fzf-lua.
-vim.keymap.set('n', '<leader>b', '<cmd>FzfLua buffers<CR>')
-vim.keymap.set('n', '<leader>f', '<cmd>FzfLua files<CR>')
-vim.keymap.set('n', '<leader>g', '<cmd>FzfLua grep<CR>')
-vim.keymap.set('n', '<leader>l', '<cmd>FzfLua live_grep<CR>')
-vim.keymap.set('n', '<leader>c', '<cmd>FzfLua builtin commands<CR>')
-vim.keymap.set('n', '<leader>q', function() vim.diagnostic.setqflist() end)
-
--- Function to toggle absolute/relative numbering
-local function toggle_numbering()
- local opt = vim.opt
- if opt.number:get() == false then
- opt.number = true
- elseif opt.relativenumber:get() == false then
- opt.relativenumber = true
- else
- opt.relativenumber = false
- opt.number = false
- end
-end
-
--- Key mapping to toggle numbering
-vim.keymap.set('n', '<leader>n', toggle_numbering)
diff --git a/.config/nvim/lua/config/keymappings.lua b/.config/nvim/lua/config/keymappings.lua
@@ -0,0 +1,36 @@
+-- Kill arrow keys, for great justice.
+vim.keymap.set('n', '<Up>', '<NOP>')
+vim.keymap.set('n', '<Down>', '<NOP>')
+vim.keymap.set('n', '<Left>', '<NOP>')
+vim.keymap.set('n', '<Right>', '<NOP>')
+
+-- In terminal, ESC returns to normal mode.
+vim.keymap.set('t', '<Esc>', '<C-\\><C-n>')
+
+-- Retain selection on <,>.
+vim.keymap.set('v', '<', '<gv')
+vim.keymap.set('v', '>', '>gv')
+
+-- Configure fzf-lua.
+vim.keymap.set('n', '<leader>b', '<cmd>FzfLua buffers<CR>')
+vim.keymap.set('n', '<leader>f', '<cmd>FzfLua files<CR>')
+vim.keymap.set('n', '<leader>g', '<cmd>FzfLua grep<CR>')
+vim.keymap.set('n', '<leader>l', '<cmd>FzfLua live_grep<CR>')
+vim.keymap.set('n', '<leader>c', '<cmd>FzfLua builtin commands<CR>')
+vim.keymap.set('n', '<leader>q', function() vim.diagnostic.setqflist() end)
+
+-- Function to toggle absolute/relative numbering
+local function toggle_numbering()
+ local opt = vim.opt
+ if opt.number:get() == false then
+ opt.number = true
+ elseif opt.relativenumber:get() == false then
+ opt.relativenumber = true
+ else
+ opt.relativenumber = false
+ opt.number = false
+ end
+end
+
+-- Key mapping to toggle numbering
+vim.keymap.set('n', '<leader>n', toggle_numbering)
diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua
@@ -0,0 +1,75 @@
+-- Globals.
+vim.g.mouse = 0 -- Disable visual-mode mouse select.
+vim.g.mapleader=' ' -- Set <leader> key.
+
+-- Basic options
+vim.opt.incsearch = true -- Turn on incremental searching.
+vim.opt.hlsearch = true -- Highlight search.
+vim.opt.visualbell = true -- Less noise.
+vim.opt.number = true -- Use line numbering.
+vim.opt.ruler = true -- Show row/col in status.
+vim.opt.laststatus = 2 -- Always show status line.
+vim.opt.showmatch = true -- Highlight matching bracket.
+vim.opt.history = 50 -- Keep 50 lines of cmdline history.
+vim.opt.wildmenu = true -- Nicer autocomplete.
+vim.opt.wildmode = {'longest', 'full'}
+vim.opt.wildignore = {'*.o', '*.pyc'} -- Ignore some filetypes during completion.
+vim.opt.spelllang = 'en_ca' -- Set the spelling language.
+vim.opt.completeopt:append('longest') -- Insert longest common prefix of options.
+vim.opt.autoindent = true -- Copy indent from current line when starting a new line.
+vim.opt.smartindent = true -- Attempt to autoindent when starting a new line.
+vim.opt.smarttab = true -- Use shiftwidth rather than tabstop at start of line.
+vim.opt.tabstop = 2 -- Number of spaces per tab.
+vim.opt.shiftwidth = 2 -- Number of spaces for each step of autoindent.
+vim.opt.softtabstop = 2 -- Number of spaces per tab when editing.
+vim.opt.expandtab = true -- Insert spaces in place of tabs.
+
+-- Fix Python's indent overrides.
+vim.api.nvim_create_autocmd('FileType', {
+ pattern = 'python',
+ callback = function()
+ vim.opt_local.tabstop = 2
+ vim.opt_local.shiftwidth = 2
+ vim.opt_local.softtabstop = 2
+ vim.opt_local.expandtab = true
+ end
+})
+
+-- Configure colour scheme and syntax highlighting.
+vim.opt.background = 'dark'
+if vim.fn.has('termguicolors') == 1 then
+ vim.opt.cursorline = true -- Highlight cursor line, max column.
+ vim.opt.termguicolors = true -- Enable 24-bit colour.
+ vim.cmd('colorscheme solarized-osaka')
+
+ vim.api.nvim_create_autocmd({'WinLeave'}, {
+ pattern = '*',
+ command = 'setlocal nocursorline'
+ })
+ vim.api.nvim_create_autocmd({'WinEnter'}, {
+ pattern = '*',
+ command = 'setlocal cursorline'
+ })
+ vim.api.nvim_create_autocmd({'BufLeave'}, {
+ pattern = '*',
+ command = 'setlocal nocursorline'
+ })
+ vim.api.nvim_create_autocmd({'BufEnter'}, {
+ pattern = '*',
+ command = 'setlocal cursorline'
+ })
+
+ -- Highlight over-length lines.
+ vim.api.nvim_create_autocmd({'BufEnter', 'InsertLeave'}, {
+ pattern = '*',
+ command = 'set colorcolumn=80'
+ })
+ vim.api.nvim_create_autocmd({'BufEnter', 'InsertLeave'}, {
+ pattern = {'*.txt', '*.md'},
+ command = 'set colorcolumn=80 | set textwidth=80'
+ })
+ vim.api.nvim_create_autocmd({'BufEnter', 'InsertLeave'}, {
+ pattern = {'*.java', '*.m', '*.mm'},
+ command = 'set colorcolumn=100 | set textwidth=100'
+ })
+end