diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 079c924..7ac8360 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -1,74 +1,6 @@ set nocompatible -" download vim-plug if missing -if empty(glob("~/.local/share/nvim/site/autoload/plug.vim")) - silent! execute '!curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' - autocmd VimEnter * silent! PlugInstall -endif - -call plug#begin(stdpath('data') . '/plugged') - Plug 'tpope/vim-sensible' - Plug 'tpope/vim-surround' - Plug 'tpope/vim-commentary' - Plug 'tpope/vim-repeat' - Plug 'tpope/vim-dispatch' - Plug 'tpope/vim-abolish' - - Plug 'tpope/vim-fugitive' - Plug 'tpope/vim-rhubarb' - - Plug 'tpope/vim-sexp-mappings-for-regular-people' - Plug 'guns/vim-sexp' - - Plug 'christoomey/vim-sort-motion' - - Plug 'kana/vim-textobj-user' - Plug 'kana/vim-textobj-indent' - Plug 'kana/vim-textobj-line' - - Plug 'kyazdani42/nvim-web-devicons' - - Plug 'christoomey/vim-tmux-navigator' - - Plug 'preservim/nerdtree' - - Plug 'tversteeg/registers.nvim' - - Plug 'neovim/nvim-lspconfig' - Plug 'williamboman/nvim-lsp-installer' - Plug 'hrsh7th/cmp-nvim-lsp' - Plug 'hrsh7th/cmp-buffer' - Plug 'hrsh7th/cmp-path' - Plug 'hrsh7th/cmp-cmdline' - Plug 'hrsh7th/nvim-cmp' - Plug 'jose-elias-alvarez/null-ls.nvim' - - Plug 'duane9/nvim-rg' - - Plug 'tversteeg/registers.nvim' - - Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } - " https://github.com/mrjones2014/dash.nvim/issues/137 - Plug 'ibhagwan/fzf-lua', {'commit': '341f0641ea4b0bd1cb798d7138f1a84c90848b02'} - - Plug 'mrjones2014/dash.nvim', { 'do': 'make install' } - - Plug 'elixir-editors/vim-elixir' - Plug 'khaveesh/vim-fish-syntax' - Plug 'neovimhaskell/haskell-vim' - Plug 'alx741/vim-hindent' - Plug 'gleam-lang/gleam.vim' - Plug 'benknoble/vim-racket' - Plug 'vim-scripts/scribble.vim' - - Plug 'dracula/vim', { 'as': 'dracula' } -call plug#end() - - -syntax enable -filetype plugin indent on - -colorscheme dracula +lua require('plugins') set number set relativenumber @@ -79,70 +11,6 @@ set expandtab set mouse=a -set cmdheight=2 +colorscheme dracula -set nobackup -set nowritebackup - -set spell - -let mapleader=',' - -nnoremap ; : -nnoremap q; q: -vnoremap ; : -vnoremap q; q: - -nnoremap w :w -nnoremap wq :wq - -nnoremap q :q - -nnoremap :nohlsearch - -nnoremap :NERDTreeToggle - -" Copy to clipboard -vnoremap y "+y -nnoremap Y "+yg_ -nnoremap y "+y - -" Paste from clipboard -nnoremap p "+p -nnoremap P "+P -vnoremap p "+p -vnoremap P "+P - -nnoremap ~ :split ~/.config/nvim/init.vim -nnoremap so :so % - -nnoremap f lua require('fzf-lua').files() -nnoremap a lua require('fzf-lua').grep_project() - -" nnoremap gs :Git -nnoremap gs :Git -nnoremap gp :Git push --force-with-lease -u origin head -nnoremap gf :Git fetch -nnoremap gr :Git rebase origin/main -nnoremap gb :Git checkout -b - -luafile ~/.config/nvim/lua/lsp-setup.lua - -" lua require('gitsigns').setup() - -nnoremap o :only - -lua require('dash').setup({ file_type_keywords = { elixir = { 'ex' } } }) - -nnoremap d lua require('dash').search() - -" Terminal mode -tnoremap -tnoremap h -tnoremap j -tnoremap k -tnoremap l - - -let g:vim_markdown_frontmatter = 1 -let g:vim_markdown_toml_frontmatter = 1 +lua require('keys') diff --git a/.config/nvim/lua/keys.lua b/.config/nvim/lua/keys.lua new file mode 100644 index 0000000..e87c7f8 --- /dev/null +++ b/.config/nvim/lua/keys.lua @@ -0,0 +1,49 @@ +local wk = require('which-key') +local map = vim.keymap.set + +wk.setup({ + key_labels = { + [''] = 'SPC', + [''] = 'RET', + [''] = 'TAB' + } +}) + +vim.opt.timeoutlen = 500 + +vim.g.mapleader = ' ' + +map({ 'n', 'v' }, ';', ':') +map({ 'n', 'v' }, 'q;', 'q:') + +wk.register({ + [''] = { 'Telescope find_files', 'File file in project' }, + ['/'] = { 'Telescope live_grep', 'Search project' }, + [''] = { 'NERDTreeToggle', 'Toggle NERDTree' }, + + f = { + name = 'file', + e = { 'Telescope find_files cwd=~/.config/nvim', 'Find file in .config/nvim' }, + E = { 'e ~/.config/nvim', 'Browse .config/nvim' }, + f = { 'Telescope find_files cwd=~/ hidden=true no_ignore=true no_ignore_parent=true follow=true', 'Find file' }, + F = { 'Telescope find_files', 'File file from here' }, + l = { 'NERDTreeFind', 'Locate file' }, + r = { 'Telescope oldfiles', 'Recent files' }, + }, + + q = { + name = 'quit/session', + b = { 'q', 'Buffer' }, + q = { 'qa', 'Neovim' }, + }, + + e = { + name = 'editor', + p = { + name = 'packer', + s = { 'PackerSync', 'Packer Sync' }, + c = { 'PackerCompile', 'Packer Compile' }, + l = { 'PackerClean', 'Packer Clean' }, + } + } +}, { prefix = '' }) diff --git a/.config/nvim/lua/lsp-setup.lua b/.config/nvim/lua/lsp-setup.lua deleted file mode 100644 index 96d1ade..0000000 --- a/.config/nvim/lua/lsp-setup.lua +++ /dev/null @@ -1,105 +0,0 @@ -local lsp_installer = require("nvim-lsp-installer") - -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.diagnostic.open_float()', opts) - -- buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', opts) - -- buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', opts) - -- buf_set_keymap('n', 'q', 'lua vim.diagnostic.setloclist()', opts) - -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) - - if client.resolved_capabilities.document_formatting then - vim.cmd([[ - augroup LspFormatting - autocmd! * - autocmd BufWritePre lua vim.lsp.buf.formatting_sync() - augroup END - ]]) - end - - - -- Setup nvim-cmp. - local cmp = require'cmp' - - cmp.setup({ - snippet = { - -- REQUIRED - you must specify a snippet engine - expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. - -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. - -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. - end, - }, - mapping = { - [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), - [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. - [''] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - }, { - { name = 'buffer' }, - }) - }) - - -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). - cmp.setup.cmdline('/', { - sources = { - { name = 'buffer' } - } - }) - - -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). - cmp.setup.cmdline(':', { - sources = cmp.config.sources({ - { name = 'path' } - }, { - { name = 'cmdline' } - }) - }) -end - --- Register a handler that will be called for all installed servers. --- Alternatively, you may also register handlers on specific server instances instead (see example below). -lsp_installer.on_server_ready(function(server) - local opts = { - on_attach = on_attach - } - - -- (optional) Customize the options passed to the server - -- if server.name == "tsserver" then - -- opts.root_dir = function() ... end - -- end - - -- This setup() function is exactly the same as lspconfig's setup function. - -- Refer to https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md - server:setup(opts) -end) diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua new file mode 100644 index 0000000..b99050d --- /dev/null +++ b/.config/nvim/lua/plugins.lua @@ -0,0 +1,78 @@ +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() + +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]]) + +return require('packer').startup(function(use) + use 'wbthomason/packer.nvim' + + use 'tpope/vim-sensible' + use 'tpope/vim-surround' + use 'tpope/vim-commentary' + use 'tpope/vim-repeat' + use 'tpope/vim-dispatch' + use 'tpope/vim-abolish' + + use { + 'tpope/vim-fugitive', + 'tpope/vim-rhubarb', + } + + use 'christoomey/vim-sort-motion' + use 'christoomey/vim-tmux-navigator' + + use { + 'kana/vim-textobj-user', + 'kana/vim-textobj-indent', + 'kana/vim-textobj-line', + } + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.0', + requires = { + { 'nvim-lua/plenary.nvim' }, + { 'nvim-telescope/telescope-fzf-native.nvim', run='make' } + }, + config = function() + require('telescope').setup() + require('telescope').load_extension('fzf') + end + } + + use { 'folke/which-key.nvim', config = function() require('keys') end } + + use 'preservim/nerdtree' + + use { + { 'williamboman/mason.nvim', config = function() require('mason').setup() end }, + 'williamboman/mason-lspconfig.nvim', + 'neovim/nvim-lspconfig', + 'mfussenegger/nvim-dap', + 'jose-elias-alvarez/null-ls.nvim', + 'mhartington/formatter.nvim', + } + + + use { 'dracula/vim', as = 'dracula' } + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end)