NVIM Configs in Lua #1

Merged
tyrel merged 4 commits from nvim into main 2023-01-02 20:38:02 +00:00
8 changed files with 323 additions and 181 deletions

25
home/config/nvim/init.lua Normal file
View File

@ -0,0 +1,25 @@
require("settings")
-- Install Packer automatically:
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
return require('packer').startup(function(use)
-- Packer can manage itself
use("wbthomason/packer.nvim")
require("plugins")(use)
local packer_bootstrap = ensure_packer()
if packer_bootstrap then
require('packer').sync()
end
end)

View File

@ -1,180 +0,0 @@
syntax enable
let mapleader = " "
call plug#begin('~/.vim/plugged')
Plug 'atelierbram/vim-colors_atelier-schemes'
Plug 'robertmeta/nofrils'
Plug 'vim-test/vim-test'
Plug 'hashivim/vim-terraform'
Plug 'rmagatti/auto-session'
Plug 'rmagatti/session-lens'
Plug 'ludovicchabant/vim-gutentags'
Plug 'ervandew/supertab'
Plug 'preservim/nerdtree'
Plug 'liuchengxu/space-vim-dark'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'mhinz/vim-startify'
Plug 'jeetsukumaran/vim-buffergator'
Plug 'ap/vim-buftabline'
Plug 'airblade/vim-gitgutter'
Plug 'majutsushi/tagbar'
Plug 'vim-airline/vim-airline'
Plug 'enricobacis/vim-airline-clock'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'thoughtbot/vim-rspec'
Plug 'voldikss/vim-floaterm'
Plug 'fatih/vim-go'
Plug 'whatyouhide/vim-gotham'
Plug 'nanotech/jellybeans.vim'
Plug 'sickill/vim-monokai'
Plug 'flebel/vim-mypy', { 'for': 'python', 'branch': 'bugfix/fast_parser_is_default_and_only_parser' }
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'psf/black', { 'branch': 'stable' }
Plug 'gf3/peg.vim'
call plug#end()
map <C-o> :NERDTreeToggle<CR>
set tabstop=2
set shiftwidth=2
set expandtab
set hidden
set background=dark
set autoindent
set preserveindent
set copyindent
set mouse=
set shell=~/.nix-profile/bin/fish
" Set Colors
if (has("termguicolors"))
set termguicolors
endif
colorscheme Atelier_SulphurpoolDark
hi Comment cterm=italic
" Relative numbers and when not in buffer set absolute numbers
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" Disable EX Mode
map q: <Nop>
" Disable EX Mode
nnoremap Q <nop>
nnoremap <C-K> :bnext<CR>
nnoremap <C-J> :bprev<CR>
nmap <leader>bq :bp <BAR> bd #<CR>
" Airline
let g:airline#extensions#clock#format = '%I:%M:%S %X'
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fa <cmd>Ag<cr>
" nnoremap <leader>ft <cmd>Telescope help_tags<cr>
"lua << EOF
"require('telescope').setup{
" file_ignore_patterns = {"node_modules","./venv/"},
"}
"EOF
" RSpec.vim mappings
map <Leader>rt :call RunCurrentSpecFile()<CR>
map <Leader>rs :call RunNearestSpec()<CR>
map <Leader>rl :call RunLastSpec()<CR>
map <Leader>ra :call RunAllSpecs()<CR>
" let g:python_host_prog = '~/.nvim.pythonenv2/bin/python'
if exists("$VIRTUAL_ENV")
let g:python3_host_prog=substitute(system("which -a python3 | head -n2 | tail -n1"), "\n", '', 'g')
else
let g:python3_host_prog=substitute(system("which python3"), "\n", '', 'g')
endif
" Floaterm
let g:floaterm_keymap_toggle = '<F9>'
let g:floaterm_width = 0.9
let g:floaterm_height = 0.9
" Line Numbers
set number relativenumber " Turn line numbering on at startup
noremap <F1> :set invnumber invrelativenumber<CR>
"Tagbar
"
noremap <F8> :Tagbar<CR>
let g:tagbar_autofocus=1
" Session Lens
lua <<EOF
require('session-lens').setup {
path_display={'shorten'},
}
EOF
noremap <F2> :SearchSession<CR>
" Syntax Colors
function! SynStack ()
for i1 in synstack(line("."), col("."))
let i2 = synIDtrans(i1)
let n1 = synIDattr(i1, "name")
let n2 = synIDattr(i2, "name")
echo n1 "->" n2
endfor
endfunction
" TreeSitter
lua <<EOF
require'nvim-treesitter.configs'.setup {
highlight = {
-- `false` will disable the whole extension
enable = true,
-- list of language that will be disabled
disable = {},
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
EOF
" Guten Tags
" set statusline+=%{gutentags#statusline()}
" Indent Line
let g:indentLine_char = '│'
" GBrowse open current line
nnoremap <leader>gb :.GBrowse<CR>
" vim-test
nmap <silent> <leader>t. :TestNearest<CR>
nmap <silent> <leader>tf :TestFile<CR>
nmap <silent> <leader>ts :TestSuite<CR>
let test#strategy = "neovim"
" Mypy
nmap <silent> <leader>mp :Mypy<CR>

View File

@ -0,0 +1,81 @@
syntax enable
let mapleader = " "
set autoindentz
set preserveindent
set copyindent
set shell=~/.nix-profile/bin/fish
" Set Colors
if (has("termguicolors"))
set termguicolors
endif
hi Comment cterm=italic
" Relative numbers and when not in buffer set absolute numbers
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" Disable EX Mode
map q: <Nop>
" Disable EX Mode
nnoremap Q <nop>
" Airline
let g:airline#extensions#clock#format = '%I:%M:%S %X'
" nnoremap <leader>ft <cmd>Telescope help_tags<cr>
" let g:python_host_prog = '~/.nvim.pythonenv2/bin/python'
if exists("$VIRTUAL_ENV")
let g:python3_host_prog=substitute(system("which -a python3 | head -n2 | tail -n1"), "\n", '', 'g')
else
let g:python3_host_prog=substitute(system("which python3"), "\n", '', 'g')
endif
" Line Numbers
set number relativenumber " Turn line numbering on at startup
noremap <F1> :set invnumber invrelativenumber<CR>
"Tagbar
"
" Syntax Colors
function! SynStack ()
for i1 in synstack(line("."), col("."))
let i2 = synIDtrans(i1)
let n1 = synIDattr(i1, "name")
let n2 = synIDattr(i2, "name")
echo n1 "->" n2
endfor
endfunction
" Guten Tags
" set statusline+=%{gutentags#statusline()}
" Indent Line
let g:indentLine_char = '│'
" vim-test
nmap <silent> <leader>t. :TestNearest<CR>
nmap <silent> <leader>tf :TestFile<CR>
nmap <silent> <leader>ts :TestSuite<CR>
let test#strategy = "neovim"
" Mypy
nmap <silent> <leader>mp :Mypy<CR>

View File

@ -0,0 +1,66 @@
vim.cmd([[autocmd BufWritePost plugins.lua PackerCompile]])
return function(use)
local parser_install_dir = vim.fn.stdpath("cache") .. "/treesitters"
vim.fn.mkdir(parser_install_dir, "p")
-- Prevents reinstall of treesitter plugins every boot
vim.opt.runtimepath:append(parser_install_dir)
-- Treesitter is managed by the package config, we just manage configs/deps here
use({ "nvim-treesitter/nvim-treesitter-refactor" })
use({ "RRethy/nvim-treesitter-textsubjects" })
require("nvim-treesitter.configs").setup({
-- highlight = { enable = true, disable = { "lua" } },
-- indent = { enable = true },
-- refactor = { highlight_definitions = { enable = true } },
-- incremental_selection = { enable = true },
-- matchup = { enable = true },
-- textsubjects = {
-- enable = true,
-- prev_selection = ",",
-- keymaps = {
-- ["."] = "textsubjects-smart",
-- },
-- },
parser_install_dir = parser_install_dir,
})
use({'atelierbram/vim-colors_atelier-schemes'})
use({'robertmeta/nofrils'})
use({'vim-test/vim-test'})
use({'hashivim/vim-terraform'})
use({'rmagatti/auto-session'})
use({'rmagatti/session-lens',
config = function() require'session-lens'.setup { path_display={'shorten'} } end
})
use({'ludovicchabant/vim-gutentags'})
-- use({'ervandew/supertab'})
use({'preservim/nerdtree'})
use({'liuchengxu/space-vim-dark'})
use({'junegunn/fzf', dir='~/.fzf'})
use({'junegunn/fzf.vim'})
use({'mhinz/vim-startify'})
use({'jeetsukumaran/vim-buffergator'})
use({'ap/vim-buftabline'})
use({'airblade/vim-gitgutter'})
use({'majutsushi/tagbar'})
use {
'nvim-lualine/lualine.nvim',
requires = { 'kyazdani42/nvim-web-devicons', opt = true }
}
use({
'nvim-telescope/telescope.nvim',
config = function () require('telescope').setup{ file_ignore_patterns = {"node_modules","./venv/"} } end
})
use({'thoughtbot/vim-rspec'})
use({'voldikss/vim-floaterm'})
use({'fatih/vim-go'})
use({'whatyouhide/vim-gotham'})
use({'nanotech/jellybeans.vim'})
use({'sickill/vim-monokai'})
use({'tpope/vim-fugitive'})
use({'tpope/vim-rhubarb'})
use({'gf3/peg.vim'})
end

View File

@ -0,0 +1,122 @@
vim.g.mapleader = " "
vim.g.maplocalleader = " "
vim.opt.shell = "/usr/local/bin/fish"
vim.opt.history = 1000
vim.opt.termguicolors = true
vim.opt.background = "dark"
vim.opt.mouse = "" -- disable
-- vim.opt.ruler = true -- Position at the bottom of the screen
vim.opt.joinspaces = false
vim.opt.hidden = true
vim.opt.previewheight = 5
--
vim.opt.shortmess = vim.o.shortmess .. "atI"
vim.opt.lazyredraw = true
vim.opt.splitbelow = true
vim.opt.splitright = true
-- Global settings
vim.opt.autochdir = true -- Keep vim's directory context same as the current buffer
vim.opt.listchars = "tab:> ,trail:.,extends:$,nbsp:_"
vim.opt.fillchars = "fold:-"
-- Search
vim.opt.hlsearch = true
vim.opt.incsearch = true
vim.opt.ignorecase = true
vim.opt.wildmode = "list:longest" -- Autocomplete
-- Buffer settings
vim.opt.autoindent = true
vim.opt.expandtab = true
vim.opt.shiftwidth = 2
vim.opt.softtabstop = 4
vim.opt.tabstop = 2
vim.opt.undofile = true
vim.opt.number = true
vim.opt.relativenumber = true
vim.cmd 'colorscheme Atelier_SulphurpoolDark'
vim.g.floaterm_keymap_toggle = '<F9>'
vim.g.floaterm_width = 0.9
vim.g.floaterm_height = 0.9
vim.g.tagbar_autofocus=1
-- Highlight yank
vim.api.nvim_command([[
au TextYankPost * lua vim.highlight.on_yank {higroup="IncSearch", timeout=150, on_visual=true}
]])
-- TODO: ... the rest of plugin/legacy.vim
local map = vim.api.nvim_set_keymap
local function t(str) -- Convert termcodes for mapping
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col(".") - 1
if col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
return true
else
return false
end
end
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t("<C-n>")
elseif vim.fn.call("vsnip#available", { 1 }) == 1 then
return t("<Plug>(vsnip-expand-or-jump)")
elseif check_back_space() then
return t("<Tab>")
else
return vim.fn["compe#complete"]()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t("<C-p>")
elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then
return t("<Plug>(vsnip-jump-prev)")
else
-- If <S-Tab> is not working in your terminal, change it to <C-h>
return t("<S-Tab>")
end
end
-- vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", { expr = true })
-- vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", { expr = true })
-- vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
-- vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", { expr = true })
map("v", ">", ">gv", {}) -- Retain visual select when indenting
map("v", "<", "<gv", {}) -- Retain visual select when indenting
vim.api.nvim_set_keymap("n", "<Leader>bq",":bp <BAR> bd #<CR>", {silent=true})
vim.api.nvim_set_keymap("n", "<Leader>ff", ":Telescope find_files<cr>", {silent=true})
vim.api.nvim_set_keymap("n", "<Leader>fg", ":Telescope live_grep<cr>", {silent=true})
vim.api.nvim_set_keymap("n", "<Leader>fb", ":Telescope buffers<cr>", {silent=true})
vim.api.nvim_set_keymap("n", "<Leader>fa", ":Ag<cr>", {silent=true})
vim.api.nvim_set_keymap("n", "<leader>gb",":.GBrowse<CR>", {silent=true})
vim.api.nvim_set_keymap("n", "<C-J>", ":bprev<CR>", {silent = true})
vim.api.nvim_set_keymap("n", "<C-K>", ":bnext<CR>", {silent = true})
vim.api.nvim_set_keymap("n", "<C-o>", ":NERDTreeToggle<CR>", {silent = true})
vim.api.nvim_set_keymap("n", "<F1>", ":set invnumber invrelativenumber<CR>", {silent = true })
vim.api.nvim_set_keymap("n", "<F2>",":SearchSession<CR>", {silent = true })
vim.api.nvim_set_keymap("n", "<F8>", ":Tagbar<CR>", {silent = true })

View File

@ -0,0 +1,16 @@
local utils = { }
local scopes = {o = vim.o, b = vim.bo, w = vim.wo}
function utils.opt(scope, key, value)
scopes[scope][key] = value
if scope ~= 'o' then scopes['o'][key] = value end
end
function utils.map(mode, lhs, rhs, opts)
local options = {noremap = true}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
return utils

View File

@ -27,6 +27,13 @@
# Inject tree-sitters, since they're annoying to maintain with sideloading
(nvim-treesitter.withPlugins (plugins: pkgs.tree-sitter.allGrammars))
];
# We used to manage our own init.lua but now we want the home-manager
# managed init.vim to load our init.lua which makes this a little dirty.
extraConfig = ''
lua << EOF
${builtins.readFile ../../home/config/nvim/init.lua}
EOF
'';
};
programs.fish = {

View File

@ -1,10 +1,15 @@
{ pkgs, ... }:
{ pkgs, config, ... }:
{
xdg.configFile = {
"nvim" = {
source = ../../home/config/nvim;
recursive = true;
};
"nvim/lua" = {
source = config.lib.file.mkOutOfStoreSymlink ../config/nvim/lua;
recursive = true;
};
"nvim/legacy.vim".source = config.lib.file.mkOutOfStoreSymlink ../../home/config/nvim/legacy.vim;
"fish" = {
source = ../../home/config/fish;
recursive = true;