settings.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. -- basic keymaps
  41. -- j/k with wraps
  42. vim.keymap.set({ 'n', 'v' }, 'j', 'gj')
  43. vim.keymap.set({ 'n', 'v' }, 'k', 'gk')
  44. -- select pasted text
  45. vim.keymap.set('n', 'gp', '`[v`]')
  46. -- format on save
  47. vim.api.nvim_create_autocmd('BufWritePre', {
  48. callback = function(opts)
  49. if vim.bo.filetype == 'diff' then
  50. return
  51. end
  52. if not vim.g.no_lsp_format then
  53. -- check if can LSP format
  54. local clients = vim.lsp.get_clients({ bufnr = opts.buf, method = 'textDocument/formatting' })
  55. if #clients > 0 then
  56. vim.lsp.buf.format({ bufnr = opts.buf })
  57. end
  58. end
  59. -- otherwise strip trailing whitespace
  60. vim.cmd('%s/\\s\\+$//e')
  61. end,
  62. })