nvim/lua/config/settings.lua

90 lines
2.4 KiB
Lua
Raw Normal View History

2022-12-31 17:43:31 +01:00
local g = vim.g
local opt = vim.opt
g.mapleader = ' '
g.tex_flavor = 'latex'
g.c_syntax_for_h = true
2023-04-08 23:47:10 +02:00
--opt.wildoptions = true -- TODO: see how it works
2022-12-31 17:43:31 +01:00
opt.termguicolors = true
opt.guicursor = 'n-v-c-sm:hor20,i-ci-ve:ver20,r-cr-o:Block'
opt.mouse = 'nv'
2022-12-31 17:43:31 +01:00
opt.path = '.,,**h'
2023-04-08 23:47:10 +02:00
-- opt.pumheight = 10 -- TODO: probably to change
2022-12-31 17:43:31 +01:00
opt.fileencoding = 'utf-8'
opt.splitbelow = true
opt.splitright = true
2023-04-08 23:47:10 +02:00
opt.smartindent = false -- TODO: maybe?
2022-12-31 17:43:31 +01:00
opt.showmode = false
opt.undofile = true
opt.updatetime = 300
opt.backup = false
opt.clipboard:prepend { 'unnamedplus' }
opt.smartcase = true
opt.cursorline = true
opt.sessionoptions = 'folds'
opt.foldmethod = 'marker'
opt.foldlevel = 0
opt.number = true
opt.hidden = true
opt.shortmess:append('I', 'W', 's')
2023-04-08 23:47:10 +02:00
-- opt.scrolloff = 15 -- TODO: maybe ?
2022-12-31 17:43:31 +01:00
opt.iskeyword:prepend { '-' }
opt.inccommand = 'nosplit'
2023-04-08 23:47:10 +02:00
opt.completeopt:append 'menuone'
2022-12-31 17:43:31 +01:00
opt.timeoutlen = 300
opt['foldenable'] = false
2023-04-08 23:47:10 +02:00
opt.fillchars = 'eob: '
opt.cmdheight = 1
2023-04-20 14:50:06 +02:00
opt.grepprg = 'rg --vimgrep --no-heading --smart-case --hidden'
opt.grepformat = '%f:%l:%c:%m'
2023-04-08 23:47:10 +02:00
-- opt.autochdir = true
2022-12-31 17:43:31 +01:00
2023-04-08 23:47:10 +02:00
vim.api.nvim_create_user_command('Cd', 'lcd %:p:h', { nargs = 0 })
2023-01-22 17:46:45 +01:00
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
2023-04-08 23:47:10 +02:00
vim.cmd [[normal! zz]]
2023-01-22 17:46:45 +01:00
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'"<c-e>]]
end
end
end
vim.api.nvim_create_autocmd({ 'BufWinEnter', 'FileType' }, {
group = vim.api.nvim_create_augroup('nvim-lastplace', {}),
callback = run,
})