diff options
author | Cody Hiar <cody@hiar.ca> | 2021-11-16 21:11:11 -0700 |
---|---|---|
committer | Cody Hiar <cody@hiar.ca> | 2021-11-16 21:11:11 -0700 |
commit | befa7238acd46e49c9fe16025eaecbba98c20b84 (patch) | |
tree | 6fa7b460a06b33cef43ca71f3277e4358de0603c | |
parent | 4e893c3b70d6559c075c99cde0f0e278080cd165 (diff) |
bunch of reorg/clean
-rw-r--r-- | init.lua | 175 |
1 files changed, 86 insertions, 89 deletions
@@ -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 = "<c-n>" -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', '<Space>', '', {}) +vim.api.nvim_set_keymap('n', '<Space>', '', {}) 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 <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" +]] -options = { noremap = true } - - - -map('n', '<leader><leader>', ':noh<cr>', options) -map('i', 'jj', '<esc>', options) - +-- Keymaps +--noh gets rid of highlighted search results +vim.api.nvim_set_keymap('n', '<leader><leader>', ':noh<cr>', { noremap = true }) +-- `jj` maps to escape +vim.api.nvim_set_keymap('i', 'jj', '<esc>', { noremap = true }) -- Visually select last copied text -map('n', 'gp', "`[v`]", options) -map('n', '<leader>ps', '<cmd>source ~/.config/nvim/init.lua<cr><cmd>PackerSync<cr>', options) -map('n', '<leader>ff', "<cmd>lua require('telescope.builtin').find_files({hidden=true})<cr>", options) -map('n', '<leader>fb', '<cmd>Telescope buffers<cr>', options) -map('n', '<leader>fj', '<cmd>Telescope jumplist<cr>', options) -map('n', '<leader>f/', '<cmd>Telescope live_grep<cr>', options) -map('n', '<leader>fa', '<cmd>Telescope grep_string<cr>', options) -map('n', '<leader>fg', "<cmd>lua require('telescope.builtin').git_status()<cr>", options) -map('n', '<leader>ft', "<cmd>lua require('telescope.builtin').tags({layout_strategy='center', only_sort_tags=true, show_line=true})<cr>", options) - -map('n', '<leader>du', '<cmd>diffupdate<cr>', options) -map('n', '<leader>dd', '<cmd>diffget<cr>', options) -map('n', '<leader>df', '<cmd>diffput<cr>', 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', '<leader>co', '<cmd>copen<cr>', { noremap = true }) +vim.api.nvim_set_keymap('n', '<leader>cc', '<cmd>cclose<cr>', { noremap = true }) -- Visually select line without ending -map('n', '<leader>v', '^v$h', options) - +vim.api.nvim_set_keymap('n', '<leader>v', '^v$h', { noremap = true }) -- Ledger Shortcuts -- Copy the last entry -map('n', '<leader>ll', 'G{jV}y}p10l', options) +vim.api.nvim_set_keymap('n', '<leader>ll', 'G{jV}y}p10l', { noremap = true }) -- Copy the current entry to the bottom, copy date from last entry -map('n', '<leader>lb', '{jV}yGp10l{{jvEy}jvEpl', options) +vim.api.nvim_set_keymap('n', '<leader>lb', '{jV}yGp10l{{jvEy}jvEpl', { noremap = true }) -- Copy the current entry to the next position -map('n', '<leader>ln', '{jV}y}p10l', options) +vim.api.nvim_set_keymap('n', '<leader>ln', '{jV}y}p10l', { noremap = true }) -- Jump down from line to replace dollar ammount -map('n', '<leader>ld', 'j^f$lC', options) +vim.api.nvim_set_keymap('n', '<leader>ld', 'j^f$lC', { noremap = true }) -- After searching pull entry to current position -map('n', '<leader>ly', 'vapy<C-o>p{{jvEy}jvEpl', options) - - -map('n', '<leader>ep', 'ofrom pudb import set_trace; set_trace()<esc>', options) - - - - -map('n', '<c-w>t', "<cmd>tabnew<cr>", options) -map('n', '<c-w><c-f>', '<c-w>f<c-w>T', options) -map('n', '<c-w><c-]>', '<c-w>v<c-]><c-w>T', options) -map('n', '<c-w><c-t>', '<c-w>v<c-w>T', options) -map('n', '<leader>ee', '<cmd>e!<cr>', options) -map('n', '<expr> k', [[(v:count > 1 ? "m'" . v:count : '') . 'k']], options) -map('n', '<expr> j', [[(v:count > 1 ? "m'" . v:count : '') . 'j']], options) - - -map('n', '<leader>co', '<cmd>copen<cr>', options) -map('n', '<leader>cc', '<cmd>cclose<cr>', options) - -map('n', '<leader>ew', '<cmd>ArgWrap<cr>', options) - -map('n', '<leader>gs', '<cmd>Git<cr>', options) -map('n', '<leader>gd', '<cmd>Gdiffsplit<cr>', options) - --- map('n', '<leader>m', '<cmd>Ranger<cr>', options) --- map('n', '<leader>n', '<cmd>RangerWorkingDirectory<cr>', options) -map('n', '<leader>m', '<cmd>LfWorkingDirectory<cr>', options) -map('n', '<leader>n', '<cmd>Lf<cr>', options) - -map('', '<leader>s', '<cmd>HopChar2<cr>', options) - +vim.api.nvim_set_keymap('n', '<leader>ly', 'vapy<C-o>p{{jvEy}jvEpl', { noremap = true }) +-- Shorcut to insert pudb statements for python +vim.api.nvim_set_keymap('n', '<leader>ep', 'ofrom pudb import set_trace; set_trace()<esc>', { noremap = true }) +-- Easy new tab creation +vim.api.nvim_set_keymap('n', '<c-w>t', "<cmd>tabnew<cr>", { noremap = true }) +vim.api.nvim_set_keymap('n', '<c-w><c-f>', '<c-w>f<c-w>T', { noremap = true }) +vim.api.nvim_set_keymap('n', '<c-w><c-]>', '<c-w>v<c-]><c-w>T', { noremap = true }) +vim.api.nvim_set_keymap('n', '<c-w><c-t>', '<c-w>v<c-w>T', { noremap = true }) +vim.api.nvim_set_keymap('n', '<leader>ee', '<cmd>e!<cr>', { noremap = true }) +vim.api.nvim_set_keymap('n', '<expr> k', [[(v:count > 1 ? "m'" . v:count : '') . 'k']], { noremap = true }) +vim.api.nvim_set_keymap('n', '<expr> 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', '<leader>ps', '<cmd>source ~/.config/nvim/init.lua<cr><cmd>PackerSync<cr>', { 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 <c-x><c-o> 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', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', 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', '<leader>ff', "<cmd>lua require('telescope.builtin').find_files({hidden=true})<cr>", { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>fb', '<cmd>Telescope buffers<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>fj', '<cmd>Telescope jumplist<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>f/', '<cmd>Telescope live_grep<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>fa', '<cmd>Telescope grep_string<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>fg', "<cmd>lua require('telescope.builtin').git_status()<cr>", { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>ft', "<cmd>lua require('telescope.builtin').tags({layout_strategy='center', only_sort_tags=true, show_line=true})<cr>", { 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', '<leader>ew', '<cmd>ArgWrap<cr>', { noremap = true }) + end + } + use { + 'tpope/vim-fugitive', + config = function() + vim.api.nvim_set_keymap('n', '<leader>du', '<cmd>diffupdate<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>dd', '<cmd>diffget<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>df', '<cmd>diffput<cr>', { noremap = true }) + vim.api.nvim_set_keymap('n', '<leader>gs', '<cmd>Git<cr>', { 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', '<leader>m', '<cmd>Lf<cr>', { noremap = true }); + vim.api.nvim_set_keymap('n', '<leader>n', '<cmd>LfWorkingDirectory<cr>', { 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('', '<leader>s', '<cmd>HopChar2<cr>', { 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 = "<c-n>" + end + } +-- The treesitter for nix doesn't do indents use 'LnL7/vim-nix' use { 'dense-analysis/ale', |