From 9f6a1408d700e7b4c6efd2813b0c7c2995b77b1b Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Fri, 7 Jul 2023 14:12:42 -0700 Subject: [PATCH 1/2] Convert to lua --- README.md | 36 ++++++++++++++---------- conf/config.lua | 18 ++++++++++++ conf/config.vim | 15 ---------- conf/git.lua | 8 ++++++ conf/git.vim | 9 ------ conf/keybinds.lua | 32 ++++++++++++++++++++++ conf/keybinds.vim | 28 ------------------- conf/langs/general.lua | 45 ++++++++++++++++++++++++++++++ conf/langs/general.vim | 46 ------------------------------- conf/langs/python.lua | 19 +++++++++++++ conf/langs/python.vim | 9 ------ conf/plugins.lua | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ conf/plugins.vim | 69 ---------------------------------------------- conf/search.lua | 22 +++++++++++++++ conf/search.vim | 15 ---------- conf/ui.lua | 12 ++++++++ conf/ui.vim | 18 ------------ init.lua | 16 +++++++++++ init.vim | 17 ------------ ui.lua | 4 +++ ui.vim | 5 ---- 21 files changed, 271 insertions(+), 246 deletions(-) create mode 100644 conf/config.lua delete mode 100644 conf/config.vim create mode 100644 conf/git.lua delete mode 100644 conf/git.vim create mode 100644 conf/keybinds.lua delete mode 100644 conf/keybinds.vim create mode 100644 conf/langs/general.lua delete mode 100644 conf/langs/general.vim create mode 100644 conf/langs/python.lua delete mode 100644 conf/langs/python.vim create mode 100644 conf/plugins.lua delete mode 100644 conf/plugins.vim create mode 100644 conf/search.lua delete mode 100644 conf/search.vim create mode 100644 conf/ui.lua delete mode 100644 conf/ui.vim create mode 100644 init.lua delete mode 100644 init.vim create mode 100644 ui.lua delete mode 100644 ui.vim diff --git a/README.md b/README.md index b943013..ce75ff8 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ it's own repository for easier cloning without pulling down the entire `essentials` repository. I use the `nord` theme for both my terminal and Vim. You will need to adjust your theme and -airline according to your tastes in `plugins.vim` and `ui.vim`. +airline according to your tastes in `plugins.lua` and `ui.lua`. The V2 repo aims to take full advantage of asynchronous code and a modularized configuration to make adaptation easier and the UI snappier. Additionally support for `tmux` has improved with this iteration @@ -33,12 +33,12 @@ For Python editing: ## Structure * `conf`: Contains all configuration related files. - * `plugins.vim`: General plugin definitions. - * `keybinds.vim`: General keybinds such as leader key, etc. - * `config.vim`: Dumping ground for general configurations. - * `ui.vim`: General UI configurations. - * `search.vim`: Search configurations (for example ctrl-p). - * `git.vim`: Fugitive configurations. + * `plugins.lua`: General plugin definitions. + * `keybinds.lua`: General keybinds such as leader key, etc. + * `config.lua`: Dumping ground for general configurations. + * `ui.lua`: General UI configurations. + * `search.lua`: Search configurations (for example ctrl-p). + * `git.lua`: Fugitive configurations. * `langs`: Language specific configurations and keybinds. ## Installation @@ -49,7 +49,7 @@ git clone git@git.xchg.sh:angrygoats/vim-config nvim ``` If you have added/changed plugins remember to `:PlugInstall` after saving. There currently -is no autodetect on a changed `plugin.vim`. +is no autodetect on a changed `plugins.lua`. If you run into problems with pyenv on first start, insure that pyenv is installed and your pyenv has at least one installation available. For example, run `pyenv install 3.9.1`. @@ -70,7 +70,7 @@ order issues. This may be patched in the future. Pyenv support is added via [vim-pyenv](http://github.com/lambdalisue/vim-pyenv). `:PyenvActivate` can be used to activate a given environment. -The file `conf/langs/python.vim` contains formatting code typical of a Python project (4 space indents, etc). If you +The file `conf/langs/python.lua` contains formatting code typical of a Python project (4 space indents, etc). If you wish to adjust this you can do that here, or make modifications on a per-project basis. ## Other Notes @@ -104,19 +104,25 @@ The default leader is the space key. ### Git -`vim-fugitive` is installed. Bindings can be found in `conf/keybinds.vim` and documentation can be found +`vim-fugitive` is installed. Bindings can be found in `conf/keybinds.lua` and documentation can be found [here](https://github.com/tpope/vim-fugitive). The following binds are set to help development: ``` -nnoremap gs :Git -nnoremap gd :Git diff -nnoremap gb :Git blame -nnoremap gc :Git commit -nnoremap gp :Git push +gs :Git +gd :Git diff +gb :Git blame +gc :Git commit +gp :Git push ``` +### Treesitter + +Treesitter is installed as a plugin and syntax highlighting can be modified in `conf/lang/general.lua`. +You can add languages you would like there. Alternatively, auto-loading is enabled which should +handle most syntax highlighting cases. + ### LSP `vim-lsp` is installed with `vim-lsp-settings`. While editing a file that has a supported LSP server diff --git a/conf/config.lua b/conf/config.lua new file mode 100644 index 0000000..1d7e4ba --- /dev/null +++ b/conf/config.lua @@ -0,0 +1,18 @@ +-- General Configurations (Any language/Tool) + +-- Stripping trailing whitespace on save +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*" }, + command = [[:%s/\s\+$//e]] +}) + +-- Standard variables +vim.opt.expandtab = true -- tabs to spaces +vim.opt.tabstop = 2 -- spaces entered when tab key is pressed +vim.opt.shiftwidth = 2 -- spaces entered for indentation +vim.opt.number = true -- Line numbering +vim.opt.clipboard = "unnamedplus" -- Share system clipboard +vim.opt.eol = true -- End of line at bottom of file +vim.opt.shiftround = true +vim.opt.list = true +vim.opt.listchars={tab = »·, trail=·} diff --git a/conf/config.vim b/conf/config.vim deleted file mode 100644 index 4010d2b..0000000 --- a/conf/config.vim +++ /dev/null @@ -1,15 +0,0 @@ -" General Configurations (Any language/Tool) - -" Stripping trailing whitespace on save -autocmd BufWritePre * :%s/\s\+$//e - -" Standard variables -set expandtab " tabs to spaces -set tabstop=2 " spaces entered when tab key is pressed -set shiftwidth=2 " spaces entered for indentation -set number " Line numbering -set clipboard+=unnamedplus " Share system clipboard -set eol " End of line at bottom of file -set shiftround -set list -set list listchars=tab:»·,trail:· diff --git a/conf/git.lua b/conf/git.lua new file mode 100644 index 0000000..f32198f --- /dev/null +++ b/conf/git.lua @@ -0,0 +1,8 @@ +-- Fugitive Configuration +-- +-- Fugitive bindings +vim.api.nvim_set_keymap('n', 'gs', ':Git', {noremap = true}) +vim.api.nvim_set_keymap('n', 'gd', ':Git diff', {noremap = true}) +vim.api.nvim_set_keymap('n', 'gb', ':Git blame', {noremap = true}) +vim.api.nvim_set_keymap('n', 'gc', ':Git commit', {noremap = true}) +vim.api.nvim_set_keymap('n', 'gp', ':Git push', {noremap = true}) diff --git a/conf/git.vim b/conf/git.vim deleted file mode 100644 index 0435a60..0000000 --- a/conf/git.vim +++ /dev/null @@ -1,9 +0,0 @@ -" Fugitive Configuration - -" Fugitive bindings -nnoremap gs :Git " This binding is a weird one. - " :Git is now the full status page. -nnoremap gd :Git diff -nnoremap gb :Git blame -nnoremap gc :Git commit -nnoremap gp :Git push diff --git a/conf/keybinds.lua b/conf/keybinds.lua new file mode 100644 index 0000000..f9552d7 --- /dev/null +++ b/conf/keybinds.lua @@ -0,0 +1,32 @@ +-- General-Purpose keybinds +local keymap_opts = { silent = true, noremap = true } + +function NumberToggle() + if vim.o.relativenumber then + vim.opt.relativenumber = false + vim.opt.number = true + else + vim.opt.relativenumber = true + end +end + +-- Space is the leader key when outside of insert mode. +vim.g.mapleader = " " + +vim.api.nvim_set_keymap('', 't', ':NERDTreeToggle', {silent = true}) + +-- -r controls relative line numbering. +vim.api.nvim_set_keymap('n', 'r', 'lua NumberToggle()', keymap_opts) + +-- Pressing enter in command mode clears the current search highlighting until +-- the next search. +vim.api.nvim_set_keymap('n', '', ':noh', keymap_opts) + +-- This one maps F5 to delete all trailing whitespace +vim.api.nvim_set_keymap( + 'n', + '', + [[:let _s=@/:%s/\s\+$//e:let @/=_s:nohl]], + keymap_opts) + + diff --git a/conf/keybinds.vim b/conf/keybinds.vim deleted file mode 100644 index 3bbb57e..0000000 --- a/conf/keybinds.vim +++ /dev/null @@ -1,28 +0,0 @@ -" General-Purpose keybinds - -" Space is the leader key when outside of insert mode. -let mapleader=" " - -map t :NERDTreeToggle -nnoremap r :call NumberToggle() - -" Pressing enter in command mode clears the current search highlighting until -" the next search. -nnoremap :noh - -" This one maps F5 to delete all trailing whitespace -nnoremap :let _s=@/:%s/\s\+$//e:let @/=_s:nohl - -" Togglable relative line numbering -function! NumberToggle() - if(&relativenumber == 1) - set norelativenumber - set number - else - set relativenumber - endif -endfunc - -" r will toggle relative line numbers. -nnoremap r :call NumberToggle() - diff --git a/conf/langs/general.lua b/conf/langs/general.lua new file mode 100644 index 0000000..7fb57bd --- /dev/null +++ b/conf/langs/general.lua @@ -0,0 +1,45 @@ +-- General configuration +vim.g.ale_linters = { + python = {'black', 'flake8'}, + c: {'clang-format'}, + cpp: {'clang-format'} +} + +vim.g.ale_fixers = { + ['*'] = {'remove_trailing_lines', 'trim_whitespace'} +} + +let g:ale_fix_on_save = 1 + +-- Treesitter config. +require'nvim-treesitter.configs'.setup { + ensure_installed = { + "c", + "lua", + "markdown", + "python", + "query", + "vim", + "vimdoc", + }, + + -- Prefer asynchronous install for ensure_installed. + sync_install = false, + auto_install = true, + + highlight = { + enable = true, + + -- Disable for excessively large files. + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, + + -- Disable vim regex highlighting. May intefer with some `indent` style stuff. + additional_vim_regex_highlighting = false, + }, +} diff --git a/conf/langs/general.vim b/conf/langs/general.vim deleted file mode 100644 index 5aca597..0000000 --- a/conf/langs/general.vim +++ /dev/null @@ -1,46 +0,0 @@ -" General configuration -let g:ale_fixers = { - \ '*': ['remove_trailing_lines', 'trim_whitespace'], - \ 'python': ['black', 'flake8'], - \ 'c': ['clang-format'], - \ 'c++': ['clang-format'] - \} - -let g:ale_fix_on_save = 1 - -"" Treesitter config. -"" TODO: Remove lua << EOF and EOF when all files are converted -"" to lua. -lua << EOF -require'nvim-treesitter.configs'.setup { - ensure_installed = { - "c", - "lua", - "markdown", - "python", - "query", - "vim", - "vimdoc", - }, - - -- Prefer asynchronous install for ensure_installed. - sync_install = false, - auto_install = true, - - highlight = { - enable = true, - - -- Disable for excessively large files. - disable = function(lang, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, - - -- Disable vim regex highlighting. May intefer with some `indent` style stuff. - additional_vim_regex_highlighting = false, - }, -} -EOF diff --git a/conf/langs/python.lua b/conf/langs/python.lua new file mode 100644 index 0000000..9bd08f7 --- /dev/null +++ b/conf/langs/python.lua @@ -0,0 +1,19 @@ +-- Python configurations + +vim.api.nvim_create_autocmd( + { + "BufNewFile", + "BufRead", + }, + { + pattern = "*.py", + callback = function() + local buf = vim.api.nvim_get_current_buf() + vim.api.nvim_buf_set_option(buf, "expandtab") + vim.api.nvim_buf_set_option(buf, "autoindent") + vim.api.nvim_buf_set_option(buf, "tabstop", 4) + vim.api.nvim_buf_set_option(buf, "softtabstop", 4) + vim.api.nvim_buf_set_option(buf, "shiftwidth", 4) + end + } +) diff --git a/conf/langs/python.vim b/conf/langs/python.vim deleted file mode 100644 index b6d5b12..0000000 --- a/conf/langs/python.vim +++ /dev/null @@ -1,9 +0,0 @@ -" Python configurations - -"" Set Python standard formatting. -au BufNewFile,BufRead *.py - \ set expandtab |" replace tabs with spaces - \ set autoindent |" copy indent when starting a new line - \ set tabstop=4 - \ set softtabstop=4 - \ set shiftwidth=4 diff --git a/conf/plugins.lua b/conf/plugins.lua new file mode 100644 index 0000000..9d41515 --- /dev/null +++ b/conf/plugins.lua @@ -0,0 +1,74 @@ +-- Plugin definitions. + +local vim = vim +local Plug = vim.fn['plug#'] + +-- I have no idea how to auto-install vim-plug on Windows +-- so you will have to install it manually. +vim.cmd [[ + if !(has('win16') || has('win32') || has('win64')) + if empty(glob('~/.config/nvim/autoload/plug.vim')) + silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs + \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + autocmd VimEnter * PlugInstall | source % + endif + endif +]] + +vim.call('plug#begin', '~/.config/nvim/plugged') + +-- UI +Plug 'arcticicestudio/nord-vim' +Plug 'vim-airline/vim-airline' +Plug 'vim-airline/vim-airline-themes' +Plug 'ryanoasis/vim-devicons' +Plug 'preservim/nerdtree' +-- This plugin has been archived so if there are problems +-- They may emerge here +Plug 'Xuyuanp/nerdtree-git-plugin' +Plug('nvim-treesitter/nvim-treesitter', {['do'] = vim.fn[':TSUpdate']}) + +-- General Editing +Plug 'tpope/vim-surround' +Plug 'tpope/vim-commentary' + +-- Search +Plug 'kien/ctrlp.vim' + +-- Git +Plug 'tpope/vim-fugitive' + +-- LSP +Plug 'prabirshrestha/vim-lsp' +Plug 'mattn/vim-lsp-settings' + +-- Autocomplete +Plug 'prabirshrestha/asyncomplete.vim' +Plug 'prabirshrestha/asyncomplete-lsp.vim' + +-- Tmux Helper +Plug 'preservim/vimux' +Plug 'christoomey/vim-tmux-navigator' + +-- Linting +Plug 'w0rp/ale' + +-- Planning +Plug 'jceb/vim-orgmode' + +-- Commands +Plug 'skywind3000/asyncrun.vim' + +-- Syntax highlighting +Plug 'sheerun/vim-polyglot' + +-- Languages + +------------------------- +-- Python +------------------------- + +-- Pyenv Support +Plug 'lambdalisue/vim-pyenv' + +vim.call('plug#end') diff --git a/conf/plugins.vim b/conf/plugins.vim deleted file mode 100644 index 131010a..0000000 --- a/conf/plugins.vim +++ /dev/null @@ -1,69 +0,0 @@ -" Plugin definitions. - -" I have no idea how to auto-install vim-plug on Windows -" so you will have to install it manually. -if !(has('win16') || has('win32') || has('win64')) - if empty(glob('~/.config/nvim/autoload/plug.vim')) - silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs - \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim - autocmd VimEnter * PlugInstall | source % - endif -endif - -call plug#begin('~/.config/nvim/plugged') - -" UI -Plug 'arcticicestudio/nord-vim' -Plug 'vim-airline/vim-airline' -Plug 'vim-airline/vim-airline-themes' -Plug 'ryanoasis/vim-devicons' -Plug 'preservim/nerdtree' -"" This plugin has been archived so if there are problems -"" They may emerge here -Plug 'Xuyuanp/nerdtree-git-plugin' -Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} - -" General Editing -Plug 'tpope/vim-surround' -Plug 'tpope/vim-commentary' - -"" Search -Plug 'kien/ctrlp.vim' - -"" Git -Plug 'tpope/vim-fugitive' - -"" LSP -Plug 'prabirshrestha/vim-lsp' -Plug 'mattn/vim-lsp-settings' - -"" Autocomplete -Plug 'prabirshrestha/asyncomplete.vim' -Plug 'prabirshrestha/asyncomplete-lsp.vim' - -"" Tmux Helper -Plug 'preservim/vimux' -Plug 'christoomey/vim-tmux-navigator' - -"" Linting -Plug 'w0rp/ale' - -"" Planning -Plug 'jceb/vim-orgmode' - -"" Commands -Plug 'skywind3000/asyncrun.vim' - -"" Syntax highlighting -Plug 'sheerun/vim-polyglot' - -"" Languages - -""""""""""""""""""""""""" -" Python -""""""""""""""""""""""""" - -"" Pyenv Support -Plug 'lambdalisue/vim-pyenv' - -call plug#end() diff --git a/conf/search.lua b/conf/search.lua new file mode 100644 index 0000000..da465ac --- /dev/null +++ b/conf/search.lua @@ -0,0 +1,22 @@ +-- Specific search configurations + +-- ctrlp hotkeys +vim.g.ctrlp_map = '' +vim.g.ctrlp_cmd = 'CtrlP' + +-- Rebind Ctrl-P to match the window opening keys of nerd tree +vim.g.ctrl_p_prompt_mappings = { + ['AcceptSelection("h")'] = {'','',''}, + ['AcceptSelection("v")'] = {'','' }, +} + +-- ctrlp configuration +vim.opt.wildignore = { + "*/tmp/*", + "*.so", + "*.swp", + "*.zip", + "*\\tmp\\*", + "*.exe", + "*.out" +} diff --git a/conf/search.vim b/conf/search.vim deleted file mode 100644 index 3a8dcff..0000000 --- a/conf/search.vim +++ /dev/null @@ -1,15 +0,0 @@ -" Specific search configurations - -" ctrlp hotkeys -let g:ctrlp_map='' -let g:ctrlp_cmd='CtrlP' - -" Rebind Ctrl-P to match the window opening keys of nerd tree -let g:ctrl_p_prompt_mappings = { - \ 'AcceptSelection("h")': ['', '', ''], - \ 'AcceptSelection("v")': ['', ''], -\ } - -" ctrlp configuration -set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux -set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe " Windows diff --git a/conf/ui.lua b/conf/ui.lua new file mode 100644 index 0000000..de68cb6 --- /dev/null +++ b/conf/ui.lua @@ -0,0 +1,12 @@ +-- UI Definitions + +vim.cmd [[colorscheme nord]] + +-- Helps some themes. +vim.opt.termguicolors = true + +-- Always show hidden files in nerdtree +vim.g.NERDTreeShowHidden = 1 + + + diff --git a/conf/ui.vim b/conf/ui.vim deleted file mode 100644 index 3e965ab..0000000 --- a/conf/ui.vim +++ /dev/null @@ -1,18 +0,0 @@ -" UI Definitions - -colorscheme nord - -" Helps some themes. -if (has('nvim')) - let $NVIM_TUI_ENABLE_TRUE_COLOR = 1 -endif - -if (has('termguicolors')) - set termguicolors -endif - -" Always show hidden files in nerdtree -let NERDTreeShowHidden=1 - - - diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..0c8a02b --- /dev/null +++ b/init.lua @@ -0,0 +1,16 @@ +-- Initialization + +require('/conf/plugins') +require('/conf/keybinds') +require('/conf/config') +require('/conf/ui') +require('/conf/search') +require('/conf/git') +require('ui') + +local paths = vim.fn.glob(vim.fn.stdpath 'config' .. 'config/langs/*.lua', true, true, true) + +for _, file in ipairs(paths) do + require(file) +end + diff --git a/init.vim b/init.vim deleted file mode 100644 index 2aedb55..0000000 --- a/init.vim +++ /dev/null @@ -1,17 +0,0 @@ -" Initialization - -let g:nvim_config_root = stdpath('config') - -exe 'source' g:nvim_config_root . '/conf/plugins.vim' -exe 'source' g:nvim_config_root . '/conf/keybinds.vim' -exe 'source' g:nvim_config_root . '/conf/config.vim' -exe 'source' g:nvim_config_root . '/conf/ui.vim' -exe 'source' g:nvim_config_root . '/conf/search.vim' -exe 'source' g:nvim_config_root . '/conf/git.vim' - -let lang_configs = glob(g:nvim_config_root . '/conf/langs/*.vim', 1, 1) - -for lang_config in lang_configs - exe 'source' lang_config -endfor - diff --git a/ui.lua b/ui.lua new file mode 100644 index 0000000..060c963 --- /dev/null +++ b/ui.lua @@ -0,0 +1,4 @@ +-- UI Definitions + +vim.cmd [[colorscheme nord]] + diff --git a/ui.vim b/ui.vim deleted file mode 100644 index ff7d07d..0000000 --- a/ui.vim +++ /dev/null @@ -1,5 +0,0 @@ -" UI Definitions - - -colorscheme nord - From 258681cedefcec0ab9b0a0089297bdd810321205 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Fri, 7 Jul 2023 14:15:35 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ce75ff8..c1adae2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,10 @@ The V2 repo aims to take full advantage of asynchronous code and a modularized c adaptation easier and the UI snappier. Additionally support for `tmux` has improved with this iteration through the use of `vimux` and `vim-tmux-navigator`. +**If you are interested in the vimscript version** please refer to the [vimscript-final](https://git.xchg.sh/angrygoats/neovim-config/src/tag/vimscript-final) tag. + +All future modifications will be done in lua. + ## Requirements 1. [Neovim](https://github.com/neovim/neovim)