1
0

settings.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. -- ; as :
  42. vim.keymap.set({ 'n', 'v' }, ';', ':')
  43. -- leave insert mode via jj
  44. vim.keymap.set('i', 'jj', '<ESC>')
  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. })