Take first steos toward nvim lua config

This commit is contained in:
Andrew Tomaka 2022-09-21 22:02:30 -04:00
parent e090f64788
commit 4143a7971a
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
7 changed files with 261 additions and 29 deletions

9
.gitignore vendored
View file

@ -1,9 +1,12 @@
*.swp
alacritty/.config/alacritty/alacritty.yml
nvim/.config/nvim/plugin/packer_compiled.lua
nvim/.config/nvim/undo
vim/.config/vim/undo
zsh/.config/zsh/.zcompdump
zsh/.config/zsh/.zsh_history
zsh/.config/zsh/.zsh_sessions
vim/.config/vim/undo
nvim/.config/nvim/undo

View file

@ -25,6 +25,6 @@ for pane_info in $(tmux list-panes -a -F '#{pane_id}-#{pane_current_command}');
IFS=- read pane cmd <<< "$pane_info"
if [[ $cmd == "vim" || $cmd == "nvim" ]]; then
tmux send-keys -t $pane ":call ChangeBackground()" ENTER
tmux send-keys -t $pane ":lua ChangeBackground()" ENTER
fi
done

View file

@ -16,7 +16,7 @@ install_homebrew() {
install_shared_applications() {
brew install direnv fzf git stow the_silver_searcher tmux \
vim zsh rbenv ruby-build tfenv nodenv node-build tig libpq gnupg llvm \
awscli cmake jq watch gh
awscli cmake jq watch gh nvim
install_alacritty_terminfo
install_rust
@ -72,13 +72,9 @@ install_rust() {
}
install_vim() {
if ! test -f ~/.vim/autoload/plug.vim > /dev/null; then
curl \
--create-dirs \
--fail \
--location \
--output ~/.vim/autoload/plug.vim \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
if ! test -d ~/.local/share/nvim/site > /dev/null; then
git clone --depth 1 https://github.com/wbthomason/packer.nvim \
~/.local/share/nvim/site/pack/packer/start/packer.nvim
fi
}

249
nvim/.config/nvim/init.lua Normal file
View file

@ -0,0 +1,249 @@
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({"git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path})
vim.cmd [[packadd packer.nvim]]
return true
end
return false
end
local packer_bootstrap = ensure_packer()
require("packer").startup(function(use)
local use = use
use "wbthomason/packer.nvim"
-- TODO: autoupdate (but after plugins separate file
-- augroup packer_user_config
-- autocmd!
-- autocmd BufWritePost plugins.lua source <afile> | PackerCompile
-- augroup end
use "nvim-lua/plenary.nvim"
use "nvim-telescope/telescope.nvim"
use "nvim-treesitter/nvim-treesitter"
use "nvim-treesitter/nvim-treesitter-context"
use "famiu/bufdelete.nvim"
use "gpanders/editorconfig.nvim"
use "johnfrankmorgan/whitespace.nvim"
use "kylechui/nvim-surround"
use "lewis6991/gitsigns.nvim"
use "nyngwang/NeoZoom.lua" -- TODO: Floating window background color
use "ruifm/gitlinker.nvim"
use "gruvbox-community/gruvbox"
end)
--- SETTING CONFIGURATION
vim.opt.autowrite = true
-- vim.opt.backspace = 2 -- default in neovim?
vim.opt.cpoptions:append("$")
-- vim.opt.endofline -- default in neovim?
-- vim.opt.laststatus = 2 -- default in neovim?
-- vim.opt.backup = false -- default in neovim?
vim.opt.swapfile = false
vim.opt.wrap = false
vim.opt.scrolloff = 3
vim.opt.showmatch = true
-- vim.opt.showmode = true -- default in neovim?
-- vim.opt.showmode = true -- default in neovim?
vim.opt.timeoutlen = 500
vim.opt.virtualedit = "all"
-- vim.opt.hlsearch = true -- default in neovim?
vim.opt.ignorecase = true
-- vim.opt.incsearch = true -- default in neovim?
vim.opt.smartcase = true
-- vim.opt.wrapscan = true -- default in neovim?
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.textwidth = 80
vim.opt.colorcolumn = {80, 120}
-- Tabs are 2 spaces
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.shiftround = true -- make >> go to next tab
-- undo
vim.opt.undolevels = 5000
vim.opt.undofile = true
vim.opt.undodir = os.getenv("HOME") .. "/.config/nvim/undo"
-- REMAP CONFIGURATION
--- Stay in visual mode while tabbing
vim.keymap.set("v", ">", ">gv")
vim.keymap.set("v", "<", "<gv")
--- quick replacement
vim.keymap.set("n", "S", ":%s//g<LEFT><LEFT>")
vim.keymap.set("v", "S", 'y:%s/<C-r><C-r>"//g<Left><Left>')
--- COMMAND CONFIGURATION
--- Avoid typos
vim.api.nvim_create_user_command("W", "w", {})
vim.api.nvim_create_user_command("Wq", "wq", {})
-- CUSTOM CONFIGURATION
--- Targetting!
local reticle = vim.api.nvim_create_augroup("Reticle", {
clear = true
})
vim.api.nvim_create_autocmd({"VimEnter", "WinEnter", "BufWinEnter"}, {
group = reticle,
callback = function()
vim.opt_local.cursorline = true
vim.opt_local.cursorcolumn = true
end
})
vim.api.nvim_create_autocmd({"WinLeave"}, {
group = reticle,
callback = function()
vim.opt_local.cursorline = false
vim.opt_local.cursorcolumn = false
end
})
--- background matching terminal
function ChangeBackground()
local file = io.open(os.getenv("HOME") .. "/.config/atomaka/color.yml", "rb")
local background = file:read()
file:close()
vim.opt.background = background
end
ChangeBackground()
-- LEADER CONFIGURATION
vim.g.mapleader = ","
vim.keymap.set("n", "<leader>sz", ":luafile ~/.config/nvim/init.lua<cr>")
vim.keymap.set({ "n", "v" }, "<leader>cp", '"+y')
vim.keymap.set({ "n", "v" }, "<leader>pa", '"+P')
vim.keymap.set("n", "<leader>cs", ":let @/ = ''<cr>")
vim.keymap.set("n", "<leader>fj", ":%!jq .<cr>")
vim.keymap.set("n", "<leader>gg", ":exe '!gh gist create -w %:p'<cr><cr>")
--- tabs
vim.keymap.set("n", "<Leader>2", function()
print("Setting tabstop to 2")
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
end)
vim.keymap.set("n", "<Leader>4", function()
print("Setting tabstop to 4")
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
end)
vim.keymap.set("n", "<Leader>a", function()
print("Setting tabstop to tab")
vim.opt.tabstop = 8
vim.opt.shiftwidth = 8
vim.opt.expandtab = false
end)
vim.keymap.set("n", "<Leader>st", ':let @/ = "\t"<cr>')
-- COLOR CONFIGURATION
vim.cmd("colorscheme gruvbox")
vim.api.nvim_create_autocmd({"ColorScheme", "BufWinEnter"}, {
callback = function()
vim.cmd("hi Normal ctermbg=NONE guibg=NONE")
end,
})
-- PLUGIN CONFIGURATION
--- bufdelete.nvim
vim.keymap.set("n", "<Leader>bd", function()
require("bufdelete").bufdelete(0, true)
end)
--- gitlinker.nvim
require"gitlinker".setup()
vim.keymap.set("n", "<Leader>gh", function()
require"gitlinker".get_buf_range_url(
"n",
{ action_callback = require"gitlinker.actions".open_in_browser }
)
end, { silent = true })
vim.keymap.set("v", "<leader>gh", function()
require"gitlinker".get_buf_range_url(
"v",
{ action_callback = require"gitlinker.actions".open_in_browser }
)
end)
--- gitsigns.nvim
require("gitsigns").setup()
vim.keymap.set("n", "<leader>gb", require("gitsigns").toggle_current_line_blame)
--- NeoZoom.lua
require("neo-zoom").setup({
left_ratio = 0,
top_ratio = 0,
width_ratio = 1,
height_ratio = 1,
border = "none",
})
vim.keymap.set("n", "<C-w>z", require("neo-zoom").neo_zoom)
--- nvim-surround
require("nvim-surround").setup()
--- nvim-treesitter
require"nvim-treesitter.configs".setup {
ensure_installed = "all",
sync_install = false,
ignore_install = { "phpdoc" }, -- TODO: https://github.com/claytonrcarter/tree-sitter-phpdoc/issues/15
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
}
-- nvim-treesitter-context
require("treesitter-context").setup({
patterns = {
rust = {
-- default rust
"impl_item",
"struct",
"enum",
-- substrate xD
"macro_invocation",
},
},
})
--- packer.nvim
vim.keymap.set("n", "<Leader>pi", function()
vim.cmd("PackerCompile")
vim.cmd("PackerInstall")
end)
vim.keymap.set("n", "<Leader>pu", ":PackerSync<CR>")
vim.keymap.set("n", "<Leader>pc", ":PackerClean<CR>")
--- telescope.nvim
vim.keymap.set("n", "<C-p>", function()
require("telescope.builtin").git_files()
end)
--- whitespace.nvim
require("whitespace-nvim").setup({
hightlight = "red"
})
vim.keymap.set("n", "<Leader>fw", function()
require("whitespace-nvim").trim()
end, { silent = true })

View file

@ -1,3 +0,0 @@
set runtimepath+=~/.vim,~/.vim/after
set packpath+=~/.vim
source ~/.vimrc

View file

@ -8,6 +8,7 @@ bind-key b send-prefix
set -g automatic-rename off
set -g renumber-windows on
set -g history-limit 100000
set-option -sg escape-time 10
set-option -g base-index 1
set-window-option -g monitor-activity off

View file

@ -21,9 +21,6 @@ Plug 'vim-ruby/vim-ruby'
" colors
Plug 'morhetz/gruvbox'
" testing
Plug 'wellle/context.vim' " consider nvim-treesitter-context
call plug#end()
" STATUS LINE
@ -154,18 +151,7 @@ augroup END
set cursorline
set cursorcolumn
" crosshair
set cursorline
set cursorcolumn
" crosshair
set cursorline
set cursorcolumn
" PLUGIN CONFIGURATION
" context.vim
let g:context_highlight_border = '<hide>'
" editorconfig-vim
let g:EditorConfig_exclude_patterns = ['fugitive://.*', 'scp://.*']