This repository has been archived on 2024-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
neovim/config/basic.lua

203 lines
4.8 KiB
Lua
Raw Normal View History

-------------------------------------------------------------------------------
--
-- Basic Settings
--
vim.cmd("filetype off")
-- Leaders
vim.g.mapleader = ","
vim.g.maplocalleader = "-"
-- Better Unix support
vim.opt.viewoptions = { "folds", "options", "cursor", "unix", "slash" }
vim.opt.encoding = "utf-8"
-- True color support
vim.opt.termguicolors = true
-- Other options
vim.cmd("syntax on")
vim.opt.backspace = { "indent", "eol", "start" }
vim.opt.laststatus = 2
vim.opt.showmode = false
-- Tabs as spaces
vim.opt.expandtab = true
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
-- Fixes broken cursor on Linux
vim.opt.guicursor = ""
-- Disable mouse / touchpad
vim.opt.mouse = ""
-- Incremental substitutin
vim.opt.inccommand = "split"
-------------------------------------------------------------------------------
--
-- General editor options
--
-- Hide files when leaving them.
vim.opt.hidden = true
-- Show line numbers.
vim.opt.number = true
-- Minimum line number column width.
vim.opt.numberwidth = 1
-- Number of screen lines to use for the commandline.
vim.opt.cmdheight = 2
-- Lines length limit (0 if no limit).
vim.opt.textwidth = 0
-- Don't cut lines in the middle of a work.
vim.opt.linebreak = true
-- Show matching parenthesis.
vim.opt.showmatch = true
-- Time during which the matching parenthesis is shown.
vim.opt.matchtime = 2
-- Sensible default line auto cutting and formatting.
vim.opt.formatoptions = "jtcrq"
-- Copy/Past to/from clipboard.
vim.opt.clipboard = "unnamedplus"
-- Highlight line cursor is currently on.
vim.opt.cursorline = true
-- Invisible characters representation when :set list
vim.opt.listchars = {
tab = "",
trail = "~",
nbsp = "",
eol = "¬",
}
-- Search
-- Incremental search.
vim.opt.incsearch = true
-- Case insensitive.
vim.opt.ignorecase = true
-- Case insensitive if no uppercase letter in pattern, case sensitive otherwise.
vim.opt.smartcase = true
-- Spell
vim.opt.spelllang = "en,ru"
-- Fold level
vim.opt.foldlevel = 99
vim.opt.foldlevelstart = 99
vim.opt.foldminlines = 3
vim.opt.foldnestmax = 5
-------------------------------------------------------------------------------
--
-- File type specified
--
local bufReadFile = { "BufNewFile", "BufRead" }
-- Set up a line limiter for each lang
local line_limiter_augroup = vim.api.nvim_create_augroup("line_limiter", {})
local function set_line_limiter(limit, patterns)
vim.api.nvim_create_autocmd(bufReadFile, {
pattern = patterns,
group = line_limiter_augroup,
callback = function()
vim.wo.colorcolumn = tostring(limit)
end,
})
end
set_line_limiter(101, {
"*.nix",
"*.vim",
"*.lua",
"*.ts",
"*.tsx",
"*.js",
"*.jsx",
"*.rs",
})
set_line_limiter(81, {
"*.json",
"*.yml",
"*.yaml",
"*.md",
"*.html",
"*.css",
})
-- Spell check for markdown files
local spell_check_augroup = vim.api.nvim_create_augroup("spell_check", {})
vim.api.nvim_create_autocmd(bufReadFile, {
pattern = { "*.md" },
group = spell_check_augroup,
callback = function()
vim.wo.spell = true
end,
})
-- Set up fold method for each lang
local folding_augroup = vim.api.nvim_create_augroup("folding", {})
vim.api.nvim_create_autocmd(bufReadFile, {
group = folding_augroup,
pattern = {
"*.js",
"*.jsx",
"*.ts",
"*.tsx",
},
callback = function()
vim.cmd("syntax on")
vim.wo.foldmethod = "syntax"
end,
})
-------------------------------------------------------------------------------
--
-- Bindings
--
local function clear_search_hl()
vim.opt.hlsearch = false
end
vim.keymap.set("n", "<C-z>", clear_search_hl, { desc = "Clear search highlighting" })
-- Enable fast navigation between windows
vim.keymap.set("n", "<C-h>", "<C-W>h")
vim.keymap.set("n", "<C-l>", "<C-W>l")
vim.keymap.set("n", "<C-j>", "<C-W>j")
vim.keymap.set("n", "<C-k>", "<C-W>k")
-- Disable the annoying and useless ex-mode
vim.keymap.set("n", "Q", "<nop>")
vim.keymap.set("n", "gQ", "<nop>")
-- Disable arrow keys
vim.keymap.set("n", "<Up>", "<nop>")
vim.keymap.set("n", "<Down>", "<nop>")
vim.keymap.set("n", "<Left>", "<nop>")
vim.keymap.set("n", "<Right>", "<nop>")
vim.keymap.set("v", "<Up>", "<nop>")
vim.keymap.set("v", "<Down>", "<nop>")
vim.keymap.set("v", "<Left>", "<nop>")
vim.keymap.set("v", "<Right>", "<nop>")
-- ... instead of insert mode for rus lang and popups
-- vim.keymap.set("i", "<Up>", "<nop>")
-- vim.keymap.set("i", "<Down>", "<nop>")
-- vim.keymap.set("i", "<Left>", "<nop>")
-- vim.keymap.set("i", "<Right>", "<nop>")
-- Disable page up / down
vim.keymap.set("n", "<PageUp>", "<nop>")
vim.keymap.set("n", "<PageDown>", "<nop>")
vim.keymap.set("v", "<PageUp>", "<nop>")
vim.keymap.set("v", "<PageDown>", "<nop>")
vim.keymap.set("i", "<PageUp>", "<nop>")
vim.keymap.set("i", "<PageDown>", "<nop>")
-------------------------------------------------------------------------------
--
-- Abbreviatures
--
vim.cmd("cabbrev bsp belowright split")
vim.cmd("cabbrev rvsp belowright vsplit")