Skip to content

Commit

Permalink
feat(neovim): split from Vim & revamp configuration
Browse files Browse the repository at this point in the history
Neovim has acquired many features and diverged quite a bit from Vim over
the past few years that it was worth revisiting the configuration.

- Migrate configuration from Vim Script to Lua
- Use Home Manager for plugin management
- Prefer built-in Neovim features over external plugins
- Make use of TreeSitter and built-in LSP
  • Loading branch information
midchildan committed Sep 8, 2024
1 parent 6c42706 commit df379f5
Show file tree
Hide file tree
Showing 14 changed files with 497 additions and 12 deletions.
1 change: 0 additions & 1 deletion files/.config/nvim

This file was deleted.

154 changes: 154 additions & 0 deletions files/.config/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
local augroup = vim.api.nvim_create_augroup("vimrc", { clear = true })

-- {{{ General

vim.opt.backup = true
vim.opt.backupdir:remove(".")
vim.opt.undofile = true
vim.opt.ignorecase = true
vim.opt.smartcase = true

vim.g.tex_flavor = "latex"

vim.cmd("silent! packadd! cfilter")

-- See :h :DiffOrig
vim.cmd([[
command! DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
]])

-- }}}
-- {{{ Editing

vim.opt.expandtab = true
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 2
vim.opt.copyindent = true
vim.opt.preserveindent = true
vim.opt.formatoptions:append({ "m", "B" })
vim.opt.fileencodings = {
"ucs-bom",
"utf-8",
"iso-2022-jp",
"euc-jp",
"cp932",
"default",
"latin1",
}

-- jump to the last known cursor position
vim.api.nvim_create_autocmd("BufReadPost", {
group = augroup,
callback = function(opts)
local ft = vim.bo[opts.buf].filetype
local line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1]
local in_range = 1 < line and line <= vim.api.nvim_buf_line_count(opts.buf)

if in_range and not ft:match("commit") then
vim.api.nvim_feedkeys([[g`"]], "nx", false)
end
end,
})

-- }}}
-- {{{ UI

vim.opt.colorcolumn = "81"
vim.opt.foldenable = false
vim.opt.inccommand = "split"
vim.opt.lazyredraw = true
vim.opt.mouse = "a"
vim.opt.number = true
vim.opt.showmatch = true
vim.opt.title = true
vim.opt.wildignorecase = true
vim.opt.diffopt = {
"internal",
"filler",
"closeoff",
"algorithm:histogram",
"indent-heuristic",
}

vim.api.nvim_create_autocmd("TextYankPost", {
group = augroup,
pattern = "*",
callback = function(args)
vim.highlight.on_yank({
higroup = "Visual",
timeout = 300,
})
end,
})

vim.api.nvim_create_autocmd("QuickfixCmdPost", {
group = augroup,
pattern = [[\C[^lA-Z]*]],
command = "botright cwindow",
})

vim.api.nvim_create_autocmd("QuickfixCmdPost", {
group = augroup,
pattern = "l*",
command = "botright lwindow",
})

-- }}}
-- {{{ Keybindings

vim.g.mapleader = " "
vim.g.maplocalleader = "\\"

vim.keymap.set("n", "<Leader>b", "<Cmd>bmodified<CR>")

vim.keymap.set({ "i", "s" }, "<Tab>", function()
if vim.snippet.active({ direction = 1 }) then
return "<Cmd>lua vim.snippet.jump(1)<CR>"
else
return "<Tab>"
end
end, { expr = true })

vim.keymap.set({ "i", "s" }, "<S-Tab>", function()
if vim.snippet.active({ direction = -1 }) then
return "<Cmd>lua vim.snippet.jump(-1)<CR>"
else
return "<S-Tab>"
end
end, { expr = true })

-- find merge conflict marker
vim.keymap.set({ "n", "x", "o" }, "<Leader>fc", [[/\v^[<=>]{7}( .*<Bar>$)<CR>]])
-- find whitespace errors
vim.keymap.set({ "n", "x", "o" }, "<Leader>f ", [[/\s\+$\<Bar> \+\ze\t<CR>]])
-- find full-width punctuation marks
vim.keymap.set({ "n", "x", "o" }, "<Leader>f.", [[/\v(\.<Bar>.<Bar>。)<CR>]])
vim.keymap.set({ "n", "x", "o" }, "<Leader>f,", [[/\v(,<Bar>,<Bar>、)<CR>]])
vim.keymap.set({ "n", "x", "o" }, "<Leader>f!", [[f! /\v(!<Bar>!)<CR>]])
vim.keymap.set({ "n", "x", "o" }, "<Leader>f!", [[f? /\v(\?<Bar>?)<CR>]])

-- text objects
vim.keymap.set("x", "al", "<Esc>0v$")
vim.keymap.set("o", "al", "<Cmd>normal! 0v$<CR>")
vim.keymap.set("x", "il", "<Esc>^vg_")
vim.keymap.set("o", "il", "<Cmd>normal! ^vg_<CR>")
vim.keymap.set("x", "ag", "gg0oG$")
vim.keymap.set("o", "ag", [[<Cmd>exe "normal! m`"<Bar>keepjumps normal! ggVG<CR>]])

-- toggles
vim.keymap.set("n", "<Leader>ts", "<Cmd>setlocal spell! spell?<CR>")
vim.keymap.set("n", "<Leader>tv", "<Cmd>call vimrc#toggle_virtualedit()<CR>")
vim.keymap.set("n", "<Leader>tq", "<Cmd>call vimrc#toggle_textwidth()<CR>")
vim.keymap.set("n", "<Leader>t#", "<Cmd>setlocal relativenumber! relativenumber?<CR>")
vim.keymap.set("n", "<Leader>t ", "<Cmd>call vimrc#toggle_whitespace_check()<CR>")
vim.keymap.set("n", "<Leader>t<Tab>", "<Cmd>call vimrc#toggle_whitespace_visibility()<CR>")

-- 3-way merge
vim.keymap.set("n", "<Leader>1", "<Cmd>diffget LOCAL<CR>")
vim.keymap.set("n", "<Leader>2", "<Cmd>diffget BASE<CR>")
vim.keymap.set("n", "<Leader>3", "<Cmd>diffget REMOTE<CR>")

-- }}}

-- vim:set foldmethod=marker:
2 changes: 2 additions & 0 deletions files/.vim/ftplugin/fugitive.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if !empty(mapcheck('q', 'n'))
nunmap <buffer> q
endif

let b:editorconfig = v:false
1 change: 0 additions & 1 deletion files/.vim/ginit.vim

This file was deleted.

1 change: 0 additions & 1 deletion files/.vim/init.vim

This file was deleted.

2 changes: 1 addition & 1 deletion nix/devshells/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

ansible = pkgs.callPackage ./ansible.nix { };

setup = pkgs.callPackage ./setup.nix { inherit (self'.packages) neovim; };
setup = pkgs.callPackage ./setup.nix { };

quic = pkgs.callPackage ./quic.nix { };
};
Expand Down
2 changes: 0 additions & 2 deletions nix/devshells/setup.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
curl,
emacs-nox,
git,
neovim,
}:

mkShellNoCC {
Expand All @@ -13,6 +12,5 @@ mkShellNoCC {
curl
emacs-nox
git
neovim
];
}
1 change: 1 addition & 0 deletions nix/home/modules/vim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ in
};
};
};
default = { };
description = "Install the specified vim plugins.";
};

Expand Down
1 change: 1 addition & 0 deletions nix/home/profiles/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
./development.nix
./fonts.nix
./macos.nix
./neovim.nix
./web.nix
];

Expand Down
3 changes: 2 additions & 1 deletion nix/home/profiles/minimal.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ in
less
ripgrep
zsh-syntax-highlighting
myPkgs.neovim
];

programs.direnv = {
enable = mkDefault true;
nix-direnv.enable = mkDefault true;
};

dotfiles.profiles.neovim.enable = mkDefault true;

dotfiles.manpages = {
enable = mkDefault true;
useSystemMan = mkDefault (!isNixOS);
Expand Down
Loading

0 comments on commit df379f5

Please sign in to comment.