diff --git a/.gitignore b/.gitignore index 005b535b606..8a192cab54d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ test.sh nvim spell/ -lazy-lock.json diff --git a/init.lua b/init.lua index b98ffc6198a..67dde3a6d4b 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,5 @@ --[[ - +--- Benoit's custom file ===================================================================== ==================== READ THIS BEFORE CONTINUING ==================== ===================================================================== @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.o` @@ -99,7 +99,7 @@ vim.g.have_nerd_font = false -- For more options, you can see `:help option-list` -- Make line numbers default -vim.o.number = true +vim.o.number = false -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! -- vim.o.relativenumber = true @@ -974,10 +974,10 @@ require('lazy').setup({ -- Uncomment any of the lines below to enable them (you will need to restart nvim). -- -- require 'kickstart.plugins.debug', - -- require 'kickstart.plugins.indent_line', + require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', + require 'kickstart.plugins.neo-tree', -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` @@ -1012,5 +1012,62 @@ require('lazy').setup({ }, }) +-- adapted from https://github.com/ethanholz/nvim-lastplace/blob/main/lua/nvim-lastplace/init.lua +local ignore_buftype = { 'quickfix', 'nofile', 'help' } +local ignore_filetype = { 'gitcommit', 'gitrebase', 'svn', 'hgcommit' } + +local function run() + if vim.tbl_contains(ignore_buftype, vim.bo.buftype) then + return + end + + if vim.tbl_contains(ignore_filetype, vim.bo.filetype) then + -- reset cursor to first line + vim.cmd [[normal! gg]] + return + end + + -- If a line has already been specified on the command line, we are done + -- nvim file +num + if vim.fn.line '.' > 1 then + return + end + + local last_line = vim.fn.line [['"]] + local buff_last_line = vim.fn.line '$' + + -- If the last line is set and the less than the last line in the buffer + if last_line > 0 and last_line <= buff_last_line then + local win_last_line = vim.fn.line 'w$' + local win_first_line = vim.fn.line 'w0' + -- Check if the last line of the buffer is the same as the win + if win_last_line == buff_last_line then + -- Set line to last line edited + vim.cmd [[normal! g`"]] + -- Try to center + elseif buff_last_line - last_line > ((win_last_line - win_first_line) / 2) - 1 then + vim.cmd [[normal! g`"zz]] + else + vim.cmd [[normal! G'"]] + end + end +end + +vim.api.nvim_create_autocmd('BufRead', { + callback = function(opts) + vim.api.nvim_create_autocmd('BufWinEnter', { + once = true, + buffer = opts.buf, + callback = function() + local ft = vim.bo[opts.buf].filetype + local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1] + if not (ft:match 'commit' and ft:match 'rebase') and last_known_line > 1 and last_known_line <= vim.api.nvim_buf_line_count(opts.buf) then + vim.api.nvim_feedkeys([[g`"]], 'nx', false) + end + end, + }) + end, +}) + -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et