commit d0c0a080587d3f20072a741fcc1697df75707795
parent 773da3b55126b4fa2a8a3390c062ee3beec363e1
Author: Chris Bracken <chris@bracken.jp>
Date: Sat, 24 Aug 2024 15:43:46 -0700
vim: migrate neovim config to Lua
This migrates the vimscript init.vim to a Lua-based init.lua. Any
options that are redundant in neovim, or whose defaults in are the
values that I had previously be setting, have been eliminated.
Diffstat:
3 files changed, 137 insertions(+), 142 deletions(-)
diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua
@@ -0,0 +1,137 @@
+-- Plugin management with vim-plug.
+vim.cmd [[
+call plug#begin()
+" Colour scheme.
+Plug 'craftzdog/solarized-osaka.nvim'
+
+" Formatting.
+Plug 'rhysd/vim-clang-format' " clang-format.
+
+" Language support plugins.
+Plug 'https://gn.googlesource.com/gn', { 'rtp': 'misc/vim' }
+Plug 'nathangrigg/vim-beancount'
+Plug 'rust-lang/rust.vim'
+Plug 'neovim/nvim-lspconfig'
+
+" Behaviour.
+Plug 'ibhagwan/fzf-lua'
+Plug 'tpope/vim-fugitive'
+Plug 'lewis6991/gitsigns.nvim'
+call plug#end()
+]]
+
+-- Configure plugins.
+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/init.vim b/.config/nvim/init.vim
@@ -1,142 +0,0 @@
-set nocompatible
-set encoding=utf-8
-
-call plug#begin()
-" Colour scheme.
-Plug 'craftzdog/solarized-osaka.nvim'
-
-" Formatting.
-Plug 'rhysd/vim-clang-format' " clang-format.
-
-" Language support plugins.
-Plug 'https://gn.googlesource.com/gn', { 'rtp': 'misc/vim' }
-Plug 'nathangrigg/vim-beancount'
-Plug 'rust-lang/rust.vim'
-Plug 'neovim/nvim-lspconfig'
-
-" Behaviour.
-Plug 'ibhagwan/fzf-lua'
-Plug 'tpope/vim-fugitive'
-Plug 'lewis6991/gitsigns.nvim'
-call plug#end()
-
-" Configure plugins that require Lua-based setup.
-source $HOME/.config/nvim/plugins.lua
-
-" Bind fancier manpage plugin to Shift-k.
-runtime ftplugin/man.vim
-set keywordprg=:Man
-
-" Disable visual-mode mouse select.
-set mouse=
-
-" Set <leader> to comma for convenience.
-let mapleader=','
-
-" Enable middle-mouse paste.
-map! <S-Insert> <MiddleMouse>
-map <S-Insert> <MiddleMouse>
-
-" Kill ex mode.
-noremap Q <NOP>
-
-" Kill arrow keys, for great justice.
-noremap <Up> <NOP>
-noremap <Down> <NOP>
-noremap <Left> <NOP>
-noremap <Right> <NOP>
-
-" In terminal, ESC returns to normal mode.
-tnoremap <Esc> <C-\><C-n>
-
-" Retain selection on <,>.
-vnoremap < <gv
-vnoremap > >gv
-
-" Snippets.
-nnoremap <leader>sch :0r ~/.config/nvim/snippets/cc.h<CR>
-nnoremap <leader>sci :0r ~/.config/nvim/snippets/cc.cc<CR>
-nnoremap <leader>scn :.-1r ~/.config/nvim/snippets/namespace.cc<CR>
-nnoremap <leader>scs :.-1r ~/.config/nvim/snippets/struct.cc<CR>
-nnoremap <leader>scc :.-1r ~/.config/nvim/snippets/class.cc<CR>
-nnoremap <leader>sjn :.-1r ~/.config/nvim/snippets/journal.md<CR>
-
-" Basic options.
-set incsearch " Turn on incrememental searching.
-set hlsearch " Highlight search.
-set visualbell " Less noise.
-set number " Use line numbering.
-set ruler " Show row/col in status.
-set laststatus=2 " Always show status line.
-set showmatch " Highlight matching bracket.
-set history=50 " Keep 50 lines of cmdline history.
-set wildmenu " Nicer autocomplete.
-set wildmode=longest,full
-set wildignore=*.o,*.pyc " Ignore some filetypes during completion.
-set spelllang=en_ca " Set the spelling language.
-
-" Omnicomplete.
-set completeopt+=longest
-
-" Indentation/tabulation.
-set autoindent " Copy indent from current line when starting a new line.
-set smartindent " Attempt to autoindent when starting a new line.
-set smarttab " Use shiftwidth rather than tabstop at start of line.
-set tabstop=2 " Number of spaces per tab.
-set shiftwidth=2 " Number of spaces for each step of autoindent.
-set softtabstop=2 " Number of spaces per tab when editing.
-set expandtab " Insert spaces in place of tabs.
-
-" Fix python's indent overrides.
-au FileType python setl ts=2 sw=2 sts=2 et
-
-" Configure tag file locations.
-set tags+=~/.local/tags/system.tags
-set tags+=~/.local/tags/cxx.tags
-
-" Configure fzf-lua.
-nnoremap <leader>b <cmd>FzfLua buffers<CR>
-nnoremap <leader>f <cmd>FzfLua files<CR>
-nnoremap <leader>g <cmd>FzfLua grep<CR>
-nnoremap <leader>l <cmd>FzfLua live_grep<CR>
-nnoremap <leader>c <cmd>FzfLua builtin commands<CR>
-nnoremap <leader>q <cmd>lua vim.diagnostic.setqflist()<CR>
-
-" Configure colour scheme and syntax highlighting.
-if &t_Co > 2
- syntax enable
- set background=dark
- colorscheme solarized-osaka
-
- " Highlight cursor line, max column.
- set cursorline
-
- " Cursor line highlighting.
- au WinLeave * setlocal nocursorline
- au WinEnter * setlocal cursorline
- au BufLeave * setlocal nocursorline
- au BufEnter * setlocal cursorline
-
- " Highlight over-length lines.
- au BufEnter,InsertLeave * set colorcolumn=80
- au BufEnter,InsertLeave *.txt,*.md set colorcolumn=80
- au BufEnter,InsertLeave *.txt,*.md set textwidth=80
- au BufEnter,InsertLeave *.java,*.m,*.mm set colorcolumn=100
- au BufEnter,InsertLeave *.java,*.m,*.mm set textwidth=100
-endif
-
-""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
-" Functions
-
-" Toggle absolute/relative numbering.
-function! ToggleNumbering()
- if (&number == 0)
- set number
- elseif (&relativenumber == 0)
- set relativenumber
- else
- set norelativenumber
- set nonumber
- endif
-endfunc
-nnoremap <leader>n :call ToggleNumbering()<CR>
diff --git a/.config/nvim/plugins.lua b/.config/nvim/lua/plugins.lua