initial changes to migrate nvim config to lua

This commit is contained in:
Salar Rahmanian 2021-07-11 15:06:37 -07:00
parent 9a75f9a72e
commit 811706c9fa
4 changed files with 540 additions and 44 deletions

View file

@ -161,56 +161,63 @@
end end
''; '';
# Neovim Configuration
xdg.configFile."nvim/lua/salargalaxyline.lua".source = programs/neovimlua/settings/salargalaxyline.lua;
xdg.configFile."nvim/init.lua".source = programs/neovimlua/init.lua;
home.packages = [ home.packages = [
pkgs.awscli pkgs.adoptopenjdk-bin
pkgs.pgcli
pkgs.tig
pkgs.ripgrep
pkgs.hugo
pkgs.jansson
pkgs.universal-ctags
pkgs.httpie
pkgs.global
pkgs.fd
pkgs.curlFull
pkgs.wget
pkgs.readline
pkgs.tree
pkgs.exa
pkgs.openssl
pkgs.xz
pkgs.gitAndTools.diff-so-fancy
pkgs.ranger
pkgs.gnupg
pkgs.niv
pkgs.ffmpeg
pkgs.gradle
pkgs.maven
pkgs.procs
pkgs.shellcheck
pkgs.cabal-install
pkgs.hlint
pkgs.ghcid
pkgs.pandoc
pkgs.multimarkdown
pkgs.direnv
pkgs.nixfmt
pkgs.cmake
pkgs.any-nix-shell pkgs.any-nix-shell
pkgs.asciinema pkgs.asciinema
pkgs.ncdu
pkgs.prettyping
pkgs.rnix-lsp
pkgs.aspell pkgs.aspell
pkgs.procs pkgs.awscli
pkgs.cabal-install
pkgs.cmake
pkgs.coursier
pkgs.curlFull
pkgs.direnv
pkgs.dust pkgs.dust
pkgs.tokei pkgs.exa
pkgs.tealdeer pkgs.fd
pkgs.hyperfine pkgs.ffmpeg
pkgs.ghcid
pkgs.gitAndTools.diff-so-fancy
pkgs.global
pkgs.gnupg
pkgs.gradle
pkgs.graphviz pkgs.graphviz
pkgs.hlint
pkgs.httpie
pkgs.hugo
pkgs.hyperfine
pkgs.jansson
pkgs.maven
pkgs.multimarkdown
pkgs.ncdu
pkgs.neofetch pkgs.neofetch
pkgs.adoptopenjdk-openj9-bin-16 pkgs.neovim
pkgs.vscodium pkgs.niv
pkgs.nixFlakes pkgs.nixFlakes
pkgs.nixfmt
pkgs.nodePackages.pyright
pkgs.openssl
pkgs.pandoc
pkgs.pgcli
pkgs.prettyping
pkgs.procs
pkgs.procs
pkgs.ranger
pkgs.readline
pkgs.ripgrep
pkgs.rnix-lsp
pkgs.shellcheck
pkgs.tealdeer
pkgs.tig
pkgs.tokei
pkgs.tree
pkgs.universal-ctags
pkgs.vscodium
pkgs.wget
pkgs.xz
]; ];
} }

View file

@ -1,4 +1,4 @@
[ [
./git ./git
./neovim # ./neovim
] ]

301
programs/neovimlua/init.lua Normal file
View file

@ -0,0 +1,301 @@
local execute = vim.api.nvim_command
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
local function load_plugins()
local use = require('packer').use
require('packer').startup(function()
use 'wbthomason/packer.nvim' -- Package manager
use 'nvim-treesitter/nvim-treesitter'
use 'folke/which-key.nvim'
use 'tpope/vim-commentary' -- "gc" to comment visual regions/lines
use {'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}} }
use 'folke/tokyonight.nvim' -- Theme
use 'windwp/nvim-autopairs' -- Autopairs
use 'kyazdani42/nvim-tree.lua' -- File explorer
use { 'glepnir/galaxyline.nvim', config = function() require'salargalaxyline' end, requires = {'kyazdani42/nvim-web-devicons'} }
use 'lukas-reineke/indent-blankline.nvim'
use { 'lewis6991/gitsigns.nvim', requires = {'nvim-lua/plenary.nvim'} }
use { 'TimUntersberger/neogit', requires = 'nvim-lua/plenary.nvim' }
use 'neovim/nvim-lspconfig' -- Collection of configurations for built-in LSP client
use { 'hrsh7th/nvim-compe', requires = { { 'L3MON4D3/LuaSnip' } } } -- Autocompletion plugin
use 'kevinhwang91/nvim-bqf'
use 'mfussenegger/nvim-dap'
use 'sheerun/vim-polyglot'
use 'scalameta/nvim-metals'
end)
end
_G.load_config = function()
require('nvim-autopairs').setup()
require("which-key").setup()
require("salargalaxyline")
-- Treesitter
require("nvim-treesitter.configs").setup({
playground = { enable = true },
query_linter = {
enable = true,
use_virtual_text = true,
lint_events = { "BufWrite", "CursorHold" },
},
ensure_installed = "maintained",
highlight = { enable = true },
})
-- neogit
require('neogit').setup({
integrations = {
diffview = false
}
})
--Incremental live completion
vim.o.inccommand = "nosplit"
--Set highlight on search
vim.o.hlsearch = false
vim.o.incsearch = true
--Make line numbers default
vim.wo.number = true
--Do not save when switching buffers
vim.o.hidden = true
--Enable mouse mode
vim.o.mouse = "a"
-- clipboard
vim.o.clipboard = 'unnamedplus'
--Enable break indent
vim.o.breakindent = true
--Save undo history
vim.cmd[[set undofile]]
--Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
--Decrease update time
vim.o.updatetime = 250
vim.wo.signcolumn="yes"
--Set colorscheme (order is important here)
vim.g.tokyonight_style = "night"
vim.g.tokyonight_italic_functions = true
vim.o.termguicolors = true
vim.cmd[[colorscheme tokyonight]]
--Remap space as leader key
vim.api.nvim_set_keymap('', '<Space>', '<Nop>', { noremap = true, silent=true})
vim.g.mapleader = " "
vim.g.maplocalleader = " "
--Remap for dealing with word wrap
vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap=true, expr = true, silent = true})
vim.api.nvim_set_keymap('n', 'j', "v:count == 0 ? 'gj' : 'j'", {noremap= true, expr = true, silent = true})
--Remap escape to leave terminal mode
vim.api.nvim_set_keymap('t', '<Esc>', [[<c-\><c-n>]], {noremap = true})
--Add map to enter paste mode
vim.o.pastetoggle="<F3>"
--Map blankline
vim.g.indent_blankline_char = ""
vim.g.indent_blankline_filetype_exclude = { 'help', 'packer' }
vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile'}
vim.g.indent_blankline_char_highlight = 'LineNr'
-- Toggle to disable mouse mode and indentlines for easier paste
ToggleMouse = function()
if vim.o.mouse == 'a' then
vim.cmd[[IndentBlanklineDisable]]
vim.wo.signcolumn='no'
vim.o.mouse = 'v'
vim.wo.number = false
print("Mouse disabled")
else
vim.cmd[[IndentBlanklineEnable]]
vim.wo.signcolumn='yes'
vim.o.mouse = 'a'
vim.wo.number = true
print("Mouse enabled")
end
end
vim.api.nvim_set_keymap('n', '<F10>', '<cmd>lua ToggleMouse()<cr>', { noremap = true })
-- Telescope
require('telescope').setup {
defaults = {
mappings = {
i = {
["<C-u>"] = false,
["<C-d>"] = false,
},
},
generic_sorter = require'telescope.sorters'.get_fzy_sorter,
file_sorter = require'telescope.sorters'.get_fzy_sorter,
}
}
--Add leader shortcuts
vim.api.nvim_set_keymap('n', '<leader>f', [[<cmd>lua require('telescope.builtin').find_files()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader><space>', [[<cmd>lua require('telescope.builtin').buffers()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>l', [[<cmd>lua require('telescope.builtin').current_buffer_fuzzy_find()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>t', [[<cmd>lua require('telescope.builtin').tags()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>?', [[<cmd>lua require('telescope.builtin').oldfiles()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>sd', [[<cmd>lua require('telescope.builtin').grep_string()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>sp', [[<cmd>lua require('telescope.builtin').live_grep()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>o', [[<cmd>lua require('telescope.builtin').tags{ only_current_buffer = true }<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>gc', [[<cmd>lua require('telescope.builtin').git_commits()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>gb', [[<cmd>lua require('telescope.builtin').git_branches()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>gs', [[<cmd>lua require('telescope.builtin').git_status()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>gp', [[<cmd>lua require('telescope.builtin').git_bcommits()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>m', [[<cmd>lua require('nvim-tree').toggle()<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>ng', [[<cmd>lua require('neogit').open({ kind = "split" })<cr>]], { noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<leader>nu', ':PackerUpdate<CR>', { noremap = true, silent = true })
-- Change preview window location
vim.g.splitbelow = true
-- Highlight on yank
vim.api.nvim_exec([[
augroup YankHighlight
autocmd!
autocmd TextYankPost * silent! lua vim.highlight.on_yank()
augroup end
]], false)
-- Y yank until the end of line
vim.api.nvim_set_keymap('n', 'Y', 'y$', { noremap = true})
--
-- LSP settings
local nvim_lsp = require('lspconfig')
local on_attach = function(_client, bufnr)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gm', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
end
-- Enable the following language servers
local servers = { 'jdtls', 'pyright', 'rnix','sourcekit', 'sqlls' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup { on_attach = on_attach }
end
-- metals
vim.opt_global.shortmess:remove("F"):append("c")
metals_config = require("metals").bare_config
metals_config.init_options.statusBarProvider = "on"
vim.cmd [[augroup lsp]]
vim.cmd [[au!]]
vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]]
vim.cmd [[augroup end]]
-- Map :Format to vim.lsp.buf.formatting()
vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]])
-- Set completeopt to have a better completion experience
vim.o.completeopt="menuone,noinsert"
-- Compe setup
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = true;
source = {
path = true;
nvim_lsp = {
priority = 1000,
filetypes = { "scala", "sbt", "java" },
},
nvim_lua = true,
buffer = true,
luasnip = true,
};
}
local t = function(str)
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
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
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>"
else
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})
end
if fn.isdirectory(install_path) == 0 then
fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path})
load_plugins()
require('packer').sync()
vim.cmd 'autocmd User PackerComplete ++once lua load_config()'
else
load_plugins()
_G.load_config()
end

View file

@ -0,0 +1,188 @@
local gl = require('galaxyline')
local gls = gl.section
gl.short_line_list = {'LuaTree','vista','dbui'}
local colors = {
bg = '#282c34',
yellow = '#fabd2f',
cyan = '#008080',
darkblue = '#081633',
green = '#afd700',
orange = '#FF8800',
purple = '#5d4d7a',
magenta = '#d16d9e',
grey = '#c0c0c0',
blue = '#0087d7',
red = '#ec5f67'
}
local buffer_not_empty = function()
if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then
return true
end
return false
end
gls.left[1] = {
FirstElement = {
provider = function() return '' end,
highlight = {colors.blue,colors.yellow}
},
}
gls.left[2] = {
ViMode = {
provider = function()
local alias = {n = 'NORMAL',i = 'INSERT',c= 'COMMAND',v= 'VISUAL',V= 'VISUAL LINE', [''] = 'VISUAL BLOCK'}
return alias[vim.fn.mode()]
end,
separator = '',
separator_highlight = {colors.purple,function()
if not buffer_not_empty() then
return colors.purple
end
return colors.darkblue
end},
highlight = {colors.darkblue,colors.purple,'bold'},
},
}
gls.left[3] ={
FileIcon = {
provider = 'FileIcon',
condition = buffer_not_empty,
highlight = {require('galaxyline.provider_fileinfo').get_file_icon_color,colors.darkblue},
},
}
gls.left[4] = {
FileName = {
provider = {'FileName','FileSize'},
condition = buffer_not_empty,
separator = '',
separator_highlight = {colors.purple,colors.darkblue},
highlight = {colors.magenta,colors.darkblue}
}
}
gls.left[5] = {
GitIcon = {
provider = function() return '' end,
condition = buffer_not_empty,
highlight = {colors.orange,colors.purple},
}
}
gls.left[6] = {
GitBranch = {
provider = 'GitBranch',
condition = buffer_not_empty,
highlight = {colors.grey,colors.purple},
}
}
local checkwidth = function()
local squeeze_width = vim.fn.winwidth(0) / 2
if squeeze_width > 40 then
return true
end
return false
end
gls.left[7] = {
DiffAdd = {
provider = 'DiffAdd',
condition = checkwidth,
icon = '',
highlight = {colors.green,colors.purple},
}
}
gls.left[8] = {
DiffModified = {
provider = 'DiffModified',
condition = checkwidth,
icon = '',
highlight = {colors.orange,colors.purple},
}
}
gls.left[9] = {
DiffRemove = {
provider = 'DiffRemove',
condition = checkwidth,
icon = '',
highlight = {colors.red,colors.purple},
}
}
gls.left[10] = {
LeftEnd = {
provider = function() return '' end,
separator = '',
separator_highlight = {colors.purple,colors.bg},
highlight = {colors.purple,colors.purple}
}
}
gls.left[11] = {
DiagnosticError = {
provider = 'DiagnosticError',
icon = '',
highlight = {colors.red,colors.bg}
}
}
gls.left[12] = {
Space = {
provider = function () return ' ' end
}
}
gls.left[13] = {
DiagnosticWarn = {
provider = 'DiagnosticWarn',
icon = '',
highlight = {colors.blue,colors.bg},
}
}
gls.right[1]= {
FileFormat = {
provider = 'FileFormat',
separator = '',
separator_highlight = {colors.bg,colors.purple},
highlight = {colors.grey,colors.purple},
}
}
gls.right[2] = {
LineInfo = {
provider = 'LineColumn',
separator = ' | ',
separator_highlight = {colors.darkblue,colors.purple},
highlight = {colors.grey,colors.purple},
},
}
gls.right[3] = {
PerCent = {
provider = 'LinePercent',
separator = '',
separator_highlight = {colors.darkblue,colors.purple},
highlight = {colors.grey,colors.darkblue},
}
}
gls.right[4] = {
ScrollBar = {
provider = 'ScrollBar',
highlight = {colors.yellow,colors.purple},
}
}
gls.short_line_left[1] = {
BufferType = {
provider = 'FileTypeName',
separator = '',
separator_highlight = {colors.purple,colors.bg},
highlight = {colors.grey,colors.purple}
}
}
gls.short_line_right[1] = {
BufferIcon = {
provider= 'BufferIcon',
separator = '',
separator_highlight = {colors.purple,colors.bg},
highlight = {colors.grey,colors.purple}
}
}