aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2022-09-11 18:24:10 +0800
committerGitHub <noreply@github.com>2022-09-11 18:24:10 +0800
commit40fa9aab1cbd9ce176140d733ec7157fa7e0a5b6 (patch)
tree5bd2dd21b365a3e419aad4481493ae9630238153
parent89effe8b172ef871ca38a90ff77003f5a796e521 (diff)
parent6e8e61e53ae15af3a9f5a3577ffea424dd95b66d (diff)
Merge pull request #104 from jdhao/global
global.vim --> global.lua
-rw-r--r--core/globals.lua81
-rw-r--r--core/globals.vim77
-rw-r--r--init.lua2
-rw-r--r--lua/utils.lua17
4 files changed, 94 insertions, 83 deletions
diff --git a/core/globals.lua b/core/globals.lua
new file mode 100644
index 0000000..56c5b19
--- /dev/null
+++ b/core/globals.lua
@@ -0,0 +1,81 @@
+local fn = vim.fn
+local api = vim.api
+
+local utils = require('utils')
+
+-- Inspect something
+function _G.inspect(item)
+ vim.pretty_print(item)
+end
+
+------------------------------------------------------------------------
+-- custom variables --
+------------------------------------------------------------------------
+vim.g.is_win = (utils.has("win32") or utils.has("win64")) and true or false
+vim.g.is_linux = (utils.has("unix") and (not utils.has("macunix"))) and true or false
+vim.g.is_mac = utils.has("macunix") and true or false
+
+vim.g.logging_level = "info"
+
+------------------------------------------------------------------------
+-- builtin variables --
+------------------------------------------------------------------------
+vim.g.loaded_perl_provider = 0 -- Disable perl provider
+vim.g.loaded_ruby_provider = 0 -- Disable ruby provider
+vim.g.loaded_node_provider = 0 -- Disable node provider
+vim.g.did_install_default_menus = 1 -- do not load menu
+
+if utils.executable('python3') then
+ if vim.g.is_win then
+ vim.g.python3_host_prog = fn.substitute(fn.exepath("python3"), ".exe$", '', 'g')
+ else
+ vim.g.python3_host_prog = fn.exepath("python3")
+ end
+else
+ api.nvim_err_writeln("Python3 executable not found! You must install Python3 and set its PATH correctly!")
+ return
+end
+
+-- Custom mapping <leader> (see `:h mapleader` for more info)
+vim.g.mapleader = ','
+
+-- Enable highlighting for lua HERE doc inside vim script
+vim.g.vimsyn_embed = 'l'
+
+-- Use English as main language
+if not vim.g.is_mac then
+ vim.cmd [[language en_US.utf-8]]
+end
+
+-- use filetype.lua instead of filetype.vim
+vim.g.do_filetype_lua = 1
+vim.g.did_load_filetypes = 0
+
+-- Disable loading certain plugins
+
+-- Whether to load netrw by default, see https://github.com/bling/dotvim/issues/4
+vim.g.loaded_netrw = 1
+vim.g.loaded_netrwPlugin = 1
+vim.g.netrw_liststyle = 3
+if vim.g.is_win then
+ vim.g.netrw_http_cmd = "curl --ssl-no-revoke -Lo"
+end
+
+-- Do not load tohtml.vim
+vim.g.loaded_2html_plugin = 1
+
+-- Do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all these plugins are
+-- related to checking files inside compressed files)
+vim.g.loaded_zipPlugin = 1
+vim.g.loaded_gzip = 1
+vim.g.loaded_tarPlugin = 1
+
+-- Do not load the tutor plugin
+vim.g.loaded_tutor_mode_plugin = 1
+
+-- Do not use builtin matchit.vim and matchparen.vim since we use vim-matchup
+vim.g.loaded_matchit = 1
+vim.g.loaded_matchparen = 1
+
+-- Disable sql omni completion, it is broken.
+vim.g.loaded_sql_completion = 1
diff --git a/core/globals.vim b/core/globals.vim
deleted file mode 100644
index b6103ec..0000000
--- a/core/globals.vim
+++ /dev/null
@@ -1,77 +0,0 @@
-"{ Global Variable
-"{{ Custom variables
-let g:is_win = (has('win32') || has('win64')) ? v:true : v:false
-let g:is_linux = (has('unix') && !has('macunix')) ? v:true : v:false
-let g:is_mac = has('macunix') ? v:true : v:false
-let g:logging_level = 'info'
-"}}
-
-"{{ Builtin variables
-" Disable perl provider
-let g:loaded_perl_provider = 0
-
-" Disable ruby provider
-let g:loaded_ruby_provider = 0
-
-" Disable node provider
-let g:loaded_node_provider = 0
-
-let g:did_install_default_menus = 1 " do not load menu
-
-" Path to Python 3 interpreter (must be an absolute path), make startup
-" faster. See https://neovim.io/doc/user/provider.html.
-if executable('python')
- if g:is_win
- let g:python3_host_prog=substitute(exepath('python'), '.exe$', '', 'g')
- elseif g:is_linux || g:is_mac
- let g:python3_host_prog=exepath('python')
- endif
-else
- echoerr 'Python 3 executable not found! You must install Python 3 and set its PATH correctly!'
-endif
-
-" Custom mapping <leader> (see `:h mapleader` for more info)
-let g:mapleader = ','
-
-" Enable highlighting for lua HERE doc inside vim script
-let g:vimsyn_embed = 'l'
-
-" Use English as main language
-if !g:is_mac
- language en_US.utf-8
-endif
-
-" use filetype.lua instead of filetype.vim
-let g:do_filetype_lua = 1
-let g:did_load_filetypes = 0
-"}}
-
-"{{ Disable loading certain plugins
-" Whether to load netrw by default, see
-" https://github.com/bling/dotvim/issues/4
-let g:loaded_netrw = 1
-let g:loaded_netrwPlugin = 1
-let g:netrw_liststyle = 3
-if g:is_win
- let g:netrw_http_cmd = 'curl --ssl-no-revoke -Lo'
-endif
-
-" Do not load tohtml.vim
-let g:loaded_2html_plugin = 1
-
-" Do not load zipPlugin.vim, gzip.vim and tarPlugin.vim (all these plugins are
-" related to checking files inside compressed files)
-let g:loaded_zipPlugin = 1
-let loaded_gzip = 1
-let g:loaded_tarPlugin = 1
-
-let g:loaded_tutor_mode_plugin = 1 " do not load the tutor plugin
-
-" Do not use builtin matchit.vim and matchparen.vim since we use vim-matchup
-let g:loaded_matchit = 1
-let g:loaded_matchparen = 1
-"}}
-
-" Disable sql omni completion, it is broken.
-let g:loaded_sql_completion = 1
-"}
diff --git a/init.lua b/init.lua
index 658d3ce..fbbfbb9 100644
--- a/init.lua
+++ b/init.lua
@@ -22,7 +22,7 @@ if nvim_ver ~= expected_ver then
end
local core_conf_files = {
- "globals.vim", -- some global settings
+ "globals.lua", -- some global settings
"options.vim", -- setting options in nvim
"autocommands.vim", -- various autocommands
"mappings.lua", -- all the user-defined mappings
diff --git a/lua/utils.lua b/lua/utils.lua
index d3198ac..ab1473f 100644
--- a/lua/utils.lua
+++ b/lua/utils.lua
@@ -1,10 +1,5 @@
local fn = vim.fn
--- inspect something
-function _G.inspect(item)
- vim.pretty_print(item)
-end
-
local M = {}
function M.executable(name)
@@ -15,6 +10,18 @@ function M.executable(name)
return false
end
+--- check whether a feature exists in Nvim
+--- @feat: string
+--- the feature name, like `nvim-0.7` or `unix`.
+--- return: bool
+M.has = function(feat)
+ if fn.has(feat) == 1 then
+ return true
+ end
+
+ return false
+end
+
--- Create a dir if it does not exist
function M.may_create_dir(dir)
local res = fn.isdirectory(dir)