From 5ea3f3c3457e68766424309a5583d57c859cf9a7 Mon Sep 17 00:00:00 2001 From: PowerUser64 Date: Fri, 3 Sep 2021 01:18:44 -0700 Subject: [PATCH] began nvim migration to lua --- .config/nvim/init.lua | 5 + .config/nvim/{init.vim => init.vim.bak} | 0 .config/nvim/lua/lsp.lua | 150 ++++++++++++++++++++++++ .config/nvim/lua/other.lua | 86 ++++++++++++++ .config/nvim/lua/plugins.lua | 125 ++++++++++++++++++++ .config/nvim/lua/settings.lua | 147 +++++++++++++++++++++++ 6 files changed, 513 insertions(+) create mode 100644 .config/nvim/init.lua rename .config/nvim/{init.vim => init.vim.bak} (100%) create mode 100644 .config/nvim/lua/lsp.lua create mode 100644 .config/nvim/lua/other.lua create mode 100644 .config/nvim/lua/plugins.lua create mode 100644 .config/nvim/lua/settings.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua new file mode 100644 index 0000000..d307be4 --- /dev/null +++ b/.config/nvim/init.lua @@ -0,0 +1,5 @@ +-- basic settings: ~/.config/nvim/lua/settings.lua +require('settings') +-- plugins and plugin settings: ~/.config/nvim/lua/plugins.lua +require('plugins') + diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim.bak similarity index 100% rename from .config/nvim/init.vim rename to .config/nvim/init.vim.bak diff --git a/.config/nvim/lua/lsp.lua b/.config/nvim/lua/lsp.lua new file mode 100644 index 0000000..96525e0 --- /dev/null +++ b/.config/nvim/lua/lsp.lua @@ -0,0 +1,150 @@ +local M = {} + +-- lsp_signature +M.signature = function() + cfg = { + Gse_lspsaga = true + } +end + +-- lspinstall +M.lspinstall = function() + local function setup_servers() + require'lspinstall'.setup() + local servers = require'lspinstall'.installed_servers() + for _, server in pairs(servers) do + require'lspconfig'[server].setup{} + end + end + + setup_servers() + + -- Automatically reload after `:LspInstall ` so we don't have to restart neovim + require'lspinstall'.post_install_hook = function () + setup_servers() -- reload installed servers + vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server + end +end + +-- treesitter +M.treesitter = function () + require'nvim-treesitter.configs'.setup { + ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages + --ignore_install = { "javascript", "java" }, -- List of parsers to ignore installing + highlight = { + enable = true, -- false will disable the whole extension + -- disable = { "c", "rust" }, -- list of language that will be disabled + -- 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, + }, + indent = { + enable = true + } + } +end + +-- lspkind +M.lspkind = function() + require('lspkind').init({ + -- enables text annotations + -- + -- default: true + with_text = true, + + -- default symbol map + -- can be either 'default' (requires nerd-fonts font) or + -- 'codicons' for codicon preset (requires vscode-codicons font) + -- + -- default: 'default' + preset = 'codicons', + + -- override preset symbols + -- + -- default: {} + symbol_map = { + Text = "", + Method = "", + Function = "", + Constructor = "", + Field = "ﰠ", + Variable = "", + Class = "ﴯ", + Interface = "", + Module = "", + Property = "ﰠ", + Unit = "塞", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "פּ", + Event = "", + Operator = "", + TypeParameter = "" + }, + }) +end + +-- lspconfig +M.lspconfig = function() + local nvim_lsp = require('lspconfig') + + -- Use an on_attach function to only map the following keys + -- after the language server attaches to the current buffer + local on_attach = function(client, bufnr) + local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end + local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + + -- Enable completion triggered by + buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + + -- Mappings. + local opts = { noremap=true, silent=true } + + -- See `:help vim.lsp.*` for documentation on any of the below functions + buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) + buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + + end + + -- Use a loop to conveniently call 'setup' on multiple servers and + -- map buffer local keybindings when the language server attaches + local servers = { 'pyright', 'rust_analyzer', 'tsserver' } + for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } + end +end + +return M + +-- vim:expandtab:tabstop=3:sw=3 + diff --git a/.config/nvim/lua/other.lua b/.config/nvim/lua/other.lua new file mode 100644 index 0000000..ca217c0 --- /dev/null +++ b/.config/nvim/lua/other.lua @@ -0,0 +1,86 @@ +local M = {} + +-- nvimtree +M.nvimtree = function () + local tree_cb = require'nvim-tree.config'.nvim_tree_callback + -- default mappings + vim.g.nvim_tree_bindings = { + { key = {"", "o", "<2-LeftMouse>"}, cb = tree_cb("edit") }, + { key = {"<2-RightMouse>", ""}, cb = tree_cb("cd") }, + { key = "", cb = tree_cb("vsplit") }, + { key = "", cb = tree_cb("split") }, + { key = "", cb = tree_cb("tabnew") }, + { key = "<", cb = tree_cb("prev_sibling") }, + { key = ">", cb = tree_cb("next_sibling") }, + { key = "P", cb = tree_cb("parent_node") }, + { key = "", cb = tree_cb("close_node") }, + { key = "", cb = tree_cb("close_node") }, + { key = "", cb = tree_cb("preview") }, + { key = "K", cb = tree_cb("first_sibling") }, + { key = "J", cb = tree_cb("last_sibling") }, + { key = "I", cb = tree_cb("toggle_ignored") }, + { key = "H", cb = tree_cb("toggle_dotfiles") }, + { key = "R", cb = tree_cb("refresh") }, + { key = "a", cb = tree_cb("create") }, + { key = "d", cb = tree_cb("remove") }, + { key = "r", cb = tree_cb("rename") }, + { key = "", cb = tree_cb("full_rename") }, + { key = "x", cb = tree_cb("cut") }, + { key = "c", cb = tree_cb("copy") }, + { key = "p", cb = tree_cb("paste") }, + { key = "y", cb = tree_cb("copy_name") }, + { key = "Y", cb = tree_cb("copy_path") }, + { key = "gy", cb = tree_cb("copy_absolute_path") }, + { key = "[c", cb = tree_cb("prev_git_item") }, + { key = "]c", cb = tree_cb("next_git_item") }, + { key = "-", cb = tree_cb("dir_up") }, + { key = "s", cb = tree_cb("system_open") }, + { key = "q", cb = tree_cb("close") }, + { key = "g?", cb = tree_cb("toggle_help") }, + } +end + +-- toggleterm +M.toggleterm = function() + require("toggleterm").setup{ + -- size can be a number or function which is passed the current terminal + -- size = 20 | function(term) + -- if term.direction == "horizontal" then + -- return 15 + -- elseif term.direction == "vertical" then + -- return vim.o.columns * 0.4 + -- end + -- end, + open_mapping = [[]], + toggleterm_terminal_mapping = 't', + hide_numbers = true, -- hide the number column in toggleterm buffers + shade_filetypes = {}, + shade_terminals = true, + shading_factor = '1', -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light + start_in_insert = true, + insert_mappings = true, -- whether or not the open mapping applies in insert mode + persist_size = true, + direction = 'vertical', -- | 'horizontal' | 'window' | 'float', + close_on_exit = true, -- close the terminal window when the process exits + -- shell = vim.o.shell, -- change the default shell + -- This field is only relevant if direction is set to 'float' + float_opts = { + -- The border key is *almost* the same as 'nvim_open_win' + -- see :h nvim_open_win for details on borders however + -- the 'curved' border is a custom border type + -- not natively supported but implemented in this plugin. + border = 'single', + width = 120, + height = 32, + winblend = 3, + highlights = { + border = "Normal", + background = "Normal", + } + } + } +end + +return M + +-- vim:expandtab:tabstop=3:sw=3 diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..6face5b --- /dev/null +++ b/.config/nvim/lua/plugins.lua @@ -0,0 +1,125 @@ +-- Load plugins +-- Bootstrap packer if needed +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' +end + +return require('packer').startup(function() + -- Packer + use { -- plugins + 'wbthomason/packer.nvim' + } + + -- Colors + use { -- syntax highlighting + 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate', + config = function() + require("lsp").treesitter() + end, + } + use { -- onedark theme + 'navarasu/onedark.nvim', + config = function() + vim.cmd 'colorscheme onedark' + end + } + use { -- color tag highlighter + 'norcalli/nvim-colorizer.lua' + } + + -- IDE features + ---- LSP + use { -- lsp installer + "kabouzeid/nvim-lspinstall", + -- opt = true, + -- setup = function() + -- require("other").packer_lazy_load "nvim-lspinstall" + -- -- reload the current file so lsp actually starts for it + -- vim.defer_fn(function() + -- vim.cmd "silent! e %" + -- end, 0) + -- end, + } + use { -- Default LSP configs + "neovim/nvim-lspconfig", + after = "nvim-lspinstall", + config = function() + require("lsp").lspconfig() + end + } + use { -- function parameter previews + "ray-x/lsp_signature.nvim", + after = "nvim-lspconfig", + config = function() + require("lsp").signature() + end, + } + use { -- Use the % key for more things + "andymass/vim-matchup", + -- setup = function() + -- require("other").packer_lazy_load "vim-matchup" + -- end, + } + use 'dense-analysis/ale' + + ---- Other IDE fratures + use { -- git integration + 'lewis6991/gitsigns.nvim', + requires = { + 'nvim-lua/plenary.nvim' + }, + -- config = function() + -- require('other').gitsigns() + -- end + } + use { -- file manager + 'kyazdani42/nvim-tree.lua', + requires = 'kyazdani42/nvim-web-devicons', + config = function() + require('other').nvimtree() + end + } + use { -- terminal + "akinsho/toggleterm.nvim", + config = function() + require('other').toggleterm() + end + } + + -- Conveniences + use { -- Undo tree + 'mbbill/undotree', + } + use { -- Quote pairing + 'jiangmiao/auto-pairs' + } + use { -- Alignment + 'junegunn/vim-easy-align', + } + use { -- Quote/parenthesis changing + 'tpope/vim-surround' + } + -- use { -- Some sensible defaults + -- 'tpope/vim-sensible' + -- } + use { -- Comments + 'tpope/vim-commentary' + } + -- use { -- Comments (lua) + -- "terrortylor/nvim-comment", + -- require('conveniences').nvim_comment() + -- } + use { -- git integration + 'tpope/vim-fugitive' + } + use { -- Repeatability for various tpope plugins + 'tpope/vim-repeat', + } + +end) + +-- vim:fdm=marker:fmr={,}:expandtab:tabstop=3:sw=3 + diff --git a/.config/nvim/lua/settings.lua b/.config/nvim/lua/settings.lua new file mode 100644 index 0000000..de4143d --- /dev/null +++ b/.config/nvim/lua/settings.lua @@ -0,0 +1,147 @@ +vim.cmd [[ +set suffixes+=.aux,.bbl,.blg,.brf,.cb,.dvi,.idx,.ilg,.ind,.inx,.jpg,.log,.out,.png,.toc +set suffixes-=.h +set suffixes-=.obj + +set tabstop=3 softtabstop=3 +set shiftwidth=3 +set expandtab +set smartindent +" set foldmethod=indent +" set foldlevel=0 + +set undodir=~/.vim/undo +set undofile + +set guifont=SauceCodePro\ NF\ Regular + +set hlsearch +set hidden +set ignorecase +set smartcase +set wrap +set linebreak +" set guicursor= " always use the block cursor +syntax on +set redrawtime=1000 " max syntax highlight time +set number relativenumber +set noerrorbells +set encoding=UTF-8 +set cursorline +set mouse=a +set incsearch +set scrolloff=6 +" set wildmenu +" set wildmode=full +" TextEdit might fail if hidden is not set. +set hidden +set cmdheight=1 " Give more space for displaying messages. +" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable +" delays and poor user experience. +set updatetime=300 +" Don't pass messages to |ins-completion-menu|. +set shortmess+=c +" Spell check! +set spell spelllang=en_us +" spell check in git commits +autocmd Filetype gitcommit setlocal spell +set showcmd +set signcolumn=yes +" disable spell check in help files +autocmd FileType help setlocal nospell +filetype plugin on +" Macro for opening a new terminal with spell check off +command! Term tabnew | setlocal nospell | term +autocmd FileType help setlocal nospell +" test whitespace -> +" more test whitespace -> + " Indented text + " even more test whitespace -> + +" Key bindings +let mapleader = " " +" *sigh*... +command! Q q +command! W w +command! Wq wq +command! WQ wq +" nnoremap ; : +" vnoremap ; : +" Press Alt h to toggle highlighting on/off, and show current value. +noremap :set hlsearch! hlsearch? +" Escape to enter normal mode in the terminal +tnoremap +" Replace with alt S +nnoremap :%s//g +" Wrapped line movement (hold ctrl to move like a word processor) +nmap h +nmap gj +nmap gk +nmap l +" nmap g$ +nmap $ g$ +nmap g^ +nmap g^ +nmap g^ +vmap h +vmap gj +vmap gk +vmap l +vmap g$ +vmap $ g$ +vmap g^ +vmap g^ +vmap g^ +" " Hold ctrl to move between windows, shift to reorder the windows +" nmap h +" nmap j +" nmap k +" nmap l +" nmap H +" nmap J +" nmap K +" nmap L +" " and for visual mode +" vmap h +" vmap j +" vmap k +" vmap l +" vmap H +" vmap J +" vmap K +" vmap L + + colorscheme slate +]] + +vim.cmd [[ +""""""" Quality of life things that aren't one line (also from stack overflow and stuff) +"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux. +"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support +"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.) +if (empty($TMUX)) + if (has("nvim")) + "For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 > + let $NVIM_TUI_ENABLE_TRUE_COLOR=1 + endif + "For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 > + "Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd > + " < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 > + if (has("termguicolors")) + set termguicolors + endif +endif +]] + +-- 'Visual At' plugin (https://github.com/stoeffel/.dotfiles/blob/master/vim/visual-at.vim) +vim.cmd [[ +xnoremap @ :call ExecuteMacroOverVisualRange() +function! ExecuteMacroOverVisualRange() + echo "@".getcmdline() + execute ":'<,'>normal @".nr2char(getchar()) +endfunction +]] + +-- Automatically jump to the last position in a file when opening +vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]] +