settings.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. -- split to the right by default
  30. vim.o.splitright = true
  31. -- make a new copy of the file for backup
  32. -- setting to no or auto messes with filewatchers
  33. vim.o.backupcopy = 'yes'
  34. -- disable modelines
  35. vim.o.modeline = false
  36. -- show preview of lines when using :s
  37. vim.o.inccommand = 'split'
  38. -- mouse only in visual mode
  39. vim.o.mouse = 'v'
  40. -- use POSIX-y shell for !
  41. vim.o.shell = '/bin/sh'
  42. -- diff options, increase linematch to 60 and use histogram algorithm
  43. vim.o.diffopt = 'internal,filler,closeoff,linematch:60,algorithm:histogram'
  44. -- basic keymaps
  45. -- j/k with wraps
  46. vim.keymap.set({ 'n', 'v' }, 'j', 'gj')
  47. vim.keymap.set({ 'n', 'v' }, 'k', 'gk')
  48. -- select pasted text
  49. vim.keymap.set('n', 'gp', '`[v`]')
  50. -- format on save
  51. vim.api.nvim_create_autocmd('BufWritePre', {
  52. callback = function(opts)
  53. if vim.bo.filetype == 'diff' then
  54. return
  55. end
  56. if not vim.g.no_lsp_format then
  57. -- check if can LSP format
  58. local clients = vim.lsp.get_clients({ bufnr = opts.buf, method = 'textDocument/formatting' })
  59. if #clients > 0 then
  60. vim.lsp.buf.format({ bufnr = opts.buf })
  61. end
  62. end
  63. -- otherwise strip trailing whitespace
  64. vim.cmd('%s/\\s\\+$//e')
  65. end,
  66. })