After committing I realised that indents on GitHub show differently from what I see in Neovim.
I also noticed that all formatting (including indentation) is reset when an error occurs when loading the lazy package manager, the code in this case looks the same as in GitHub
I want my editor not to lie me so it looks exactly the same in all editors.
What am I missing? :)
Neovim:
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
-- AUTOPAIRS
{
'windwp/nvim-autopairs',
event = "InsertEnter",
opts = {}
},
-- TELESCOPE
{
'nvim-telescope/telescope.nvim', tag = '0.1.5',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local actions = require("telescope.actions")
require("telescope").setup{
defaults = {
mappings = {
i = {
["<C-k>"] = actions.move_selection_previous, -- move to prev result
["<C-j>"] = actions.move_selection_next, -- move to next result
},
},
},
}
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>gf', builtin.git_files, {})
end
},
-- TREE-SITTER
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "html", "css", "javascript", "typescript", "lua", "vim" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
},
-- COLORSCHEME
{
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
opts = {},
config = function()
require("tokyonight").setup({
transparent = true
})
vim.cmd[[colorscheme tokyonight-moon]]
end
}
})
GitHub:
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
-- AUTOPAIRS
{
'windwp/nvim-autopairs',
event = "InsertEnter",
opts = {}
},
-- TELESCOPE
{
'nvim-telescope/telescope.nvim', tag = '0.1.5',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local actions = require("telescope.actions")
require("telescope").setup{
defaults = {
mappings = {
i = {
["<C-k>"] = actions.move_selection_previous, -- move to prev result
["<C-j>"] = actions.move_selection_next, -- move to next result
},
},
},
}
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>gf', builtin.git_files, {})
end
},
-- TREE-SITTER
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function ()
local configs = require("nvim-treesitter.configs")
configs.setup({
ensure_installed = { "html", "css", "javascript", "typescript", "lua", "vim" },
sync_install = false,
highlight = { enable = true },
indent = { enable = true },
})
end
},
-- COLORSCHEME
{
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
opts = {},
config = function()
require("tokyonight").setup({
transparent = true
})
vim.cmd[[colorscheme tokyonight-moon]]
end
}
})
options.lua:
vim.g.mapleader = " "
vim.wo.number = true
vim.o.mouse = 'a'
vim.o.termguicolors = true
vim.o.expandtab = false
vim.o.shiftwidth = 2
vim.o.tabstop = 2
vim.o.smartindent = true
'expandtab'
).\t
, ASCII code 0x09), which different tools display as different widths. The only place where tabs are required is in Makefiles (for extremely historical reasons). Outside of that, I second Luc's answer: I recommend always coding with spaces and configuring your editor to just insert spaces when you hit TAB.