nvim/lua/options.lua

79 lines
1.9 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

G.opt.ttimeout = true
G.opt.ttimeoutlen = 100
-- 行号
G.opt.nu = true
G.opt.rnu = true
G.opt.scrolloff = 999
-- 自动保存
G.opt.autowriteall = true
-- tab键
G.opt.sw = 2
G.opt.ts = 2
G.opt.softtabstop = 2
G.opt.smarttab = true
G.opt.expandtab = true
G.opt.autoindent = true
-- 光标
G.opt.cursorline = true
-- 分屏
G.opt.splitright = true
G.opt.splitbelow = true
-- 搜索
G.opt.ignorecase = true
G.opt.incsearch = true
-- 不换行
G.opt.textwidth = 0
G.opt.wrap = false
-- 文件判断
G.cmd("filetype plugin indent on")
-- 取消换行注释o 和 O 不自动续注释回车继续续注释一次设定formatoptions 不会变)
G.opt.formatoptions = G.opt.formatoptions - "o" + "r"
-- 进入插入模式时自动关搜索高亮(个人偏好:打字时不想被高亮干扰)
G.au({ "InsertEnter" }, {
pattern = { "*" },
callback = function()
G.opt.hlsearch = false
end,
})
-- .code-snippets 文件强制识别为 JSON方便编辑否则无法语法高亮
G.au({ "VimEnter", "BufEnter" }, {
pattern = { "*.code-snippets" },
callback = function()
G.cmd("setfiletype json")
end,
})
-- 自动检测 Conda Python 环境,优先用 conda 里的 python
local function isempty(s)
return s == nil or s == ""
end
local function use_if_defined(val, fallback)
return val ~= nil and val or fallback
end
local conda_prefix = os.getenv("CONDA_PREFIX")
if not isempty(conda_prefix) then
vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, conda_prefix .. "/bin/python")
vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, conda_prefix .. "/bin/python")
else
vim.g.python_host_prog = use_if_defined(vim.g.python_host_prog, "python")
vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, "python3")
end