nvim/lua/config/settings.lua

128 lines
3.6 KiB
Lua
Raw Normal View History

2022-12-31 17:43:31 +01:00
local g = vim.g
local opt = vim.opt
local function add(value, str, sep)
2023-01-01 19:53:20 +01:00
sep = sep or ','
str = str or ''
value = type(value) == 'table' and table.concat(value, sep) or value
return str ~= '' and table.concat({ value, str }, sep) or value
2022-12-31 17:43:31 +01:00
end
-- Globals {{{
-- g.do_filetype_lua = 1
-- g.did_load_filetypes = 0
g.netrw_liststyle = 1
g.netrw_banner = 0
2023-01-22 16:46:51 +01:00
g.netrw_list_hide = '^\\..*'
2022-12-31 17:43:31 +01:00
g.mapleader = ' '
g.tex_flavor = 'latex'
-- }}}
-- Opts {{{
-- opt.formatoptions = ""
2023-01-23 18:56:08 +01:00
opt.wildoptions = 'tagfile'
--opt.wildchar = 'c'
2022-12-31 17:43:31 +01:00
opt.termguicolors = true
opt.guifont = 'JetBrainsMono Nerd Font'
opt.guicursor = 'n-v-c-sm:hor20,i-ci-ve:ver20,r-cr-o:Block'
opt.mouse = 'vn'
opt.path = '.,,**h'
opt.pumheight = 10
opt.fileencoding = 'utf-8'
opt.splitbelow = true
opt.splitright = true
opt.ts = 4
opt.sw = 4
opt.smartindent = true
--opt.expandtab " Converts tabs to spaces
opt.showmode = false
opt.undofile = true
opt.updatetime = 300
opt.backup = false
opt.clipboard:prepend { 'unnamedplus' }
opt.smartcase = true
opt.cursorline = true
opt.viewoptions = 'folds,cursor'
opt.sessionoptions = 'folds'
opt.foldmethod = 'marker'
opt.foldlevel = 0
opt.number = true
opt.hidden = true
-- opt.shortmess = add { 'I' } -- Don't pass messages to ins-completion-menu.
opt.shortmess:append('I', 'W', 's')
opt.cmdheight = 1
2022-12-31 17:43:31 +01:00
opt.scrolloff = 15
opt.iskeyword:prepend { '-' }
opt.inccommand = 'nosplit'
opt.completeopt = { 'menu', 'menuone', 'noselect' }
opt.timeoutlen = 300
opt.conceallevel = 3
2022-12-31 17:43:31 +01:00
opt.concealcursor = 'n'
opt['foldenable'] = false
-- opt.fillchars = 'vert:▏'
opt.fillchars.eob = ' '
-- opt.fillchars.vert="▏"
opt.sessionoptions = add { 'options', 'resize', 'winpos', 'terminal' }
opt.autochdir = false
-- }}}
-- Commands and autocommands {{{
vim.api.nvim_create_user_command('Pdf', '!pandoc % -o %:r.pdf', { nargs = 0 })
vim.api.nvim_create_user_command('Slide', '!pandoc -t beamer % -o %:r.pdf', { nargs = 0 })
vim.api.nvim_create_user_command('Cd', 'lcd %:p:h', { nargs = 0 })
2023-01-22 17:46:45 +01:00
-- vim.api.nvim_create_autocmd({ 'BufWinLeave', 'BufLeave', 'WinLeave' }, { pattern = { '?*' }, command = 'mkview' })
-- vim.api.nvim_create_autocmd({ 'BufWinEnter' }, { pattern = { '?*' }, command = 'silent! loadview' })
2022-12-31 17:43:31 +01:00
-- }}}
function ToggleTroubleAuto()
local ok, trouble = pcall(require, 'trouble')
if ok then
vim.defer_fn(function()
vim.cmd 'cclose'
trouble.open 'quickfix'
end, 0)
end
end
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
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,
})