mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
Compare commits
No commits in common. "2372d9159f52d77842474e8cd3ea90ca309c2903" and "efa7b215e7010de3d1d03cc3e4adbc5ca89f3b26" have entirely different histories.
2372d9159f
...
efa7b215e7
@ -41,6 +41,26 @@ function s:resume_cursor_position() abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Display a message when the current file is not in utf-8 format.
|
||||||
|
" Note that we need to use `unsilent` command here because of this issue:
|
||||||
|
" https://github.com/vim/vim/issues/4379
|
||||||
|
augroup non_utf8_file_warn
|
||||||
|
autocmd!
|
||||||
|
" we can not use `lua vim.notify()`: it will error out E5107 parsing lua.
|
||||||
|
autocmd BufRead * if &fileencoding != 'utf-8' | call v:lua.vim.notify('File not in UTF-8 format!', 'warn', {'title': 'nvim-config'}) | endif
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
" Automatically reload the file if it is changed outside of Nvim, see
|
||||||
|
" https://unix.stackexchange.com/a/383044/221410. It seems that `checktime`
|
||||||
|
" command does not work in command line. We need to check if we are in command
|
||||||
|
" line before executing this command. See also
|
||||||
|
" https://vi.stackexchange.com/a/20397/15292.
|
||||||
|
augroup auto_read
|
||||||
|
autocmd!
|
||||||
|
autocmd FileChangedShellPost * call v:lua.vim.notify("File changed on disk. Buffer reloaded!", 'warn', {'title': 'nvim-config'})
|
||||||
|
autocmd FocusGained,CursorHold * if getcmdwintype() == '' | checktime | endif
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup numbertoggle
|
augroup numbertoggle
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
|
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
|
||||||
@ -68,6 +88,12 @@ function! s:custom_highlight() abort
|
|||||||
highlight MatchParen cterm=bold,underline gui=bold,underline
|
highlight MatchParen cterm=bold,underline gui=bold,underline
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" highlight yanked region, see `:h lua-highlight`
|
||||||
|
augroup highlight_yank
|
||||||
|
autocmd!
|
||||||
|
au TextYankPost * silent! lua vim.highlight.on_yank{higroup="YankColor", timeout=300, on_visual=false}
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup auto_close_win
|
augroup auto_close_win
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufEnter * call s:quit_current_win()
|
autocmd BufEnter * call s:quit_current_win()
|
||||||
@ -99,6 +125,17 @@ augroup git_repo_check
|
|||||||
autocmd VimEnter,DirChanged * call utils#Inside_git_repo()
|
autocmd VimEnter,DirChanged * call utils#Inside_git_repo()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
" Auto-generate packer_compiled.lua file
|
||||||
|
augroup packer_auto_compile
|
||||||
|
autocmd!
|
||||||
|
autocmd BufWritePost */nvim/lua/plugins.lua source <afile> | PackerCompile
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
augroup auto_create_dir
|
||||||
|
autocmd!
|
||||||
|
autocmd BufWritePre * lua require('utils').may_create_dir()
|
||||||
|
augroup END
|
||||||
|
|
||||||
" ref: https://vi.stackexchange.com/a/169/15292
|
" ref: https://vi.stackexchange.com/a/169/15292
|
||||||
function! s:handle_large_file() abort
|
function! s:handle_large_file() abort
|
||||||
let g:large_file = 10485760 " 10MB
|
let g:large_file = 10485760 " 10MB
|
||||||
@ -118,6 +155,3 @@ augroup LargeFile
|
|||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufReadPre * call s:handle_large_file()
|
autocmd BufReadPre * call s:handle_large_file()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" Load auto-command defined in Lua
|
|
||||||
lua require("custom-autocmd")
|
|
||||||
|
|||||||
@ -1,92 +0,0 @@
|
|||||||
local fn = vim.fn
|
|
||||||
local api = vim.api
|
|
||||||
|
|
||||||
local utils = require("utils")
|
|
||||||
|
|
||||||
|
|
||||||
-- Display a message when the current file is not in utf-8 format.
|
|
||||||
-- Note that we need to use `unsilent` command here because of this issue:
|
|
||||||
-- https://github.com/vim/vim/issues/4379
|
|
||||||
api.nvim_create_augroup("non_utf8_file", {
|
|
||||||
clear = true
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "BufRead" }, {
|
|
||||||
pattern = "*",
|
|
||||||
group = "non_utf8_file",
|
|
||||||
callback = function()
|
|
||||||
if vim.bo.fileencoding ~= 'utf-8' then
|
|
||||||
vim.notify("File not in UTF-8 format!", vim.log.levels.WARN, { title = "nvim-config" })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- highlight yanked region, see `:h lua-highlight`
|
|
||||||
api.nvim_create_augroup("highlight_yank", {
|
|
||||||
clear = true
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "TextYankPost" }, {
|
|
||||||
pattern = "*",
|
|
||||||
group = "highlight_yank",
|
|
||||||
callback = function()
|
|
||||||
vim.highlight.on_yank { higroup = "YankColor", timeout = 300, on_visual = false }
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Auto-generate packer_compiled.lua file
|
|
||||||
api.nvim_create_augroup("packer_auto_compile", {
|
|
||||||
clear = true
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "BufWritePost" }, {
|
|
||||||
pattern = "*/nvim/lua/plugins.lua",
|
|
||||||
group = "packer_auto_compile",
|
|
||||||
callback = function()
|
|
||||||
local fpath = fn.expand("<afile>")
|
|
||||||
local cmd = "source " .. fpath
|
|
||||||
vim.cmd(cmd)
|
|
||||||
vim.cmd("PackerCompile")
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Auto-create dir when saving a file, in case some intermediate directory does not exist
|
|
||||||
api.nvim_create_augroup("auto_create_dir", {
|
|
||||||
clear = true
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "BufWritePre" }, {
|
|
||||||
pattern = "*",
|
|
||||||
group = "auto_create_dir",
|
|
||||||
callback = function()
|
|
||||||
local fpath = fn.expand('<afile>')
|
|
||||||
local dir = fn.fnamemodify(fpath, ":p:h")
|
|
||||||
|
|
||||||
utils.may_create_dir(dir)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Automatically reload the file if it is changed outside of Nvim, see https://unix.stackexchange.com/a/383044/221410.
|
|
||||||
-- It seems that `checktime` does not work in command line. We need to check if we are in command
|
|
||||||
-- line before executing this command, see also https://vi.stackexchange.com/a/20397/15292 .
|
|
||||||
api.nvim_create_augroup("auto_read", {
|
|
||||||
clear = true
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "FileChangedShellPost" }, {
|
|
||||||
pattern = "*",
|
|
||||||
group = "auto_read",
|
|
||||||
callback = function()
|
|
||||||
vim.notify("File changed on disk. Buffer reloaded!", vim.log.levels.WARN, { title = "nvim-config" })
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
api.nvim_create_autocmd({ "FocusGained", "CursorHold" }, {
|
|
||||||
pattern = "*",
|
|
||||||
group = "auto_read",
|
|
||||||
callback = function()
|
|
||||||
if fn.getcmdwintype() == '' then
|
|
||||||
vim.cmd("checktime")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
@ -15,12 +15,13 @@ function M.executable(name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Create a dir if if does not exist
|
function M.may_create_dir()
|
||||||
function M.may_create_dir(dir)
|
local fpath = fn.expand('<afile>')
|
||||||
local res = fn.isdirectory(dir)
|
local parent_dir = fn.fnamemodify(fpath, ":p:h")
|
||||||
|
local res = fn.isdirectory(parent_dir)
|
||||||
|
|
||||||
if res == 0 then
|
if res == 0 then
|
||||||
fn.mkdir(dir, 'p')
|
fn.mkdir(parent_dir, 'p')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user