From b247e6f8ed8e4ed6b11eb910da935b106b8fe2a6 Mon Sep 17 00:00:00 2001 From: Proctor Date: Thu, 12 Aug 2021 14:27:32 -0500 Subject: [PATCH] move nvim config to here to use stow --- nvim/.config/nvim/fnl/my_nvim/core.fnl | 96 +++++++++++++++++++ nvim/.config/nvim/fnl/my_nvim/init.fnl | 10 ++ nvim/.config/nvim/fnl/my_nvim/mapping.fnl | 59 ++++++++++++ nvim/.config/nvim/init.lua | 111 ++++++++++++++++++++++ nvim/.config/nvim/tools.lua | 12 +++ 5 files changed, 288 insertions(+) create mode 100644 nvim/.config/nvim/fnl/my_nvim/core.fnl create mode 100644 nvim/.config/nvim/fnl/my_nvim/init.fnl create mode 100644 nvim/.config/nvim/fnl/my_nvim/mapping.fnl create mode 100644 nvim/.config/nvim/init.lua create mode 100644 nvim/.config/nvim/tools.lua diff --git a/nvim/.config/nvim/fnl/my_nvim/core.fnl b/nvim/.config/nvim/fnl/my_nvim/core.fnl new file mode 100644 index 0000000..124e659 --- /dev/null +++ b/nvim/.config/nvim/fnl/my_nvim/core.fnl @@ -0,0 +1,96 @@ +(module my_vim.core + {autoload + {a aniseed.core} + require + {nvim aniseed.nvim}}) + + +(nvim.ex.set "shortmess+=c") ; don't give |ins-completion-menu| messages. +(nvim.ex.set "path+=**") +(nvim.ex.set "wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*") + +(defn- safe-source + [filename] + (let [glob (nvim.fn.glob filename)] + (if (not (a.empty? glob)) + (nvim.ex.source filename)))) + +(a.map safe-source ["~/.vimrc" "~/.vimrc.local"]) + + +(def- backup-dir "$HOME/.vim/backup") +(def- undo-dir "$HOME.vim/undo") + +(def- on-opts [ + :autoindent + :autoread + :expandtab + :exrc ; allow project level (neo)vim files + :hlsearch + :ignorecase + :incsearch + :number + :ruler + :secure + :shiftround ; When at 3 spaces and I hit >>, go to 4, not 5. + :showcmd ; shows (parital) command in the status line + :showmatch + :smartcase + :splitbelow + :splitright + :termguicolors + :title + :undofile + :wildmenu + ]) + + +(def- val-based-opts + { + :t_Co 256 + :laststatus 2 + :encoding "utf-8" + :history 500 + :redrawtime 5000 + :scrolloff 3 + :guifont "Hasklig" + :background "dark" + :backupdir backup-dir + :directory backup-dir ;Don't clutter my dirs up with swp and tmp files + :grepprg "ag" ; Use Silver Searcher instead of grep + :tags "tags" + :updatetime 300 ; per coc.vim for diagnostic messages + :signcolumn "auto:1-3" + :cmdheight 2 ; Better display for messages + :undodir undo-dir + :undolevels 1000 + :undoreload 10000 + :foldmethod "expr" + :foldexpr "nvim_treesitter#foldexpr()" + :foldlevelstart 99 + :foldlevel 99 + :tabstop 2 + :shiftwidth 2 + :softtabstop 2 + :list "listchars=tab:➥\\ ,trail:·" + :backspace "indent,eol,start" ;allow backspacing over everything in insert mode + :wildmode "list:longest,list:full" + :wrap "off" + }) + +(defn- set-opt + [[opt val]] + (tset vim.opt (a.str opt) val)) + +(defn- set-opt-on + [opt] + (set-opt [opt true])) + +(a.map set-opt-on on-opts) + +(a.map set-opt val-based-opts) + +(nvim.ex.syntax "on") +(nvim.ex.colorscheme "solarized8") + +(nvim.fn.glob "~/.vimrc.local") diff --git a/nvim/.config/nvim/fnl/my_nvim/init.fnl b/nvim/.config/nvim/fnl/my_nvim/init.fnl new file mode 100644 index 0000000..d04aa37 --- /dev/null +++ b/nvim/.config/nvim/fnl/my_nvim/init.fnl @@ -0,0 +1,10 @@ +(module my_vim.init + {autoload + {a aniseed.core} + require + {nvim aniseed.nvim}}) + +(nvim.ex.source "~/.vimrc") + +(require :my_nvim.core) +(require :my_nvim.mapping) diff --git a/nvim/.config/nvim/fnl/my_nvim/mapping.fnl b/nvim/.config/nvim/fnl/my_nvim/mapping.fnl new file mode 100644 index 0000000..35a8915 --- /dev/null +++ b/nvim/.config/nvim/fnl/my_nvim/mapping.fnl @@ -0,0 +1,59 @@ +(module my_nvim.mapping + {autoload {nvim aniseed.nvim + nu aniseed.nvim.util + core aniseed.core}}) + +(defn- noremap [mode from to] + "Sets a mapping with {:noremap true}." + (nvim.set_keymap mode from to {:noremap true})) + +; (set nvim.g.mapleader "\\") + +(noremap :n "`" ":source ~/.config/nvim/init.lua") + +(noremap :n : ":nohlsearch/") + +;; Correct to first spelling suggestion. +(noremap :n :zz ":normal! 1z=") + + +;; nice paste from clipboard in insert mode +(noremap :i : ":set paste+:set nopaste") + + +; Insert Date +(noremap :n : "\"=strftime(\"%F\")p") +(noremap :i : "=strftime(\"%F\")") + +; Make markdown link with empty url +;map ah S +(noremap :v :ah "S") +(noremap :v :ml "xi[\"]()") + + +(noremap :n : "3") +(noremap :n : "3") + +; Unimpaired configuration +; Bubble single lines +(noremap :n : "[e") +(noremap :n : "]e") +; Bubble multiple lines +(noremap :v : "[egv") +(noremap :v : "]egv") + +; Format JSON +(noremap :n :jpp ":%!python -m json.tool --indent=2") + +; Map w!! to write readonly files +(noremap :c :w!! "w !sudo tee % >/dev/null") + +(noremap :n :gnh ":GitGutterNextHunk") +(noremap :n :gph ":GitGutterPrevHunk") +(noremap :n :gsh ":GitGutterStageHunk") + +(noremap :n :li "LspInfo") +;vim.api.nvim_set_keymap('n', 'li', 'LspInfo', { noremap=true, silent=true }) + +; Open file in Marked 2 (markdown viewer) +(noremap :n :mv ":AsyncRun -mode=bang open -a Marked\\ 2.app \'%:p\'") diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua new file mode 100644 index 0000000..c321d42 --- /dev/null +++ b/nvim/.config/nvim/init.lua @@ -0,0 +1,111 @@ +-- Source init.vim for migration of vimrc to neovim +vim.fn.sign_define("LspDiagnosticsSignError", + {texthl = "LspDiagnosticsSignError", text = "☢️", numhl = "LspDiagnosticsSignError"}) +vim.fn.sign_define("LspDiagnosticsSignWarning", + {texthl = "LspDiagnosticsSignWarning", text = "⚠️", numhl = "LspDiagnosticsSignWarning"}) +vim.fn.sign_define("LspDiagnosticsSignHint", + {texthl = "LspDiagnosticsSignHint", text = "🔎", numhl = "LspDiagnosticsSignHint"}) +vim.fn.sign_define("LspDiagnosticsSignInformation", + {texthl = "LspDiagnosticsSignInformation", text = "ℹ️", numhl = "LspDiagnosticsSignInformation"}) + +local nvim_lsp = require('lspconfig') + +function LspExecuteCommand(cmd, ...) + arguments = {vim.uri_from_bufnr(0), vim.api.nvim_win_get_cursor(0)[1] - 1, vim.api.nvim_win_get_cursor(0)[2] -1} + for _,a in pairs({...}) do table.insert(arguments, a) end + vim.lsp.buf.execute_command({command = cmd, arguments = arguments}) +end + +-- 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', 'gi', 'lua vim.lsp.buf.implementation()', opts) + buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'gs', 'lua vim.lsp.buf.document_symbol()', opts) + buf_set_keymap('n', 'gS', 'lua vim.lsp.buf.workspace_symbol()', opts) + buf_set_keymap('n', 'gt', 'lua vim.lsp.buf.type_definition()', opts) + buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', '[g', 'lua vim.lsp.diagnostic.goto_prev()', opts) + buf_set_keymap('n', ']g', 'lua vim.lsp.diagnostic.goto_next()', 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', 'rn', 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + buf_set_keymap('n', 'cn', "lua LspExecuteCommand('clean-ns')", opts) + buf_set_keymap('n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + buf_set_keymap('n', 'ref', "lua LspExecuteCommand('extract-function', vim.api.nvim_eval(\"input('Function name: ')\"))", opts) + buf_set_keymap('x', 'ref', "lua LspExecuteCommand('extract-function', vim.api.nvim_eval(\"input('Function name: ')\"))", opts) + buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + buf_set_keymap('n', 'fa', "lua vim.lsp.buf.formatting_sync()", opts) + buf_set_keymap('x', 'fa', "lua vim.lsp.buf.formatting_sync()", opts) + buf_set_keymap('n', 'ic', "lua vim.lsp.buf.incoming_calls()", opts) + buf_set_keymap('x', 'ic', "lua vim.lsp.buf.incoming_calls()", opts) + buf_set_keymap('n', 'id', "lua LspExecuteCommand('inline-symbol')", opts) + buf_set_keymap('x', 'id', "lua LspExecuteCommand('inline-symbol')", opts) + buf_set_keymap('n', 'il', "lua LspExecuteCommand('introduce-let', vim.api.nvim_eval(\"input('Binding name: ')\"))", opts) + buf_set_keymap('x', 'il', "lua LspExecuteCommand('introduce-let', vim.api.nvim_eval(\"input('Binding name: ')\"))", opts) + buf_set_keymap('n', 'm2l', "lua LspExecuteCommand('move-to-let', vim.api.nvim_eval(\"input('Binding name: ')\"))", opts) + buf_set_keymap('x', 'm2l', "lua LspExecuteCommand('move-to-let', vim.api.nvim_eval(\"input('Binding name: ')\"))", opts) + + vim.api.nvim_command[[autocmd BufWritePre lua vim.lsp.buf.formatting_sync()]] + -- vim.api.nvim_command[[autocmd BufWritePre lua vim.lsp.buf_request_sync(vim.api.nvim_get_current_buf(), 'workspace/executeCommand', {command = 'clean-ns', arguments = {vim.uri_from_bufnr(0), vim.api.nvim_win_get_cursor(0)[1], vim.api.nvim_win_get_cursor(0)[2]}, title = 'Clean Namespace'})]] + + vim.api.nvim_command[[lua print("Lsp Client Attached.")]] +end + + +-- vim.api.nvim_set_keymap('n', 'li', 'LspInfo', { noremap=true, silent=true }) + + +local function setup_servers() + require'lspinstall'.setup() + local servers = require'lspinstall'.installed_servers() + for _, server in pairs(servers) do + require'lspconfig'[server].setup{ + on_attach = on_attach, + flags = { + debounce_text_changes = 150, + } + } + 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 + + +-- require'nvim-treesitter.configs'.setup { +-- ensure_installed = "all", -- one of "all", "maintained" (parsers with maintainers), or a list of languages +-- -- ignore_install = { "javascript" }, -- 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, +-- -- }, +-- } +-- +-- +vim.g["aniseed#env"] = { module = "my_nvim.init" } diff --git a/nvim/.config/nvim/tools.lua b/nvim/.config/nvim/tools.lua new file mode 100644 index 0000000..803bab2 --- /dev/null +++ b/nvim/.config/nvim/tools.lua @@ -0,0 +1,12 @@ +local api = vim.api + +local M = {} + +function M.makeScratch() + api.nvim_command [[enew]] -- equivalent to :enew + vim.bo[0].buftype=nofile -- set the current buffer's (buffer 0) buftype to nofile + vim.bo[0].bufhidden=hide + vim.bo[0].swapfile=false +end + +return M