From 9847dc9fabad31964243bdb42c7b772869aaa836 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 31 Aug 2024 15:32:24 +0100 Subject: [PATCH] Rewrite init.vim to init.lua --- config/home.nix | 3 +- config/packages/neovim/default.nix | 2 +- config/packages/neovim/init.lua | 242 +++++++++++++++++++++++++++++ config/packages/neovim/init.vim | 143 ----------------- 4 files changed, 245 insertions(+), 145 deletions(-) create mode 100644 config/packages/neovim/init.lua delete mode 100644 config/packages/neovim/init.vim diff --git a/config/home.nix b/config/home.nix index b6c597e..fe43bf9 100644 --- a/config/home.nix +++ b/config/home.nix @@ -96,7 +96,8 @@ in { tldr unzip vim - vimPlugins.vim-plug + vimPlugins.vim-packer + vimPlugins.packer-nvim virtio-win vscode wget diff --git a/config/packages/neovim/default.nix b/config/packages/neovim/default.nix index 4480ef2..dc0b484 100644 --- a/config/packages/neovim/default.nix +++ b/config/packages/neovim/default.nix @@ -1,4 +1,4 @@ { - home.file."/home/vylpes/.config/nvim/init.vim".source = ./init.vim; + home.file."/home/vylpes/.config/nvim/init.lua".source = ./init.lua; home.file."/home/vylpes/.config/nvim/coc-settings.json".source = ./coc-settings.json; } diff --git a/config/packages/neovim/init.lua b/config/packages/neovim/init.lua new file mode 100644 index 0000000..d188436 --- /dev/null +++ b/config/packages/neovim/init.lua @@ -0,0 +1,242 @@ +-- Leader key +vim.g.mapleader = " " + +-- Disable Copilot by default +vim.g.copilot_enabled = false + +-- Basic settings +vim.opt.compatible = false +vim.opt.showmatch = true +vim.opt.ignorecase = true +vim.opt.mouse = "v" +vim.opt.hlsearch = true +vim.opt.incsearch = true + +-- Tab and indentation settings +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.expandtab = true +vim.opt.shiftwidth = 4 +vim.opt.autoindent = true + +-- Line numbering +vim.opt.number = true +vim.opt.relativenumber = true + +-- Command-line completion mode +vim.opt.wildmode = { "longest", "list" } + +-- Column marker at 80 characters +vim.opt.colorcolumn = "80" + +-- Enable filetype plugins and indentation +vim.cmd("filetype plugin indent on") + +-- Enable syntax highlighting +vim.cmd("syntax on") + +-- Enable mouse support +vim.opt.mouse = "a" + +-- Use system clipboard +vim.opt.clipboard = "unnamedplus" + +-- Enable cursorline +vim.opt.cursorline = true + +-- Optimize for fast terminal +vim.opt.ttyfast = true + +-- Do not add a newline at the end of the file +vim.opt.fixeol = false + +local data_dir = vim.fn.has('nvim') == 1 and vim.fn.stdpath('data') .. '/site' or '~/.vim' + +if vim.fn.empty(vim.fn.glob(data_dir .. '/autoload/plug.vim')) == 1 then + vim.fn.system({ + 'curl', '-fLo', data_dir .. '/autoload/plug.vim', '--create-dirs', + 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' + }) + vim.cmd('autocmd VimEnter * PlugInstall --sync | source $MYVIMRC') +end + +-- Initialize packer.nvim +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + -- Plugins + use 'dracula/vim' + use 'ryanoasis/vim-devicons' + -- use 'SirVer/ultisnips' + use 'honza/vim-snippets' + use 'scrooloose/nerdtree' + use 'preservim/nerdcommenter' + use 'mhinz/vim-startify' + use {'neoclide/coc.nvim', branch = 'release'} + use 'nvim-lua/plenary.nvim' + use 'ThePrimeagen/harpoon' + use {'junegunn/fzf', run = function() vim.fn['fzf#install']() end} + use 'junegunn/fzf.vim' + use 'neovim/nvim-lspconfig' + use 'jose-elias-alvarez/null-ls.nvim' + use 'MunifTanjim/prettier.nvim' + use 'github/copilot.vim' + use {'CopilotC-Nvim/CopilotChat.nvim', branch = 'canary'} +end) + +-- Copilot Chat +local prompts = require('CopilotChat.prompts') +local select = require('CopilotChat.select') + +require("CopilotChat").setup { + debug = false, + + question_header = '## User ', + answer_header = '## Copilot ', + error_header = '## Error ', + separator = '---', + + selection = function(source) + return select.visual(source) or select.line(source) + end, + + window = { + layout = 'float', + }, +} + +if vim.fn.has("termguicolors") == 1 then + vim.opt.termguicolors = true +end + +-- Enable syntax highlighting +vim.cmd("syntax enable") + +-- Set colorscheme to dracula +vim.cmd("colorscheme dracula") + +-- Open new vertical splits to the right +vim.opt.splitright = true + +-- Open new horizontal splits below +vim.opt.splitbelow = true + +-- Insert mode mappings +vim.api.nvim_set_keymap('i', '', ':m .+1==gi', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('i', '', ':m .-2==gi', { noremap = true, silent = true }) + +-- Visual mode mappings +vim.api.nvim_set_keymap('v', '', ":m '>+1gv=gv", { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', '', ":m '<-2gv=gv", { noremap = true, silent = true }) + +-- Normal mode mappings for window movement +vim.api.nvim_set_keymap('n', '', 'H', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'J', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'K', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'L', { noremap = true, silent = true }) + +-- Normal mode mappings for window navigation +vim.api.nvim_set_keymap('n', '', 'h', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'j', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'k', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'l', { noremap = true, silent = true }) + +-- Normal mode mapping for opening file in vertical split +vim.api.nvim_set_keymap('n', 'gf', ':vert winc f', { noremap = true, silent = true }) + +-- Insert mode mappings for CoC (Conquer of Completion) +vim.api.nvim_set_keymap('i', '', [[coc#pum#visible() ? coc#_select_confirm() : "\u\"]], { noremap = true, silent = true, expr = true }) +vim.api.nvim_set_keymap('i', '', [[coc#pum#visible() ? coc#pum#next(1) : "\"]], { noremap = true, silent = true, expr = true }) +vim.api.nvim_set_keymap('i', '', [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], { noremap = true, silent = true, expr = true }) + +-- Normal mode mappings for NERDTree +vim.api.nvim_set_keymap('n', 'n', ':NERDTreeFocus', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', ':NERDTree', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', ':NERDTreeToggle', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', ':NERDTreeFind', { noremap = true, silent = true }) + +-- Normal mode mapping for opening file explorer +vim.api.nvim_set_keymap('n', 'ee', ':Ex', { noremap = true, silent = true }) + +-- Harpoon mappings +vim.api.nvim_set_keymap('n', 'ha', 'lua require("harpoon.mark").add_file()', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'hh', 'lua require("harpoon.ui").toggle_quick_menu()', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '1', 'lua require("harpoon.ui").nav_file(1)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '2', 'lua require("harpoon.ui").nav_file(2)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '3', 'lua require("harpoon.ui").nav_file(3)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '4', 'lua require("harpoon.ui").nav_file(4)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'lua require("harpoon.ui").nav_prev()', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'lua require("harpoon.ui").nav_next()', { noremap = true, silent = true }) + +-- FZF mapping +vim.api.nvim_set_keymap('n', 'ff', ':FZF', { noremap = true, silent = true }) + +-- Miscellaneous mappings +vim.api.nvim_set_keymap('n', 'mm', ':nohl', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'ml', ':%s/\\r//g', { noremap = true, silent = true }) + +-- Yarn mappings +vim.api.nvim_set_keymap('n', 'yb', ':!yarn build', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'yi', ':!yarn install', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'ys', ':!yarn start', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'yt', ':!yarn test', { noremap = true, silent = true }) + +-- Dotnet mapping +vim.api.nvim_set_keymap('n', 'dr', ':!dotnet run', { noremap = true, silent = true }) + +-- Prettier mapping +vim.api.nvim_set_keymap('n', 'p', '(prettier-format)', { noremap = true, silent = true }) + +-- Copilot Chat mappings +vim.api.nvim_set_keymap('n', '', ':CopilotChatToggle', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'ps', ':CopilotChatStop', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'pr', ':CopilotChatReset', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pe', ':CopilotChatExplain', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pr', ':CopilotChatReview', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pf', ':CopilotChatFix', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'po', ':CopilotChatOptimize', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pd', ':CopilotChatDocs', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pt', ':CopilotChatTests', { noremap = true, silent = true }) + +-- Harpoon mappings +vim.api.nvim_set_keymap('n', 'ha', 'lua require("harpoon.mark").add_file()', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'hh', 'lua require("harpoon.ui").toggle_quick_menu()', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '1', 'lua require("harpoon.ui").nav_file(1)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '2', 'lua require("harpoon.ui").nav_file(2)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '3', 'lua require("harpoon.ui").nav_file(3)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '4', 'lua require("harpoon.ui").nav_file(4)', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'lua require("harpoon.ui").nav_prev()', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', '', 'lua require("harpoon.ui").nav_next()', { noremap = true, silent = true }) + +-- FZF mapping +vim.api.nvim_set_keymap('n', 'ff', ':FZF', { noremap = true, silent = true }) + +-- Miscellaneous mappings +vim.api.nvim_set_keymap('n', 'mm', ':nohl', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'ml', ':%s/\\r//g', { noremap = true, silent = true }) + +-- Yarn mappings +vim.api.nvim_set_keymap('n', 'yb', ':!yarn build', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'yi', ':!yarn install', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'ys', ':!yarn start', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'yt', ':!yarn test', { noremap = true, silent = true }) + +-- Dotnet mapping +vim.api.nvim_set_keymap('n', 'dr', ':!dotnet run', { noremap = true, silent = true }) + +-- Prettier mapping +vim.api.nvim_set_keymap('n', 'p', '(prettier-format)', { noremap = true, silent = true }) + +-- Copilot mappings +vim.api.nvim_set_keymap('n', '', ':CopilotChatToggle', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'ps', ':CopilotChatStop', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('n', 'pr', ':CopilotChatReset', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pe', ':CopilotChatExplain', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pr', ':CopilotChatReview', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pf', ':CopilotChatFix', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'po', ':CopilotChatOptimize', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pd', ':CopilotChatDocs', { noremap = true, silent = true }) +vim.api.nvim_set_keymap('v', 'pt', ':CopilotChatTests', { noremap = true, silent = true }) diff --git a/config/packages/neovim/init.vim b/config/packages/neovim/init.vim deleted file mode 100644 index 32d91e7..0000000 --- a/config/packages/neovim/init.vim +++ /dev/null @@ -1,143 +0,0 @@ -let mapleader = " " -let g:copilot_enabled = v:false - -set nocompatible -set showmatch -set ignorecase -set mouse=v -set hlsearch -set incsearch -set tabstop=4 -set softtabstop=4 -set expandtab -set shiftwidth=4 -set autoindent -set number -set relativenumber -set wildmode=longest,list -set cc=80 -filetype plugin indent on -syntax on -set mouse=a -set clipboard=unnamedplus -filetype plugin on -set cursorline -set ttyfast -set nofixeol - -let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' -if empty(glob(data_dir . '/autoload/plug.vim')) - silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' - autocmd VimEnter * PlugInstall --sync | source $MYVIMRC -endif - -call plug#begin("~/.vim/plugged") - Plug 'dracula/vim' - Plug 'ryanoasis/vim-devicons' - " Plug 'SirVer/ultisnips' - Plug 'honza/vim-snippets' - Plug 'scrooloose/nerdtree' - Plug 'preservim/nerdcommenter' - Plug 'mhinz/vim-startify' - Plug 'neoclide/coc.nvim', {'branch': 'release'} - Plug 'nvim-lua/plenary.nvim' - Plug 'ThePrimeagen/harpoon' - Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } - Plug 'junegunn/fzf.vim' - Plug 'neovim/nvim-lspconfig' - Plug 'jose-elias-alvarez/null-ls.nvim' - Plug 'MunifTanjim/prettier.nvim' - Plug 'github/copilot.vim' - Plug 'CopilotC-Nvim/CopilotChat.nvim', { 'branch': 'canary' } -call plug#end() - -lua << EOF -local prompts = require('CopilotChat.prompts') -local select = require('CopilotChat.select') - -require("CopilotChat").setup { - debug = false, - - question_header = '## User ', - answer_header = '## Copilot ', - error_header = '## Error ', - separator = '---', - - selection = function(source) - return select.visual(source) or select.line(source) - end, - - window = { - layout = 'float', - }, -} -EOF - -if (has("termguicolors")) - set termguicolors -endif -syntax enable -colorscheme dracula - -set splitright -set splitbelow - -inoremap :m .+1==gi -inoremap :m .-2==gi -vnoremap :m '>+1gv=gv -vnoremap :m '<-2gv=gv - -nnoremap H -nnoremap J -nnoremap K -nnoremap L - -nnoremap h -nnoremap j -nnoremap k -nnoremap l - -nnoremap gf :vert winc f - -inoremap coc#pum#visible() ? coc#_select_confirm() : "\u\" -inoremap coc#pum#visible() ? coc#pum#next(1) : "\" -inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" - -nnoremap n :NERDTreeFocus -nnoremap :NERDTree -nnoremap :NERDTreeToggle -nnoremap :NERDTreeFind -nnoremap ee :Ex - -nnoremap ha lua require("harpoon.mark").add_file() -nnoremap hh lua require("harpoon.ui").toggle_quick_menu() -nnoremap 1 lua require("harpoon.ui").nav_file(1) -nnoremap 2 lua require("harpoon.ui").nav_file(2) -nnoremap 3 lua require("harpoon.ui").nav_file(3) -nnoremap 4 lua require("harpoon.ui").nav_file(4) -nnoremap lua require("harpoon.ui").nav_prev() -nnoremap lua require("harpoon.ui").nav_next() - -nnoremap ff :FZF - -nnoremap mm :nohl -nnoremap ml :%s/\r//g - -nnoremap yb :!yarn build -nnoremap yi :!yarn install -nnoremap ys :!yarn start -nnoremap yt :!yarn test - -nnoremap dr :!dotnet run - -nnoremap p (prettier-format) - -nnoremap :CopilotChatToggle -nnoremap ps :CopilotChatStop -nnoremap pr :CopilotChatReset -vnoremap pe :CopilotChatExplain -vnoremap pr :CopilotChatReview -vnoremap pf :CopilotChatFix -vnoremap po :CopilotChatOptimize -vnoremap pd :CopilotChatDocs -vnoremap pt :CopilotChatTests