From befa7238acd46e49c9fe16025eaecbba98c20b84 Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Tue, 16 Nov 2021 21:11:11 -0700 Subject: bunch of reorg/clean --- init.lua | 175 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 86 insertions(+), 89 deletions(-) diff --git a/init.lua b/init.lua index da57d7f..a3bb5ed 100644 --- a/init.lua +++ b/init.lua @@ -1,9 +1,4 @@ ---[[ -To install everything run `:PackerSync` - -LspInfo to check if the language servers are working -]]-- - +-- To install everything run `:PackerSync` -- https://dev.to/voyeg3r/writing-useful-lua-functions-to-my-neovim-14ki -- function to remove whitespace and preserve spot on save @@ -15,7 +10,6 @@ function _G.preserve(cmd) end vim.cmd([[autocmd BufWritePre,FileWritePre,FileAppendPre,FilterWritePre * :lua preserve('%s/\\s\\+$//ge')]]) - -- Bootstrap packer if not installed local fn = vim.fn local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' @@ -24,7 +18,7 @@ if fn.empty(fn.glob(install_path)) > 0 then vim.cmd 'packadd packer.nvim' end - +-- Debug function for printing lua tables function _G.print_table(mytable) for k,v in pairs(mytable) do if (type(v) == "table") then @@ -39,32 +33,26 @@ end -- https://old.reddit.com/r/neovim/comments/lrz18i/how_to_change_colorscheme_in_lua_without_any/ vim.g.colors_name = "nord" -vim.g.SuperTabDefaultCompletionType = "" -vim.g.floaterm_opener = "edit" - --- Shortcut the map function -local map = vim.api.nvim_set_keymap - -- Set up spacebar as leader -- https://icyphox.sh/blog/nvim-lua/ -map('n', '', '', {}) +vim.api.nvim_set_keymap('n', '', '', {}) vim.g.mapleader = ' ' - -- Set spaces > tabs, 4 as default vim.o.expandtab = true vim.o.tabstop = 4 vim.o.shiftwidth = 0 vim.o.relativenumber = true - +-- Distable word wrap vim.o.wrap = false vim.o.history = 1000 -- Wildmode show list, complete to first result vim.o.wildignore = "*/app/cache,*/vendor,*/env,*.pyc,*/venv,*/__pycache__,*/venv" +-- Default split directions vim.o.splitright = true vim.o.splitbelow = true +-- set spelling language vim.o.spelllang = "en_ca" - local highlights = { "Search ctermfg=166", "DiffAdd cterm=BOLD ctermfg=NONE ctermbg=22", @@ -92,81 +80,55 @@ au BufEnter *.py let w:m2=matchadd('Error', '\%121v', 100) au BufLeave *.py call clearmatches() ]] - -- Custom commands vim.cmd [[ command! MakeTagsPython !ctags --exclude=venv --languages=python --python-kinds=-i -R . ]] +-- When using tab, enter will accept the current selection and close the window +-- instead of inserting a newline +vim.cmd [[ +inoremap pumvisible() ? "\" : "\" +]] -options = { noremap = true } - - - -map('n', '', ':noh', options) -map('i', 'jj', '', options) - +-- Keymaps +--noh gets rid of highlighted search results +vim.api.nvim_set_keymap('n', '', ':noh', { noremap = true }) +-- `jj` maps to escape +vim.api.nvim_set_keymap('i', 'jj', '', { noremap = true }) -- Visually select last copied text -map('n', 'gp', "`[v`]", options) -map('n', 'ps', 'source ~/.config/nvim/init.luaPackerSync', options) -map('n', 'ff', "lua require('telescope.builtin').find_files({hidden=true})", options) -map('n', 'fb', 'Telescope buffers', options) -map('n', 'fj', 'Telescope jumplist', options) -map('n', 'f/', 'Telescope live_grep', options) -map('n', 'fa', 'Telescope grep_string', options) -map('n', 'fg', "lua require('telescope.builtin').git_status()", options) -map('n', 'ft', "lua require('telescope.builtin').tags({layout_strategy='center', only_sort_tags=true, show_line=true})", options) - -map('n', 'du', 'diffupdate', options) -map('n', 'dd', 'diffget', options) -map('n', 'df', 'diffput', options) -map('n', '_', '[c', options) -map('n', '=', ']c', options) +vim.api.nvim_set_keymap('n', 'gp', "`[v`]", { noremap = true }) +-- Changelist navigation +vim.api.nvim_set_keymap('n', '_', '[c', { noremap = true }) +vim.api.nvim_set_keymap('n', '=', ']c', { noremap = true }) +vim.api.nvim_set_keymap('n', 'co', 'copen', { noremap = true }) +vim.api.nvim_set_keymap('n', 'cc', 'cclose', { noremap = true }) -- Visually select line without ending -map('n', 'v', '^v$h', options) - +vim.api.nvim_set_keymap('n', 'v', '^v$h', { noremap = true }) -- Ledger Shortcuts -- Copy the last entry -map('n', 'll', 'G{jV}y}p10l', options) +vim.api.nvim_set_keymap('n', 'll', 'G{jV}y}p10l', { noremap = true }) -- Copy the current entry to the bottom, copy date from last entry -map('n', 'lb', '{jV}yGp10l{{jvEy}jvEpl', options) +vim.api.nvim_set_keymap('n', 'lb', '{jV}yGp10l{{jvEy}jvEpl', { noremap = true }) -- Copy the current entry to the next position -map('n', 'ln', '{jV}y}p10l', options) +vim.api.nvim_set_keymap('n', 'ln', '{jV}y}p10l', { noremap = true }) -- Jump down from line to replace dollar ammount -map('n', 'ld', 'j^f$lC', options) +vim.api.nvim_set_keymap('n', 'ld', 'j^f$lC', { noremap = true }) -- After searching pull entry to current position -map('n', 'ly', 'vapyp{{jvEy}jvEpl', options) - - -map('n', 'ep', 'ofrom pudb import set_trace; set_trace()', options) - - - - -map('n', 't', "tabnew", options) -map('n', '', 'fT', options) -map('n', '', 'vT', options) -map('n', '', 'vT', options) -map('n', 'ee', 'e!', options) -map('n', ' k', [[(v:count > 1 ? "m'" . v:count : '') . 'k']], options) -map('n', ' j', [[(v:count > 1 ? "m'" . v:count : '') . 'j']], options) - - -map('n', 'co', 'copen', options) -map('n', 'cc', 'cclose', options) - -map('n', 'ew', 'ArgWrap', options) - -map('n', 'gs', 'Git', options) -map('n', 'gd', 'Gdiffsplit', options) - --- map('n', 'm', 'Ranger', options) --- map('n', 'n', 'RangerWorkingDirectory', options) -map('n', 'm', 'LfWorkingDirectory', options) -map('n', 'n', 'Lf', options) - -map('', 's', 'HopChar2', options) - +vim.api.nvim_set_keymap('n', 'ly', 'vapyp{{jvEy}jvEpl', { noremap = true }) +-- Shorcut to insert pudb statements for python +vim.api.nvim_set_keymap('n', 'ep', 'ofrom pudb import set_trace; set_trace()', { noremap = true }) +-- Easy new tab creation +vim.api.nvim_set_keymap('n', 't', "tabnew", { noremap = true }) +vim.api.nvim_set_keymap('n', '', 'fT', { noremap = true }) +vim.api.nvim_set_keymap('n', '', 'vT', { noremap = true }) +vim.api.nvim_set_keymap('n', '', 'vT', { noremap = true }) +vim.api.nvim_set_keymap('n', 'ee', 'e!', { noremap = true }) +vim.api.nvim_set_keymap('n', ' k', [[(v:count > 1 ? "m'" . v:count : '') . 'k']], { noremap = true }) +vim.api.nvim_set_keymap('n', ' j', [[(v:count > 1 ? "m'" . v:count : '') . 'j']], { noremap = true }) + + +-- Build a custom status line local status_line = { '%#PrimaryBlock#', '%#SecondaryBlock#', @@ -179,12 +141,16 @@ local status_line = { '%#PrimaryBlock#', '%{&filetype}', } - vim.o.statusline = table.concat(status_line) - +-- Packer package manage return require('packer').startup(function() - use 'wbthomason/packer.nvim' + use { + 'wbthomason/packer.nvim', + config = function() + vim.api.nvim_set_keymap('n', 'ps', 'source ~/.config/nvim/init.luaPackerSync', { noremap = true }) + end + } use 'Thornycrackers-Forks/nord-vim' use 'p00f/nvim-ts-rainbow' use { @@ -235,13 +201,10 @@ return require('packer').startup(function() 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) @@ -289,6 +252,13 @@ return require('packer').startup(function() {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }, }, config = function() + vim.api.nvim_set_keymap('n', 'ff', "lua require('telescope.builtin').find_files({hidden=true})", { noremap = true }) + vim.api.nvim_set_keymap('n', 'fb', 'Telescope buffers', { noremap = true }) + vim.api.nvim_set_keymap('n', 'fj', 'Telescope jumplist', { noremap = true }) + vim.api.nvim_set_keymap('n', 'f/', 'Telescope live_grep', { noremap = true }) + vim.api.nvim_set_keymap('n', 'fa', 'Telescope grep_string', { noremap = true }) + vim.api.nvim_set_keymap('n', 'fg', "lua require('telescope.builtin').git_status()", { noremap = true }) + vim.api.nvim_set_keymap('n', 'ft', "lua require('telescope.builtin').tags({layout_strategy='center', only_sort_tags=true, show_line=true})", { noremap = true }) actions = require("telescope.actions") require("telescope").setup{ extensions = { @@ -352,8 +322,22 @@ return require('packer').startup(function() require('telescope').load_extension('fzf') end, } - use 'FooSoft/vim-argwrap' - use 'tpope/vim-fugitive' + use { + 'FooSoft/vim-argwrap', + config = function() + vim.api.nvim_set_keymap('n', 'ew', 'ArgWrap', { noremap = true }) + end + } + use { + 'tpope/vim-fugitive', + config = function() + vim.api.nvim_set_keymap('n', 'du', 'diffupdate', { noremap = true }) + vim.api.nvim_set_keymap('n', 'dd', 'diffget', { noremap = true }) + vim.api.nvim_set_keymap('n', 'df', 'diffput', { noremap = true }) + vim.api.nvim_set_keymap('n', 'gs', 'Git', { noremap = true }) + + end + } use { 'lukas-reineke/indent-blankline.nvim', config = function() @@ -376,6 +360,12 @@ return require('packer').startup(function() 'ptzz/lf.vim', -- Adds a floating window requires = { {'voldikss/vim-floaterm'} }, + config = function() + vim.g.floaterm_opener = "edit" + vim.g.lf_replace_netrw = 1; + vim.api.nvim_set_keymap('n', 'm', 'Lf', { noremap = true }); + vim.api.nvim_set_keymap('n', 'n', 'LfWorkingDirectory', { noremap = true}); + end } use 'bkad/CamelCaseMotion' use { @@ -383,11 +373,18 @@ return require('packer').startup(function() as = 'hop', config = function() -- you can configure Hop the way you like here; see :h hop-config + vim.api.nvim_set_keymap('', 's', 'HopChar2', { noremap = true }) require'hop'.setup { keys = 'etovxqpdygfblzhckisuran' } end } - use 'ervandew/supertab' - -- The treesitter for nix doesn't do indents + use { + 'ervandew/supertab', + config = function() + -- Default to scrolling down the list + vim.g.SuperTabDefaultCompletionType = "" + end + } +-- The treesitter for nix doesn't do indents use 'LnL7/vim-nix' use { 'dense-analysis/ale', -- cgit v1.2.3