settings.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. -- change terminal title
  2. vim.o.title = true
  3. -- default indentation
  4. vim.o.shiftwidth = 2
  5. vim.o.tabstop = 4
  6. vim.o.expandtab = true
  7. -- permanent undo history
  8. vim.o.undofile = true
  9. -- allow switching buffers
  10. vim.o.hidden = true
  11. -- always scroll (keep current line vertically centered)
  12. vim.o.scrolloff = 999
  13. -- show line numbers
  14. vim.o.number = true
  15. vim.o.relativenumber = true
  16. -- set wordwrap indent
  17. vim.o.wrap = false
  18. vim.o.linebreak = true
  19. vim.o.breakindent = true
  20. vim.o.breakindentopt = 'shift:2,sbr'
  21. -- show whitespace
  22. vim.o.list = true
  23. -- disable search highlight
  24. vim.o.hlsearch = false
  25. -- always show sign column to avoid layout shift when staging
  26. vim.o.signcolumn = 'yes'
  27. -- have preview window be a bit taller
  28. vim.o.previewheight = 20
  29. -- make a new copy of the file for backup
  30. -- setting to no or auto messes with filewatchers
  31. vim.o.backupcopy = 'yes'
  32. -- disable modelines
  33. vim.o.modeline = false
  34. -- show preview of lines when using :s
  35. vim.o.inccommand = 'split'
  36. -- mouse only in visual mode
  37. vim.o.mouse = 'v'
  38. -- use POSIX-y shell for !
  39. vim.o.shell = '/bin/sh'
  40. -- diff options, increase linematch to 60 and use histogram algorithm
  41. vim.o.diffopt = 'internal,filler,closeoff,linematch:60,algorithm:histogram'
  42. -- basic keymaps
  43. -- j/k with wraps
  44. vim.keymap.set({ 'n', 'v' }, 'j', 'gj')
  45. vim.keymap.set({ 'n', 'v' }, 'k', 'gk')
  46. -- select pasted text
  47. vim.keymap.set('n', 'gp', '`[v`]')
  48. -- format on save
  49. vim.api.nvim_create_autocmd('BufWritePre', {
  50. callback = function(opts)
  51. if vim.bo.filetype == 'diff' then
  52. return
  53. end
  54. if not vim.g.no_lsp_format then
  55. -- check if can LSP format
  56. local clients = vim.lsp.get_clients({ bufnr = opts.buf, method = 'textDocument/formatting' })
  57. if #clients > 0 then
  58. vim.lsp.buf.format({ bufnr = opts.buf })
  59. end
  60. end
  61. -- otherwise strip trailing whitespace
  62. vim.cmd('%s/\\s\\+$//e')
  63. end,
  64. })