add nvim
All checks were successful
Hydra nixosConfigurations.container-default-x86_64-linux Hydra build #23446 of nixos-config:pr618:nixosConfigurations.container-default-x86_64-linux
Hydra nixosConfigurations.container-default-aarch64-linux Hydra build #23444 of nixos-config:pr618:nixosConfigurations.container-default-aarch64-linux
Hydra nixosConfigurations.container-default-riscv64-linux Hydra build #23445 of nixos-config:pr618:nixosConfigurations.container-default-riscv64-linux
Hydra checks.x86_64-linux.containers-default Hydra build #23443 of nixos-config:pr618:checks.x86_64-linux.containers-default
Hydra nixosConfigurations.not522 Hydra build #23447 of nixos-config:pr618:nixosConfigurations.not522
Hydra nixosConfigurations.not522-installer Hydra build #23448 of nixos-config:pr618:nixosConfigurations.not522-installer

This commit is contained in:
Charlotte 🦝 Delenk 2024-11-03 20:36:23 +01:00
parent 2b0a16d201
commit dd6abdb59e
54 changed files with 3606 additions and 0 deletions

View file

@ -1,6 +1,7 @@
_: {
imports = [
./shell
./editors
];
home-manager.users.root.imports = [
./home-manager.nix

View file

@ -0,0 +1,5 @@
_: {
imports = [
./nvim
];
}

View file

@ -0,0 +1,39 @@
set commentstring=//\ %s
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
nnoremap <silent> <buffer> <F9> :call <SID>compile_run_cpp()<CR>
function! s:compile_run_cpp() abort
let src_path = expand('%:p:~')
let src_noext = expand('%:p:~:r')
" The building flags
let _flag = '-Wall -Wextra -std=c++11 -O2'
if executable('clang++')
let prog = 'clang++'
elseif executable('g++')
let prog = 'g++'
else
echoerr 'No C++ compiler found on the system!'
endif
call s:create_term_buf('h', 20)
execute printf('term %s %s %s -o %s && %s', prog, _flag, src_path, src_noext, src_noext)
startinsert
endfunction
function s:create_term_buf(_type, size) abort
set splitbelow
set splitright
if a:_type ==# 'v'
vnew
else
new
endif
execute 'resize ' . a:size
endfunction
" For delimitMate
let b:delimitMate_matchpairs = "(:),[:],{:}"

View file

@ -0,0 +1 @@
set commentstring=#\ %s

View file

@ -0,0 +1,3 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r

View file

@ -0,0 +1,6 @@
" let the initial folding state be that all folds are closed.
set foldlevel=0
" Use nvim-treesitter for folding
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()

View file

@ -0,0 +1,12 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
nnoremap <buffer><silent> <F9> :luafile %<CR>
" For delimitMate
let b:delimitMate_matchpairs = "(:),[:],{:}"
" Use nvim-treesitter for folding
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()

View file

@ -0,0 +1,69 @@
set concealcursor=c
set synmaxcol=3000 " For long Chinese paragraphs
set wrap
" Fix minor issue with footnote, see https://github.com/vim-pandoc/vim-markdownfootnotes/issues/22
if exists(':FootnoteNumber')
nnoremap <buffer><silent> ^^ :<C-U>call markdownfootnotes#VimFootnotes('i')<CR>
inoremap <buffer><silent> ^^ <C-O>:<C-U>call markdownfootnotes#VimFootnotes('i')<CR>
imap <buffer> <silent> @@ <Plug>ReturnFromFootnote
nmap <buffer> <silent> @@ <Plug>ReturnFromFootnote
endif
" Text objects for Markdown code blocks.
xnoremap <buffer><silent> ic :<C-U>call text_obj#MdCodeBlock('i')<CR>
xnoremap <buffer><silent> ac :<C-U>call text_obj#MdCodeBlock('a')<CR>
onoremap <buffer><silent> ic :<C-U>call text_obj#MdCodeBlock('i')<CR>
onoremap <buffer><silent> ac :<C-U>call text_obj#MdCodeBlock('a')<CR>
" Use + to turn several lines to an unordered list.
" Ref: https://vi.stackexchange.com/q/5495/15292 and https://stackoverflow.com/q/42438795/6064933.
nnoremap <buffer><silent> + :set operatorfunc=AddListSymbol<CR>g@
xnoremap <buffer><silent> + :<C-U> call AddListSymbol(visualmode(), 1)<CR>
function! AddListSymbol(type, ...) abort
if a:0
let line_start = line("'<")
let line_end = line("'>")
else
let line_start = line("'[")
let line_end = line("']")
endif
" add list symbol to each line
for line in range(line_start, line_end)
let text = getline(line)
let l:end = matchend(text, '^\s*')
if l:end == 0
let new_text = '+ ' . text
else
let new_text = text[0 : l:end-1] . ' + ' . text[l:end :]
endif
call setline(line, new_text)
endfor
endfunction
" Add hard line breaks for Markdown
nnoremap <buffer><silent> \ :set operatorfunc=AddLineBreak<CR>g@
xnoremap <buffer><silent> \ :<C-U> call AddLineBreak(visualmode(), 1)<CR>
function! AddLineBreak(type, ...) abort
if a:0
let line_start = line("'<")
let line_end = line("'>")
else
let line_start = line("'[")
let line_end = line("']")
endif
for line in range(line_start, line_end)
let text = getline(line)
" add backslash to each line
let new_text = text . "\\"
call setline(line, new_text)
endfor
endfunction

View file

@ -0,0 +1,21 @@
if exists(':AsyncRun')
nnoremap <buffer><silent> <F9> :<C-U>AsyncRun python -u "%"<CR>
endif
" Do not wrap Python source code.
set nowrap
set sidescroll=5
set sidescrolloff=2
set colorcolumn=100
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " number of spaces to use for autoindent
set expandtab " expand tab to spaces so that tabs are spaces
" For delimitMate
let b:delimitMate_matchpairs = "(:),[:],{:}"
" Use nvim-treesitter for folding
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()

View file

@ -0,0 +1,6 @@
" Set quickfix window height, see also https://github.com/lervag/vimtex/issues/1127
function! AdjustWindowHeight(minheight, maxheight)
execute max([a:minheight, min([line('$'), a:maxheight])]) . 'wincmd _'
endfunction
call AdjustWindowHeight(5, 15)

View file

@ -0,0 +1 @@
set commentstring=--\ %s

View file

@ -0,0 +1,2 @@
vim.o.textwidth = 120
vim.o.wrap = true

View file

@ -0,0 +1 @@
set colorcolumn=

View file

@ -0,0 +1,15 @@
" Disable inserting comment leader after hitting o or O or <Enter>
set formatoptions-=o
set formatoptions-=r
" Set the folding related options for vim script. Setting folding option in
" modeline is annoying in that the modeline get executed each time the window
" focus is lost (see
" https://github.com/tmux-plugins/vim-tmux-focus-events/issues/14)
set foldmethod=expr foldexpr=utils#VimFolds(v:lnum) foldtext=utils#MyFoldText()
" Use :help command for keyword when pressing `K` in vim file,
" see `:h K` and https://stackoverflow.com/q/15867323/6064933
set keywordprg=:help
nnoremap <buffer><silent> <F9> :source %<CR>

View file

@ -0,0 +1,4 @@
" Turn off syntax highlighting for large YAML files.
if line('$') > 500
setlocal syntax=OFF
endif

View file

@ -0,0 +1,30 @@
function! buf_utils#GoToBuffer(count, direction) abort
if a:count == 0
if a:direction ==# 'forward'
bnext
elseif a:direction ==# 'backward'
bprevious
else
echoerr 'Bad argument ' a:direction
endif
return
endif
" Check the validity of buffer number.
if index(s:GetBufNums(), a:count) == -1
" Using `lua vim.notify('invalid bufnr: ' .. a:count)` won't work, because
" we are essentially mixing Lua and vim script. We need to make sure that
" args inside vim.notify() are valid vim values. The conversion from vim
" value to lua value will be done by Nvim. See also https://github.com/neovim/neovim/pull/11338.
call v:lua.vim.notify('Invalid bufnr: ' . a:count, 4, {'title': 'nvim-config'})
return
endif
" Do not use {count} for gB (it is less useful)
if a:direction ==# 'forward'
silent execute('buffer' . a:count)
endif
endfunction
function! s:GetBufNums() abort
return map(copy(getbufinfo({'buflisted':1})), 'v:val.bufnr')
endfunction

View file

@ -0,0 +1,86 @@
function! text_obj#URL() abort
if match(&runtimepath, 'vim-highlighturl') != -1
" Note that we use https://github.com/itchyny/vim-highlighturl to get the URL pattern.
let url_pattern = highlighturl#default_pattern()
else
let url_pattern = expand('<cfile>')
" Since expand('<cfile>') also works for normal words, we need to check if
" this is really URL using heuristics, e.g., URL length.
if len(url_pattern) <= 10
return
endif
endif
" We need to find all possible URL on this line and their start, end index.
" Then find where current cursor is, and decide if cursor is on one of the
" URLs.
let line_text = getline('.')
let url_infos = []
let [_url, _idx_start, _idx_end] = matchstrpos(line_text, url_pattern)
while _url !=# ''
let url_infos += [[_url, _idx_start+1, _idx_end]]
let [_url, _idx_start, _idx_end] = matchstrpos(line_text, url_pattern, _idx_end)
endwhile
" echo url_infos
" If no URL is found, do nothing.
if len(url_infos) == 0
return
endif
let [start_col, end_col] = [-1, -1]
" If URL is found, find if cursor is on it.
let [buf_num, cur_row, cur_col] = getcurpos()[0:2]
for url_info in url_infos
" echo url_info
let [_url, _idx_start, _idx_end] = url_info
if cur_col >= _idx_start && cur_col <= _idx_end
let start_col = _idx_start
let end_col = _idx_end
break
endif
endfor
" Cursor is not on a URL, do nothing.
if start_col == -1
return
endif
" Now set the '< and '> mark
call setpos("'<", [buf_num, cur_row, start_col, 0])
call setpos("'>", [buf_num, cur_row, end_col, 0])
normal! gv
endfunction
function! text_obj#MdCodeBlock(type) abort
" the parameter type specify whether it is inner text objects or around
" text objects.
" Move the cursor to the end of line in case that cursor is on the opening
" of a code block. Actually, there are still issues if the cursor is on the
" closing of a code block. In this case, the start row of code blocks would
" be wrong. Unless we can match code blocks, it not easy to fix this.
normal! $
let start_row = searchpos('\s*```', 'bnW')[0]
let end_row = searchpos('\s*```', 'nW')[0]
let buf_num = bufnr()
if a:type ==# 'i'
let start_row += 1
let end_row -= 1
endif
" echo a:type start_row end_row
call setpos("'<", [buf_num, start_row, 1, 0])
call setpos("'>", [buf_num, end_row, 1, 0])
execute 'normal! `<V`>'
endfunction
function! text_obj#Buffer() abort
let buf_num = bufnr()
call setpos("'<", [buf_num, 1, 1, 0])
call setpos("'>", [buf_num, line('$'), 1, 0])
execute 'normal! `<V`>'
endfunction

View file

@ -0,0 +1,194 @@
" Create command alias safely, see https://stackoverflow.com/q/3878692/6064933
" The following two functions are taken from answer below on SO:
" https://stackoverflow.com/a/10708687/6064933
function! utils#Cabbrev(key, value) abort
execute printf('cabbrev <expr> %s (getcmdtype() == ":" && getcmdpos() <= %d) ? %s : %s',
\ a:key, 1+len(a:key), <SID>Single_quote(a:value), <SID>Single_quote(a:key))
endfunction
function! s:Single_quote(str) abort
return "'" . substitute(copy(a:str), "'", "''", 'g') . "'"
endfunction
" Check the syntax group in the current cursor position, see
" https://stackoverflow.com/q/9464844/6064933 and
" https://jordanelver.co.uk/blog/2015/05/27/working-with-vim-colorschemes/
function! utils#SynGroup() abort
if !exists('*synstack')
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunction
" Check if a colorscheme exists in runtimepath.
" The following two functions are inspired by https://stackoverflow.com/a/5703164/6064933.
function! utils#HasColorscheme(name) abort
let l:pat = printf('colors/%s.vim', a:name)
return !empty(globpath(&runtimepath, l:pat))
endfunction
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
function! utils#VimFolds(lnum) abort
" get content of current line and the line below
let l:cur_line = getline(a:lnum)
let l:next_line = getline(a:lnum+1)
if l:cur_line =~# '^"{'
return '>' . (matchend(l:cur_line, '"{*') - 1)
endif
if l:cur_line ==# '' && (matchend(l:next_line, '"{*') - 1) == 1
return 0
endif
return '='
endfunction
" Custom fold text, adapted from https://vi.stackexchange.com/a/3818/15292
" and https://vi.stackexchange.com/a/6608/15292
function! utils#MyFoldText() abort
let l:line = getline(v:foldstart)
let l:fold_line_num = v:foldend - v:foldstart
let l:fold_text = substitute(l:line, '^"{\+', '', 'g')
let l:fill_char_num = &textwidth - len(l:fold_text) - len(l:fold_line_num) - 10
return printf('+%s%s %s (%s L)', repeat('-', 4), l:fold_text, repeat('-', l:fill_char_num), l:fold_line_num)
endfunction
" Toggle cursor column
function! utils#ToggleCursorCol() abort
if &cursorcolumn
set nocursorcolumn
echo 'cursorcolumn: OFF'
else
set cursorcolumn
echo 'cursorcolumn: ON'
endif
endfunction
function! utils#SwitchLine(src_line_idx, direction) abort
if a:direction ==# 'up'
if a:src_line_idx == 1
return
endif
move-2
elseif a:direction ==# 'down'
if a:src_line_idx == line('$')
return
endif
move+1
endif
endfunction
function! utils#MoveSelection(direction) abort
" only do this if previous mode is visual line mode. Once we press some keys in
" visual line mode, we will leave this mode. So the output of `mode()` will be
" `n` instead of `V`. We can use `visualmode()` instead to check the previous
" mode, see also https://stackoverflow.com/a/61486601/6064933
if visualmode() !=# 'V'
return
endif
let l:start_line = line("'<")
let l:end_line = line("'>")
let l:num_line = l:end_line - l:start_line + 1
if a:direction ==# 'up'
if l:start_line == 1
" we can also directly use `normal gv`, see https://stackoverflow.com/q/9724123/6064933
normal! gv
return
endif
silent execute printf('%s,%smove-2', l:start_line, l:end_line)
normal! gv
elseif a:direction ==# 'down'
if l:end_line == line('$')
normal! gv
return
endif
silent execute printf('%s,%smove+%s', l:start_line, l:end_line, l:num_line)
normal! gv
endif
endfunction
function! utils#Get_titlestr() abort
let l:title_str = ''
if g:is_linux
let l:title_str = hostname() . ' '
endif
let l:buf_path = expand('%:p:~')
let l:title_str = l:title_str . l:buf_path . ' '
if &buflisted && l:buf_path != ""
let l:title_str = l:title_str . strftime('%Y-%m-%d %H:%M:%S%z', getftime(expand('%')))
endif
return l:title_str
endfunction
" Output current time or unix timestamp in human-readable format.
function! utils#iso_time(timestamp) abort
" Get current datetime
if !a:timestamp
return strftime('%Y-%m-%d %H:%M:%S%z')
endif
" this timestamp in expressed in milliseconds
if len(a:timestamp) == 13
let l:timestamp = a:timestamp[:-4]
" this timestamp in expressed in microseconds
elseif len(a:timestamp) == 16
let l:timestamp = a:timestamp[:-7]
else
let l:timestamp = a:timestamp
endif
return strftime('%Y-%m-%d %H:%M:%S%z', l:timestamp)
endfunction
" Check if we are inside a Git repo.
function! utils#Inside_git_repo() abort
let res = system('git rev-parse --is-inside-work-tree')
if match(res, 'true') == -1
return v:false
else
" Manually trigger a special user autocmd InGitRepo (used lazyloading.
doautocmd User InGitRepo
return v:true
endif
endfunction
function! utils#GetGitBranch()
let l:res = systemlist('git rev-parse --abbrev-ref HEAD')[0]
if match(l:res, 'fatal') != -1
return ''
else
return l:res
endif
endfunction
" Redirect command output to a register for later processing.
" Ref: https://stackoverflow.com/q/2573021/6064933 and https://unix.stackexchange.com/q/8101/221410 .
function! utils#CaptureCommandOutput(command) abort
let l:tmp = @m
redir @m
silent! execute a:command
redir END
"create a scratch buffer for dumping the text, ref: https://vi.stackexchange.com/a/11311/15292.
tabnew | setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile
let l:lines = split(@m, '\n')
call nvim_buf_set_lines(0, 0, 0, 0, l:lines)
let @m = l:tmp
endfunction
" Edit all files matching the given patterns.
function! utils#MultiEdit(patterns) abort
for p in a:patterns
for f in glob(p, 0, 1)
execute 'edit ' . f
endfor
endfor
endfunction

View file

@ -0,0 +1,4 @@
augroup det_md
autocmd!
autocmd BufRead,BufNewFile *.pdc set filetype=markdown
augroup END

View file

@ -0,0 +1,4 @@
vim.g.catppuccin_flavour = "mocha"
require("catppuccin").setup()
vim.cmd([[colorscheme catppuccin]])

View file

@ -0,0 +1,6 @@
require("bqf").setup {
auto_resize_height = false,
preview = {
auto_preview = false,
},
}

View file

@ -0,0 +1,46 @@
require("bufferline").setup {
options = {
numbers = "buffer_id",
close_command = "bdelete! %d",
right_mouse_command = nil,
left_mouse_command = "buffer %d",
middle_mouse_command = nil,
indicator = {
icon = "", -- this should be omitted if indicator style is not 'icon'
style = "icon",
},
buffer_close_icon = "",
modified_icon = "",
close_icon = "",
left_trunc_marker = "",
right_trunc_marker = "",
max_name_length = 18,
max_prefix_length = 15,
tab_size = 10,
diagnostics = false,
custom_filter = function(bufnr)
-- if the result is false, this buffer will be shown, otherwise, this
-- buffer will be hidden.
-- filter out filetypes you don't want to see
local exclude_ft = { "qf", "fugitive", "git" }
local cur_ft = vim.bo[bufnr].filetype
local should_filter = vim.tbl_contains(exclude_ft, cur_ft)
if should_filter then
return false
end
return true
end,
show_buffer_icons = false,
show_buffer_close_icons = true,
show_close_icon = true,
show_tab_indicators = true,
persist_buffer_sort = true, -- whether or not custom sorted buffers should persist
separator_style = "bar",
enforce_regular_tabs = false,
always_show_bufferline = true,
sort_by = "id",
},
}

View file

@ -0,0 +1,19 @@
local cmp_ai = require('cmp_ai.config')
cmp_ai:setup({
max_lines = 100,
provider = 'Ollama',
provider_options = {
model = 'codellama:13b-code-q6_K',
},
notify = true,
notify_callback = function(msg)
vim.notify(msg)
end,
run_on_every_keystroke = true,
ignored_file_types = {
-- default is not to ignore
-- uncomment to ignore in lua:
-- lua = true
},
})

View file

@ -0,0 +1,75 @@
local api = vim.api
local keymap = vim.keymap
local dashboard = require("dashboard")
local conf = {}
conf.header = {
" ",
" ",
" ",
" ███╗ ██╗ ███████╗ ██████╗ ██╗ ██╗ ██╗ ███╗ ███╗",
" ████╗ ██║ ██╔════╝██╔═══██╗ ██║ ██║ ██║ ████╗ ████║",
" ██╔██╗ ██║ █████╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║",
" ██║╚██╗██║ ██╔══╝ ██║ ██║ ╚██╗ ██╔╝ ██║ ██║╚██╔╝██║",
" ██║ ╚████║ ███████╗╚██████╔╝ ╚████╔╝ ██║ ██║ ╚═╝ ██║",
" ╚═╝ ╚═══╝ ╚══════╝ ╚═════╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝",
" ",
" ",
" ",
" ",
}
conf.center = {
{
icon = "󰈞 ",
desc = "Find File ",
action = "Leaderf file --popup",
key = "<Leader> f f",
},
{
icon = "󰈢 ",
desc = "Recently opened files ",
action = "Leaderf mru --popup",
key = "<Leader> f r",
},
{
icon = "󰈬 ",
desc = "Project grep ",
action = "Leaderf rg --popup",
key = "<Leader> f g",
},
{
icon = "",
desc = "Open Nvim config ",
action = "tabnew $MYVIMRC | tcd %:p:h",
key = "<Leader> e v",
},
{
icon = "",
desc = "New file ",
action = "enew",
key = "e",
},
{
icon = "󰗼 ",
desc = "Quit Nvim ",
-- desc = "Quit Nvim ",
action = "qa",
key = "q",
},
}
dashboard.setup({
theme = 'doom',
shortcut_type = 'number',
config = conf
})
api.nvim_create_autocmd("FileType", {
pattern = "dashboard",
group = api.nvim_create_augroup("dashboard_enter", { clear = true }),
callback = function ()
keymap.set("n", "q", ":qa<CR>", { buffer = true, silent = true })
keymap.set("n", "e", ":enew<CR>", { buffer = true, silent = true })
end
})

View file

@ -0,0 +1 @@
require("fidget").setup {}

View file

@ -0,0 +1,11 @@
local keymap = vim.keymap
keymap.set("n", "<leader>gs", "<cmd>Git<cr>", { desc = "Git status" })
keymap.set("n", "<leader>gw", "<cmd>Gwrite<cr>", { desc = "Git add" })
keymap.set("n", "<leader>gc", "<cmd>Git commit<cr>", { desc = "Git commit" })
keymap.set("n", "<leader>gd", "<cmd>Gdiffsplit<cr>", { desc = "Git diff" })
keymap.set("n", "<leader>gpl", "<cmd>Git pull<cr>", { desc = "Git pull" })
keymap.set("n", "<leader>gpu", "<cmd>15 split|term git push<cr>", { desc = "Git push" })
-- convert git to Git in command line mode
vim.fn['utils#Cabbrev']('git', 'Git')

View file

@ -0,0 +1,37 @@
local keymap = vim.keymap
local gitlinker = require("gitlinker")
gitlinker.setup {
callbacks = {
["dev.azure.com"] = function(url_data)
vim.print(url_data)
local url = require"gitlinker.hosts".get_base_https_url(url_data)
if url_data.lstart then
if url_data.lend == nil then
url_data.lend = url_data.lstart
end
url = url .. "?path=/" .. url_data.file .. "&version=GC" .. url_data.rev .. "&line=" .. url_data.lstart .. "&lineEnd=" .. url_data.lend .. "&lineStartColumn=1" .. "&lineEndColumn=120"
end
return url
end
},
mappings = nil,
}
keymap.set({ "n", "v" }, "<leader>gl", function()
local mode = string.lower(vim.fn.mode())
gitlinker.get_buf_range_url(mode)
end, {
silent = true,
desc = "get git permlink",
})
keymap.set("n", "<leader>gb", function()
gitlinker.get_repo_url({
action_callback = gitlinker.actions.open_in_browser
})
end, {
silent = true,
desc = "browse repo in browser",
})

View file

@ -0,0 +1,57 @@
local gs = require("gitsigns")
gs.setup {
signs = {
add = { text = "+" },
change = { text = "~" },
delete = { text = "_" },
topdelete = { text = "" },
changedelete = { text = "" },
},
word_diff = true,
on_attach = function(bufnr)
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true, desc = "next hunk" })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true, desc = "previous hunk" })
-- Actions
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line { full = true }
end)
end,
}
vim.api.nvim_create_autocmd('ColorScheme', {
pattern = "*",
callback = function()
vim.cmd [[
hi GitSignsChangeInline gui=reverse
hi GitSignsAddInline gui=reverse
hi GitSignsDeleteInline gui=reverse
]]
end
})

View file

@ -0,0 +1,49 @@
local api = vim.api
local keymap = vim.keymap
local hlslens = require("hlslens")
hlslens.setup {
calm_down = true,
nearest_only = true,
}
local activate_hlslens = function(direction)
local cmd = string.format("normal! %s%szzzv", vim.v.count1, direction)
local status, msg = pcall(vim.cmd, cmd)
-- Deal with the case that there is no such pattern in current buffer.
if not status then
local start_idx, _ = string.find(msg, 'E486', 1, true)
local msg_part = string.sub(msg, start_idx)
api.nvim_err_writeln(msg_part)
return
end
hlslens.start()
end
keymap.set("n", "n", "", {
callback = function()
activate_hlslens("n")
end,
})
keymap.set("n", "N", "", {
callback = function()
activate_hlslens("N")
end,
})
keymap.set("n", "*", "", {
callback = function()
vim.fn.execute("normal! *N")
hlslens.start()
end,
})
keymap.set("n", "#", "", {
callback = function()
vim.fn.execute("normal! #N")
hlslens.start()
end,
})

View file

@ -0,0 +1,36 @@
local api = vim.api
local exclude_ft = { "help", "git", "markdown", "text", "gitconfig", "alpha", "dashboard" }
require("ibl").setup {
indent = {
-- -- U+2502 may also be a good choice, it will be on the middle of cursor.
-- -- U+250A is also a good choice
char = "",
},
scope = {
show_start = false,
show_end = false,
},
exclude = {
filetypes = exclude_ft,
buftypes = { "terminal" },
},
}
local gid = api.nvim_create_augroup("indent_blankline", { clear = true })
api.nvim_create_autocmd("InsertEnter", {
pattern = "*",
group = gid,
command = "IBLDisable",
})
api.nvim_create_autocmd("InsertLeave", {
pattern = "*",
group = gid,
callback = function()
if not vim.tbl_contains(exclude_ft, vim.bo.filetype) then
vim.cmd([[IBLEnable]])
end
end,
})

View file

@ -0,0 +1,273 @@
local fn = vim.fn
local api = vim.api
local keymap = vim.keymap
local lsp = vim.lsp
local diagnostic = vim.diagnostic
local utils = require("utils")
-- set quickfix list from diagnostics in a certain buffer, not the whole workspace
local set_qflist = function(buf_num, severity)
local diagnostics = nil
diagnostics = diagnostic.get(buf_num, { severity = severity })
local qf_items = diagnostic.toqflist(diagnostics)
vim.fn.setqflist({}, ' ', { title = 'Diagnostics', items = qf_items })
-- open quickfix by default
vim.cmd[[copen]]
end
local custom_attach = function(client, bufnr)
-- Mappings.
local map = function(mode, l, r, opts)
opts = opts or {}
opts.silent = true
opts.buffer = bufnr
keymap.set(mode, l, r, opts)
end
map("n", "gd", vim.lsp.buf.definition, { desc = "go to definition" })
map("n", "<C-]>", vim.lsp.buf.definition)
map("n", "K", vim.lsp.buf.hover)
map("n", "<C-k>", vim.lsp.buf.signature_help)
map("n", "<space>rn", vim.lsp.buf.rename, { desc = "varialbe rename" })
map("n", "gr", vim.lsp.buf.references, { desc = "show references" })
map("n", "[d", diagnostic.goto_prev, { desc = "previous diagnostic" })
map("n", "]d", diagnostic.goto_next, { desc = "next diagnostic" })
-- this puts diagnostics from opened files to quickfix
map("n", "<space>qw", diagnostic.setqflist, { desc = "put window diagnostics to qf" })
-- this puts diagnostics from current buffer to quickfix
map("n", "<space>qb", function() set_qflist(bufnr) end, { desc = "put buffer diagnostics to qf" })
map("n", "<space>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
map("n", "<space>wl", function()
inspect(vim.lsp.buf.list_workspace_folders())
end, { desc = "list workspace folder" })
-- Set some key bindings conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then
map("n", "<space>f", vim.lsp.buf.format, { desc = "format code" })
end
api.nvim_create_autocmd("CursorHold", {
buffer = bufnr,
callback = function()
local float_opts = {
focusable = false,
close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" },
border = "rounded",
source = "always", -- show source in diagnostic popup window
prefix = " ",
}
if not vim.b.diagnostics_pos then
vim.b.diagnostics_pos = { nil, nil }
end
local cursor_pos = api.nvim_win_get_cursor(0)
if (cursor_pos[1] ~= vim.b.diagnostics_pos[1] or cursor_pos[2] ~= vim.b.diagnostics_pos[2])
and #diagnostic.get() > 0
then
diagnostic.open_float(nil, float_opts)
end
vim.b.diagnostics_pos = cursor_pos
end,
})
-- The blow command will highlight the current variable and its usages in the buffer.
if client.server_capabilities.documentHighlightProvider then
vim.cmd([[
hi! link LspReferenceRead Visual
hi! link LspReferenceText Visual
hi! link LspReferenceWrite Visual
]])
local gid = api.nvim_create_augroup("lsp_document_highlight", { clear = true })
api.nvim_create_autocmd("CursorHold" , {
group = gid,
buffer = bufnr,
callback = function ()
lsp.buf.document_highlight()
end
})
api.nvim_create_autocmd("CursorMoved" , {
group = gid,
buffer = bufnr,
callback = function ()
lsp.buf.clear_references()
end
})
end
if vim.g.logging_level == "debug" then
local msg = string.format("Language server %s started!", client.name)
vim.notify(msg, vim.log.levels.DEBUG, { title = "Nvim-config" })
end
end
local capabilities = require('cmp_nvim_lsp').default_capabilities()
local lspconfig = require("lspconfig")
if utils.executable("pylsp") then
local venv_path = os.getenv('VIRTUAL_ENV')
local py_path = nil
-- decide which python executable to use for mypy
if venv_path ~= nil then
py_path = venv_path .. "/bin/python3"
else
py_path = vim.g.python3_host_prog
end
lspconfig.pylsp.setup {
on_attach = custom_attach,
settings = {
pylsp = {
plugins = {
-- formatter options
black = { enabled = true },
autopep8 = { enabled = false },
yapf = { enabled = false },
-- linter options
pylint = { enabled = true, executable = "pylint" },
ruff = { enabled = false },
pyflakes = { enabled = false },
pycodestyle = { enabled = false },
-- type checker
pylsp_mypy = {
enabled = true,
overrides = { "--python-executable", py_path, true },
report_progress = true,
live_mode = false
},
-- auto-completion options
jedi_completion = { fuzzy = true },
-- import sorting
isort = { enabled = true },
},
},
},
flags = {
debounce_text_changes = 200,
},
capabilities = capabilities,
}
else
--vim.notify("pylsp not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
-- if utils.executable('pyright') then
-- lspconfig.pyright.setup{
-- on_attach = custom_attach,
-- capabilities = capabilities
-- }
-- else
-- vim.notify("pyright not found!", vim.log.levels.WARN, {title = 'Nvim-config'})
-- end
if utils.executable("ltex-ls") then
lspconfig.ltex.setup {
on_attach = custom_attach,
cmd = { "ltex-ls" },
filetypes = { "text", "plaintex", "tex", "markdown" },
settings = {
ltex = {
language = "en"
},
},
flags = { debounce_text_changes = 300 },
}
end
if utils.executable("clangd") then
lspconfig.clangd.setup {
on_attach = custom_attach,
capabilities = capabilities,
filetypes = { "c", "cpp", "cc" },
flags = {
debounce_text_changes = 500,
},
}
end
-- set up vim-language-server
if utils.executable("vim-language-server") then
lspconfig.vimls.setup {
on_attach = custom_attach,
flags = {
debounce_text_changes = 500,
},
capabilities = capabilities,
}
else
-- vim.notify("vim-language-server not found!", vim.log.levels.WARN, { title = "Nvim-config" })
end
-- set up bash-language-server
if utils.executable("bash-language-server") then
lspconfig.bashls.setup {
on_attach = custom_attach,
capabilities = capabilities,
}
end
if utils.executable("lua-language-server") then
-- settings for lua-language-server can be found on https://github.com/LuaLS/lua-language-server/wiki/Settings .
lspconfig.lua_ls.setup {
on_attach = custom_attach,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files,
-- see also https://github.com/LuaLS/lua-language-server/wiki/Libraries#link-to-workspace .
-- Lua-dev.nvim also has similar settings for lua ls, https://github.com/folke/neodev.nvim/blob/main/lua/neodev/luals.lua .
library = {
vim.env.VIMRUNTIME,
fn.stdpath("config"),
},
maxPreload = 2000,
preloadFileSize = 50000,
},
},
},
capabilities = capabilities,
}
end
-- Change diagnostic signs.
fn.sign_define("DiagnosticSignError", { text = '🆇', texthl = "DiagnosticSignError" })
fn.sign_define("DiagnosticSignWarn", { text = '⚠️', texthl = "DiagnosticSignWarn" })
fn.sign_define("DiagnosticSignInfo", { text = '', texthl = "DiagnosticSignInfo" })
fn.sign_define("DiagnosticSignHint", { text = '', texthl = "DiagnosticSignHint" })
-- global config for diagnostic
diagnostic.config {
underline = false,
virtual_text = false,
signs = true,
severity_sort = true,
}
-- lsp.handlers["textDocument/publishDiagnostics"] = lsp.with(lsp.diagnostic.on_publish_diagnostics, {
-- underline = false,
-- virtual_text = false,
-- signs = true,
-- update_in_insert = false,
-- })
-- Change border of documentation hover window, See https://github.com/neovim/neovim/pull/13998.
lsp.handlers["textDocument/hover"] = lsp.with(vim.lsp.handlers.hover, {
border = "rounded",
})

View file

@ -0,0 +1,92 @@
-- Setup nvim-cmp.
local cmp = require("cmp")
local lspkind = require("lspkind")
cmp.setup {
mapping = cmp.mapping.preset.insert {
["<Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
["<S-Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
["<CR>"] = cmp.mapping.confirm { select = true },
["<C-e>"] = cmp.mapping.abort(),
["<Esc>"] = cmp.mapping.close(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
['<C-x>'] = cmp.mapping(
cmp.mapping.complete({
config = {
sources = cmp.config.sources({
{ name = 'cmp_ai' },
}),
},
}),
{ 'i' }
),
},
sources = {
{ name = "nvim_lsp" }, -- For nvim-lsp
{ name = "path" }, -- for path completion
{ name = "buffer", keyword_length = 2 }, -- for buffer word completion
{ name = "emoji", insert = true }, -- emoji completion
},
completion = {
keyword_length = 1,
completeopt = "menu,noselect",
},
view = {
entries = "custom",
},
formatting = {
format = lspkind.cmp_format {
mode = "symbol_text",
menu = {
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
path = "[Path]",
buffer = "[Buffer]",
emoji = "[Emoji]",
omni = "[Omni]",
},
},
},
}
cmp.setup.filetype("tex", {
sources = {
{ name = "omni" },
{ name = "buffer", keyword_length = 2 }, -- for buffer word completion
{ name = "path" }, -- for path completion
},
})
-- see https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#how-to-add-visual-studio-code-dark-theme-colors-to-the-menu
vim.cmd([[
highlight! link CmpItemMenu Comment
" gray
highlight! CmpItemAbbrDeprecated guibg=NONE gui=strikethrough guifg=#808080
" blue
highlight! CmpItemAbbrMatch guibg=NONE guifg=#569CD6
highlight! CmpItemAbbrMatchFuzzy guibg=NONE guifg=#569CD6
" light blue
highlight! CmpItemKindVariable guibg=NONE guifg=#9CDCFE
highlight! CmpItemKindInterface guibg=NONE guifg=#9CDCFE
highlight! CmpItemKindText guibg=NONE guifg=#9CDCFE
" pink
highlight! CmpItemKindFunction guibg=NONE guifg=#C586C0
highlight! CmpItemKindMethod guibg=NONE guifg=#C586C0
" front
highlight! CmpItemKindKeyword guibg=NONE guifg=#D4D4D4
highlight! CmpItemKindProperty guibg=NONE guifg=#D4D4D4
highlight! CmpItemKindUnit guibg=NONE guifg=#D4D4D4
]])

View file

@ -0,0 +1,10 @@
local nvim_notify = require("notify")
nvim_notify.setup {
-- Animation style
stages = "fade_in_slide_out",
-- Default timeout for notifications
timeout = 1500,
background_colour = "#2E3440",
}
vim.notify = nvim_notify

View file

@ -0,0 +1,108 @@
local keymap = vim.keymap
local nvim_tree = require("nvim-tree")
nvim_tree.setup {
auto_reload_on_write = true,
disable_netrw = false,
hijack_netrw = true,
hijack_cursor = false,
hijack_unnamed_buffer_when_opening = false,
open_on_tab = false,
sort_by = "name",
update_cwd = false,
view = {
width = 30,
side = "left",
preserve_window_proportions = false,
number = false,
relativenumber = false,
signcolumn = "yes",
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "",
edge = "",
none = " ",
},
},
icons = {
webdev_colors = true,
},
},
hijack_directories = {
enable = true,
auto_open = true,
},
update_focused_file = {
enable = false,
update_cwd = false,
ignore_list = {},
},
system_open = {
cmd = "",
args = {},
},
diagnostics = {
enable = false,
show_on_dirs = false,
icons = {
hint = "",
info = "",
warning = "",
error = "",
},
},
filters = {
dotfiles = false,
custom = {},
exclude = {},
},
git = {
enable = true,
ignore = true,
timeout = 400,
},
actions = {
use_system_clipboard = true,
change_dir = {
enable = true,
global = false,
restrict_above_cwd = false,
},
open_file = {
quit_on_open = false,
resize_window = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = { "notify", "qf", "diff", "fugitive", "fugitiveblame" },
buftype = { "nofile", "terminal", "help" },
},
},
},
},
trash = {
cmd = "trash",
require_confirm = true,
},
log = {
enable = false,
truncate = false,
types = {
all = false,
config = false,
copy_paste = false,
diagnostics = false,
git = false,
profile = false,
},
},
}
keymap.set("n", "<space>s", require("nvim-tree.api").tree.toggle, {
silent = true,
desc = "toggle nvim-tree",
})

View file

@ -0,0 +1,28 @@
local keymap = vim.keymap
local hop = require("hop")
hop.setup {
case_insensitive = true,
char2_fallback_key = "<CR>",
quit_key = "<Esc>",
match_mappings = { "zh_sc" }
}
keymap.set({ "n", "v", "o" }, "f", "", {
silent = true,
noremap = true,
callback = function()
hop.hint_char2()
end,
desc = "nvim-hop char2",
})
vim.api.nvim_create_autocmd("ColorScheme", {
pattern = "*",
callback = function()
vim.cmd([[
hi HopNextKey cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
hi HopNextKey1 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
hi HopNextKey2 cterm=bold ctermfg=176 gui=bold guibg=#ff00ff guifg=#ffffff
]])
end
})

View file

@ -0,0 +1,197 @@
local fn = vim.fn
local function spell()
if vim.o.spell then
return string.format("[SPELL]")
end
return ""
end
--- show indicator for Chinese IME
local function ime_state()
if vim.g.is_mac then
-- ref: https://github.com/vim-airline/vim-airline/blob/master/autoload/airline/extensions/xkblayout.vim#L11
local layout = fn.libcall(vim.g.XkbSwitchLib, "Xkb_Switch_getXkbLayout", "")
-- We can use `xkbswitch -g` on the command line to get current mode.
-- mode for macOS builtin pinyin IME: com.apple.inputmethod.SCIM.ITABC
-- mode for Rime: im.rime.inputmethod.Squirrel.Rime
local res = fn.match(layout, [[\v(Squirrel\.Rime|SCIM.ITABC)]])
if res ~= -1 then
return "[CN]"
end
end
return ""
end
local function trailing_space()
if not vim.o.modifiable then
return ""
end
local line_num = nil
for i = 1, fn.line("$") do
local linetext = fn.getline(i)
-- To prevent invalid escape error, we wrap the regex string with `[[]]`.
local idx = fn.match(linetext, [[\v\s+$]])
if idx ~= -1 then
line_num = i
break
end
end
local msg = ""
if line_num ~= nil then
msg = string.format("[%d]trailing", line_num)
end
return msg
end
local function mixed_indent()
if not vim.o.modifiable then
return ""
end
local space_pat = [[\v^ +]]
local tab_pat = [[\v^\t+]]
local space_indent = fn.search(space_pat, "nwc")
local tab_indent = fn.search(tab_pat, "nwc")
local mixed = (space_indent > 0 and tab_indent > 0)
local mixed_same_line
if not mixed then
mixed_same_line = fn.search([[\v^(\t+ | +\t)]], "nwc")
mixed = mixed_same_line > 0
end
if not mixed then
return ""
end
if mixed_same_line ~= nil and mixed_same_line > 0 then
return "MI:" .. mixed_same_line
end
local space_indent_cnt = fn.searchcount({ pattern = space_pat, max_count = 1e3 }).total
local tab_indent_cnt = fn.searchcount({ pattern = tab_pat, max_count = 1e3 }).total
if space_indent_cnt > tab_indent_cnt then
return "MI:" .. tab_indent
else
return "MI:" .. space_indent
end
end
local diff = function()
local git_status = vim.b.gitsigns_status_dict
if git_status == nil then
return
end
local modify_num = git_status.changed
local remove_num = git_status.removed
local add_num = git_status.added
local info = { added = add_num, modified = modify_num, removed = remove_num }
-- vim.print(info)
return info
end
local virtual_env = function()
-- only show virtual env for Python
if vim.bo.filetype ~= 'python' then
return ""
end
local conda_env = os.getenv('CONDA_DEFAULT_ENV')
local venv_path = os.getenv('VIRTUAL_ENV')
if venv_path == nil then
if conda_env == nil then
return ""
else
return string.format(" %s (conda)", conda_env)
end
else
local venv_name = vim.fn.fnamemodify(venv_path, ':t')
return string.format(" %s (venv)", venv_name)
end
end
require("lualine").setup {
options = {
icons_enabled = true,
theme = "auto",
-- component_separators = { left = "", right = "" },
-- section_separators = { left = "", right = "" },
section_separators = "",
component_separators = "",
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = {
"branch",
{
"diff",
source = diff,
},
{
virtual_env,
color = { fg = 'black', bg = "#F1CA81" }
}
},
lualine_c = {
"filename",
{
ime_state,
color = { fg = "black", bg = "#f46868" },
},
{
spell,
color = { fg = "black", bg = "#a7c080" },
},
{
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = {error = '🆇 ', warn = '⚠️ ', info = ' ', hint = ''},
},
},
lualine_x = {
"encoding",
{
"fileformat",
symbols = {
unix = "unix",
dos = "win",
mac = "mac",
},
},
"filetype",
},
lualine_y = {
"location",
},
lualine_z = {
{
trailing_space,
color = "WarningMsg",
},
{
mixed_indent,
color = "WarningMsg",
},
},
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { "filename" },
lualine_x = { "location" },
lualine_y = {},
lualine_z = {},
},
tabline = {},
extensions = { "quickfix", "fugitive", "nvim-tree" },
}

View file

@ -0,0 +1,8 @@
require("nvim-treesitter.configs").setup {
ensure_installed = {},
ignore_install = {}, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
disable = { 'help' }, -- list of language that will be disabled
},
}

View file

@ -0,0 +1,60 @@
require("which-key").setup {
plugins = {
marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
spelling = {
enabled = true, -- enabling this will show WhichKey when pressing z= to select spelling suggestions
suggestions = 9, -- how many suggestions should be shown in the list?
},
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
-- No actual key bindings are created
presets = {
operators = true, -- adds help for operators like d, y, ... and registers them for motion / text object completion
motions = true, -- adds help for motions
text_objects = true, -- help for text objects triggered after entering an operator
windows = true, -- default bindings on <c-w>
nav = true, -- misc bindings to work with windows
z = true, -- bindings for folds, spelling and others prefixed with z
g = true, -- bindings for prefixed with g
},
},
-- add operators that will trigger motion and text object completion
-- to enable all native operators, set the preset / operators plugin above
operators = { gc = "Comments" },
key_labels = {
-- override the label used to display some keys. It doesn't effect WK in any other way.
-- For example:
-- ["<space>"] = "SPC",
-- ["<cr>"] = "RET",
-- ["<tab>"] = "TAB",
},
icons = {
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
separator = "", -- symbol used between a key and it's label
group = "+", -- symbol prepended to a group
},
window = {
border = "none", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = { 0, 0, 0, 0 }, -- extra window margin [top, right, bottom, left]
padding = { 1, 0, 1, 0 }, -- extra window padding [top, right, bottom, left]
},
layout = {
height = { min = 1, max = 25 }, -- min and max height of the columns
width = { min = 20, max = 50 }, -- min and max width of the columns
spacing = 1, -- spacing between columns
align = "center", -- align columns left, center or right
},
ignore_missing = false, -- enable this to hide mappings for which you didn't specify a label
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ " }, -- hide mapping boilerplate
show_help = true, -- show help message on the command line when the popup is visible
triggers = "auto", -- automatically setup triggers
-- triggers = {"<leader>"} -- or specify a list manually
triggers_blacklist = {
-- list of mode / prefixes that should never be hooked by WhichKey
-- this is mostly relevant for key maps that start with a native binding
-- most people should not need to change this
n = { "o", "O" },
},
}

View file

@ -0,0 +1,13 @@
require("yanky").setup({
ring = {
history_length = 50,
storage = "memory",
},
preserve_cursor_position = {
enabled = false,
},
})
-- cycle through the yank history, only work after paste
vim.keymap.set("n", "[y", "<Plug>(YankyCycleForward)")
vim.keymap.set("n", "]y", "<Plug>(YankyCycleBackward)")

View file

@ -0,0 +1,15 @@
require("zen-mode").setup {
window = {
backdrop = 0.8, -- shade the backdrop of the Zen window. Set to 1 to keep the same as Normal
width = 120,
options = {
-- signcolumn = "no", -- disable signcolumn
-- number = false, -- disable number column
-- relativenumber = false, -- disable relative numbers
cursorline = false, -- disable cursorline
cursorcolumn = false, -- disable cursor column
foldcolumn = "0", -- disable fold column
list = false, -- disable whitespace characters
},
},
}

View file

@ -0,0 +1,105 @@
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_autocmd({ "BufRead" }, {
pattern = "*",
group = api.nvim_create_augroup("non_utf8_file", { clear = true }),
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`
local yank_group = api.nvim_create_augroup("highlight_yank", { clear = true })
api.nvim_create_autocmd({ "TextYankPost" }, {
pattern = "*",
group = yank_group,
callback = function()
vim.highlight.on_yank { higroup = "YankColor", timeout = 300 }
end,
})
api.nvim_create_autocmd({ "CursorMoved" }, {
pattern = "*",
group = yank_group,
callback = function()
vim.g.current_cursor_pos = vim.fn.getcurpos()
end,
})
api.nvim_create_autocmd("TextYankPost", {
pattern = "*",
group = yank_group,
callback = function(ev)
if vim.v.event.operator == 'y' then
vim.fn.setpos('.', vim.g.current_cursor_pos)
end
end,
})
-- Auto-create dir when saving a file, in case some intermediate directory does not exist
api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = "*",
group = api.nvim_create_augroup("auto_create_dir", { clear = true }),
callback = function(ctx)
local dir = fn.fnamemodify(ctx.file, ":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,
})
-- Resize all windows when we resize the terminal
api.nvim_create_autocmd("VimResized", {
group = api.nvim_create_augroup("win_autoresize", { clear = true }),
desc = "autoresize windows on resizing operation",
command = "wincmd =",
})
local function open_nvim_tree(data)
-- check if buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
if not directory then
return
end
-- create a new, empty buffer
vim.cmd.enew()
-- wipe the directory buffer
vim.cmd.bw(data.buf)
-- open the tree
require("nvim-tree.api").tree.open()
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })

View file

@ -0,0 +1,231 @@
local keymap = vim.keymap
local api = vim.api
local uv = vim.uv
-- Save key strokes (now we do not need to press shift to enter command mode).
keymap.set({ "n", "x" }, ";", ":")
-- Turn the word under cursor to upper case
keymap.set("i", "<c-u>", "<Esc>viwUea")
-- Turn the current word into title case
keymap.set("i", "<c-t>", "<Esc>b~lea")
-- Paste non-linewise text above or below current line, see https://stackoverflow.com/a/1346777/6064933
keymap.set("n", "<leader>p", "m`o<ESC>p``", { desc = "paste below current line" })
keymap.set("n", "<leader>P", "m`O<ESC>p``", { desc = "paste above current line" })
-- Shortcut for faster save and quit
keymap.set("n", "<leader>w", "<cmd>update<cr>", { silent = true, desc = "save buffer" })
-- Saves the file if modified and quit
keymap.set("n", "<leader>q", "<cmd>x<cr>", { silent = true, desc = "quit current window" })
-- Quit all opened buffers
keymap.set("n", "<leader>Q", "<cmd>qa!<cr>", { silent = true, desc = "quit nvim" })
-- Navigation in the location and quickfix list
keymap.set("n", "[l", "<cmd>lprevious<cr>zv", { silent = true, desc = "previous location item" })
keymap.set("n", "]l", "<cmd>lnext<cr>zv", { silent = true, desc = "next location item" })
keymap.set("n", "[L", "<cmd>lfirst<cr>zv", { silent = true, desc = "first location item" })
keymap.set("n", "]L", "<cmd>llast<cr>zv", { silent = true, desc = "last location item" })
keymap.set("n", "[q", "<cmd>cprevious<cr>zv", { silent = true, desc = "previous qf item" })
keymap.set("n", "]q", "<cmd>cnext<cr>zv", { silent = true, desc = "next qf item" })
keymap.set("n", "[Q", "<cmd>cfirst<cr>zv", { silent = true, desc = "first qf item" })
keymap.set("n", "]Q", "<cmd>clast<cr>zv", { silent = true, desc = "last qf item" })
-- Close location list or quickfix list if they are present, see https://superuser.com/q/355325/736190
keymap.set("n", [[\x]], "<cmd>windo lclose <bar> cclose <cr>", {
silent = true,
desc = "close qf and location list",
})
-- Delete a buffer, without closing the window, see https://stackoverflow.com/q/4465095/6064933
keymap.set("n", [[\d]], "<cmd>bprevious <bar> bdelete #<cr>", {
silent = true,
desc = "delete buffer",
})
-- Insert a blank line below or above current line (do not move the cursor),
-- see https://stackoverflow.com/a/16136133/6064933
keymap.set("n", "<space>o", "printf('m`%so<ESC>``', v:count1)", {
expr = true,
desc = "insert line below",
})
keymap.set("n", "<space>O", "printf('m`%sO<ESC>``', v:count1)", {
expr = true,
desc = "insert line above",
})
-- Move the cursor based on physical lines, not the actual lines.
keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true })
keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true })
keymap.set("n", "^", "g^")
keymap.set("n", "0", "g0")
-- Do not include white space characters when using $ in visual mode,
-- see https://vi.stackexchange.com/q/12607/15292
keymap.set("x", "$", "g_")
-- Go to start or end of line easier
keymap.set({ "n", "x" }, "H", "^")
keymap.set({ "n", "x" }, "L", "g_")
-- Continuous visual shifting (does not exit Visual mode), `gv` means
-- to reselect previous visual area, see https://superuser.com/q/310417/736190
keymap.set("x", "<", "<gv")
keymap.set("x", ">", ">gv")
-- Edit and reload nvim config file quickly
keymap.set("n", "<leader>ev", "<cmd>tabnew $MYVIMRC <bar> tcd %:h<cr>", {
silent = true,
desc = "open init.lua",
})
keymap.set("n", "<leader>sv", function()
vim.cmd([[
update $MYVIMRC
source $MYVIMRC
]])
vim.notify("Nvim config successfully reloaded!", vim.log.levels.INFO, { title = "nvim-config" })
end, {
silent = true,
desc = "reload init.lua",
})
-- Reselect the text that has just been pasted, see also https://stackoverflow.com/a/4317090/6064933.
keymap.set("n", "<leader>v", "printf('`[%s`]', getregtype()[0])", {
expr = true,
desc = "reselect last pasted area",
})
-- Always use very magic mode for searching
-- keymap.set("n", "/", [[/\v]])
-- Search in selected region
-- xnoremap / :<C-U>call feedkeys('/\%>'.(line("'<")-1).'l\%<'.(line("'>")+1)."l")<CR>
-- Change current working directory locally and print cwd after that,
-- see https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file
keymap.set("n", "<leader>cd", "<cmd>lcd %:p:h<cr><cmd>pwd<cr>", { desc = "change cwd" })
-- Use Esc to quit builtin terminal
keymap.set("t", "<Esc>", [[<c-\><c-n>]])
-- Toggle spell checking
keymap.set("n", "<F11>", "<cmd>set spell!<cr>", { desc = "toggle spell" })
keymap.set("i", "<F11>", "<c-o><cmd>set spell!<cr>", { desc = "toggle spell" })
-- Change text without putting it into the vim register,
-- see https://stackoverflow.com/q/54255/6064933
keymap.set("n", "c", '"_c')
keymap.set("n", "C", '"_C')
keymap.set("n", "cc", '"_cc')
keymap.set("x", "c", '"_c')
-- Remove trailing whitespace characters
keymap.set("n", "<leader><space>", "<cmd>StripTrailingWhitespace<cr>", { desc = "remove trailing space" })
-- check the syntax group of current cursor position
keymap.set("n", "<leader>st", "<cmd>call utils#SynGroup()<cr>", { desc = "check syntax group" })
-- Copy entire buffer.
keymap.set("n", "<leader>y", "<cmd>%yank<cr>", { desc = "yank entire buffer" })
-- Toggle cursor column
keymap.set("n", "<leader>cl", "<cmd>call utils#ToggleCursorCol()<cr>", { desc = "toggle cursor column" })
-- Move current line up and down
keymap.set("n", "<A-k>", '<cmd>call utils#SwitchLine(line("."), "up")<cr>', { desc = "move line up" })
keymap.set("n", "<A-j>", '<cmd>call utils#SwitchLine(line("."), "down")<cr>', { desc = "move line down" })
-- Move current visual-line selection up and down
keymap.set("x", "<A-k>", '<cmd>call utils#MoveSelection("up")<cr>', { desc = "move selection up" })
keymap.set("x", "<A-j>", '<cmd>call utils#MoveSelection("down")<cr>', { desc = "move selection down" })
-- Replace visual selection with text in register, but not contaminate the register,
-- see also https://stackoverflow.com/q/10723700/6064933.
keymap.set("x", "p", '"_c<Esc>p')
-- Go to a certain buffer
keymap.set("n", "gb", '<cmd>call buf_utils#GoToBuffer(v:count, "forward")<cr>', {
desc = "go to buffer (forward)",
})
keymap.set("n", "gB", '<cmd>call buf_utils#GoToBuffer(v:count, "backward")<cr>', {
desc = "go to buffer (backward)",
})
-- Switch windows
keymap.set("n", "<c-left>", "<c-w>h")
keymap.set("n", "<c-Right>", "<C-W>l")
keymap.set("n", "<c-Up>", "<C-W>k")
keymap.set("n", "<c-Down>", "<C-W>j")
-- Text objects for URL
keymap.set({ "x", "o" }, "iu", "<cmd>call text_obj#URL()<cr>", { desc = "URL text object" })
-- Text objects for entire buffer
keymap.set({ "x", "o" }, "iB", ":<C-U>call text_obj#Buffer()<cr>", { desc = "buffer text object" })
-- Do not move my cursor when joining lines.
keymap.set("n", "J", function()
vim.cmd([[
normal! mzJ`z
delmarks z
]])
end, {
desc = "join lines without moving cursor",
})
keymap.set("n", "gJ", function()
-- we must use `normal!`, otherwise it will trigger recursive mapping
vim.cmd([[
normal! mzgJ`z
delmarks z
]])
end, {
desc = "join lines without moving cursor",
})
-- Break inserted text into smaller undo units when we insert some punctuation chars.
local undo_ch = { ",", ".", "!", "?", ";", ":" }
for _, ch in ipairs(undo_ch) do
keymap.set("i", ch, ch .. "<c-g>u")
end
-- insert semicolon in the end
keymap.set("i", "<A-;>", "<Esc>miA;<Esc>`ii")
-- Go to the beginning and end of current line in insert mode quickly
keymap.set("i", "<C-A>", "<HOME>")
keymap.set("i", "<C-E>", "<END>")
-- Go to beginning of command in command-line mode
keymap.set("c", "<C-A>", "<HOME>")
-- Delete the character to the right of the cursor
keymap.set("i", "<C-D>", "<DEL>")
keymap.set("n", "<leader>cb", function()
local cnt = 0
local blink_times = 7
local timer = uv.new_timer()
timer:start(0, 100, vim.schedule_wrap(function()
vim.cmd[[
set cursorcolumn!
set cursorline!
]]
if cnt == blink_times then
timer:close()
end
cnt = cnt + 1
end))
end)

View file

@ -0,0 +1 @@
require("config.lazy-nvim")

View file

@ -0,0 +1,59 @@
local fn = vim.fn
local M = {}
function M.executable(name)
if fn.executable(name) > 0 then
return true
end
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)
if res == 0 then
fn.mkdir(dir, "p")
end
end
--- Generate random integers in the range [Low, High], inclusive,
--- adapted from https://stackoverflow.com/a/12739441/6064933
--- @low: the lower value for this range
--- @high: the upper value for this range
function M.rand_int(low, high)
-- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933
math.randomseed(os.time())
return math.random(low, high)
end
--- Select a random element from a sequence/list.
--- @seq: the sequence to choose an element
function M.rand_element(seq)
local idx = M.rand_int(1, #seq)
return seq[idx]
end
function M.add_pack(name)
local status, error = pcall(vim.cmd, "packadd " .. name)
return status
end
return M

View file

@ -0,0 +1,50 @@
" Capture output from a command to register @m, to paste, press "mp
command! -nargs=1 -complete=command Redir call utils#CaptureCommandOutput(<q-args>)
command! -bar -bang -nargs=+ -complete=file Edit call utils#MultiEdit([<f-args>])
call utils#Cabbrev('edit', 'Edit')
call utils#Cabbrev('man', 'Man')
" show current date and time in human readable format
command! -nargs=? Datetime echo utils#iso_time(<q-args>)
" Convert Markdown file to PDF
command! ToPDF call s:md_to_pdf()
function! s:md_to_pdf() abort
" check if pandoc is installed
if executable('pandoc') != 1
echoerr "pandoc not found"
return
endif
let l:md_path = expand("%:p")
let l:pdf_path = fnamemodify(l:md_path, ":r") .. ".pdf"
let l:header_path = stdpath('config') . '/resources/head.tex'
let l:cmd = "pandoc --pdf-engine=xelatex --highlight-style=zenburn --table-of-content " .
\ "--include-in-header=" . l:header_path . " -V fontsize=10pt -V colorlinks -V toccolor=NavyBlue " .
\ "-V linkcolor=red -V urlcolor=teal -V filecolor=magenta -s " .
\ l:md_path . " -o " . l:pdf_path
if g:is_mac
let l:cmd = l:cmd . '&& open ' . l:pdf_path
endif
if g:is_win
let l:cmd = l:cmd . '&& start ' . l:pdf_path
endif
" echomsg l:cmd
let l:id = jobstart(l:cmd)
if l:id == 0 || l:id == -1
echoerr "Error running command"
endif
endfunction
" json format
command! -range JSONFormat <line1>,<line2>!python -m json.tool

View file

@ -0,0 +1,118 @@
command! LogAutocmds call s:log_autocmds_toggle()
function! s:log_autocmds_toggle()
augroup LogAutocmd
autocmd!
augroup END
let l:date = strftime('%F', localtime())
let s:activate = get(s:, 'activate', 0) ? 0 : 1
if !s:activate
call s:log('Stopped autocmd log (' . l:date . ')')
return
endif
call s:log('Started autocmd log (' . l:date . ')')
augroup LogAutocmd
for l:au in s:aulist
silent execute 'autocmd' l:au '* call s:log(''' . l:au . ''')'
endfor
augroup END
endfunction
function! s:log(message)
silent execute '!echo "'
\ . strftime('%T', localtime()) . ' - ' . a:message . '"'
\ '>> /tmp/vim_log_autocommands'
endfunction
" These are deliberately left out due to side effects
" - SourceCmd
" - FileAppendCmd
" - FileWriteCmd
" - BufWriteCmd
" - FileReadCmd
" - BufReadCmd
" - FuncUndefined
let s:aulist = [
\ 'BufNewFile',
\ 'BufReadPre',
\ 'BufRead',
\ 'BufReadPost',
\ 'FileReadPre',
\ 'FileReadPost',
\ 'FilterReadPre',
\ 'FilterReadPost',
\ 'StdinReadPre',
\ 'StdinReadPost',
\ 'BufWrite',
\ 'BufWritePre',
\ 'BufWritePost',
\ 'FileWritePre',
\ 'FileWritePost',
\ 'FileAppendPre',
\ 'FileAppendPost',
\ 'FilterWritePre',
\ 'FilterWritePost',
\ 'BufAdd',
\ 'BufCreate',
\ 'BufDelete',
\ 'BufWipeout',
\ 'BufFilePre',
\ 'BufFilePost',
\ 'BufEnter',
\ 'BufLeave',
\ 'BufWinEnter',
\ 'BufWinLeave',
\ 'BufUnload',
\ 'BufHidden',
\ 'BufNew',
\ 'SwapExists',
\ 'FileType',
\ 'Syntax',
\ 'EncodingChanged',
\ 'TermChanged',
\ 'VimEnter',
\ 'GUIEnter',
\ 'GUIFailed',
\ 'TermResponse',
\ 'QuitPre',
\ 'VimLeavePre',
\ 'VimLeave',
\ 'FileChangedShell',
\ 'FileChangedShellPost',
\ 'FileChangedRO',
\ 'ShellCmdPost',
\ 'ShellFilterPost',
\ 'CmdUndefined',
\ 'SpellFileMissing',
\ 'SourcePre',
\ 'VimResized',
\ 'FocusGained',
\ 'FocusLost',
\ 'CursorHold',
\ 'CursorHoldI',
\ 'CursorMoved',
\ 'CursorMovedI',
\ 'WinEnter',
\ 'WinLeave',
\ 'TabEnter',
\ 'TabLeave',
\ 'CmdwinEnter',
\ 'CmdwinLeave',
\ 'InsertEnter',
\ 'InsertChange',
\ 'InsertLeave',
\ 'InsertCharPre',
\ 'TextChanged',
\ 'TextChangedI',
\ 'ColorScheme',
\ 'RemoteReply',
\ 'QuickFixCmdPre',
\ 'QuickFixCmdPost',
\ 'SessionLoadPost',
\ 'MenuPopup',
\ 'CompleteDone',
\ 'User',
\ ]

View file

@ -0,0 +1,78 @@
\usepackage{fancyvrb,newverbs}
\usepackage[top=2cm, bottom=1.5cm, left=2cm, right=2cm]{geometry}
\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
\usepackage{hyperref}
% begin a new page for each section (first level header),
% we need to combine this with `-V subparagraph` when invoking pandc
% \usepackage{titlesec}
% \newcommand{\sectionbreak}{\clearpage}
% change background color for inline code in markdown files.
% The following code does not work well for long text, because the text will exceed the page boundary.
\definecolor{bgcolor}{HTML}{DADADA}
\let\oldtexttt\texttt
\renewcommand{\texttt}[1]{
\colorbox{bgcolor}{\oldtexttt{#1}}
}
% change style of quote, see also https://tex.stackexchange.com/a/436253/114857
\usepackage[most]{tcolorbox}
\definecolor{linequote}{RGB}{224,215,188}
\definecolor{backquote}{RGB}{249,245,233}
\definecolor{bordercolor}{RGB}{221,221,221}
% change left border: https://tex.stackexchange.com/a/475716/114857
% change left margin: https://tex.stackexchange.com/a/457936/114857
\newtcolorbox{myquote}[1][]{%
enhanced,
breakable,
size=minimal,
left=10pt,
top=5pt,
bottom=5pt,
frame hidden,
boxrule=0pt,
sharp corners=all,
colback=backquote,
borderline west={2pt}{0pt}{bordercolor},
#1
}
% redefine quote environment to use the myquote environment, see https://tex.stackexchange.com/a/337587/114857
\renewenvironment{quote}{\begin{myquote}}{\end{myquote}}
% start a new page after toc, we need to save the old command before defining
% new one to avoid recursive command calls,
% see https://tex.stackexchange.com/questions/47351/can-i-redefine-a-command-to-contain-itself
\let\oldtoc\tableofcontents
\renewcommand{\tableofcontents}{\oldtoc\newpage}
% fix header level issue
\usepackage{enumitem}
\setlistdepth{9}
\setlist[itemize,1]{label=$\bullet$}
\setlist[itemize,2]{label=$\bullet$}
\setlist[itemize,3]{label=$\bullet$}
\setlist[itemize,4]{label=$\bullet$}
\setlist[itemize,5]{label=$\bullet$}
\setlist[itemize,6]{label=$\bullet$}
\setlist[itemize,7]{label=$\bullet$}
\setlist[itemize,8]{label=$\bullet$}
\setlist[itemize,9]{label=$\bullet$}
\renewlist{itemize}{itemize}{9}
\setlist[enumerate,1]{label=$\arabic*.$}
\setlist[enumerate,2]{label=$\alph*.$}
\setlist[enumerate,3]{label=$\roman*.$}
\setlist[enumerate,4]{label=$\arabic*.$}
\setlist[enumerate,5]{label=$\alpha*$}
\setlist[enumerate,6]{label=$\roman*.$}
\setlist[enumerate,7]{label=$\arabic*.$}
\setlist[enumerate,8]{label=$\alph*.$}
\setlist[enumerate,9]{label=$\roman*.$}
\renewlist{enumerate}{enumerate}{9}

View file

@ -0,0 +1,123 @@
" Do not use smart case in command line mode, extracted from https://vi.stackexchange.com/a/16511/15292.
augroup dynamic_smartcase
autocmd!
autocmd CmdLineEnter : set nosmartcase
autocmd CmdLineLeave : set smartcase
augroup END
augroup term_settings
autocmd!
" Do not use number and relative number for terminal inside nvim
autocmd TermOpen * setlocal norelativenumber nonumber
" Go to insert mode by default to start typing command
autocmd TermOpen * startinsert
augroup END
" More accurate syntax highlighting? (see `:h syn-sync`)
augroup accurate_syn_highlight
autocmd!
autocmd BufEnter * :syntax sync fromstart
augroup END
" Return to last cursor position when opening a file
augroup resume_cursor_position
autocmd!
autocmd BufReadPost * call s:resume_cursor_position()
augroup END
" Only resume last cursor position when there is no go-to-line command (something like '+23').
function s:resume_cursor_position() abort
if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
let l:args = v:argv " command line arguments
for l:cur_arg in l:args
" Check if a go-to-line command is given.
let idx = match(l:cur_arg, '\v^\+(\d){1,}$')
if idx != -1
return
endif
endfor
execute "normal! g`\"zvzz"
endif
endfunction
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
" Define or override some highlight groups
augroup custom_highlight
autocmd!
autocmd ColorScheme * call s:custom_highlight()
augroup END
function! s:custom_highlight() abort
" For yank highlight
highlight YankColor ctermfg=59 ctermbg=41 guifg=#34495E guibg=#2ECC71
" For cursor colors
highlight Cursor cterm=bold gui=bold guibg=#00c918 guifg=black
highlight Cursor2 guifg=red guibg=red
" For floating windows border highlight
highlight FloatBorder guifg=LightGreen guibg=NONE
" highlight for matching parentheses
highlight MatchParen cterm=bold,underline gui=bold,underline
endfunction
augroup auto_close_win
autocmd!
autocmd BufEnter * call s:quit_current_win()
augroup END
" Quit Nvim if we have only one window, and its filetype match our pattern.
function! s:quit_current_win() abort
let l:quit_filetypes = ['qf', 'vista', 'NvimTree']
let l:should_quit = v:true
let l:tabwins = nvim_tabpage_list_wins(0)
for w in l:tabwins
let l:buf = nvim_win_get_buf(w)
let l:bf = getbufvar(l:buf, '&filetype')
if index(l:quit_filetypes, l:bf) == -1
let l:should_quit = v:false
endif
endfor
if l:should_quit
qall
endif
endfunction
augroup git_repo_check
autocmd!
autocmd VimEnter,DirChanged * call utils#Inside_git_repo()
augroup END
" ref: https://vi.stackexchange.com/a/169/15292
function! s:handle_large_file() abort
let g:large_file = 10485760 " 10MB
let f = expand("<afile>")
if getfsize(f) > g:large_file || getfsize(f) == -2
set eventignore+=all
" turning off relative number helps a lot
set norelativenumber
setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1
else
set eventignore-=all relativenumber
endif
endfunction
augroup LargeFile
autocmd!
autocmd BufReadPre * call s:handle_large_file()
augroup END
" Load auto-command defined in Lua
lua require("custom-autocmd")

View file

@ -0,0 +1,178 @@
scriptencoding utf-8
" change fillchars for folding, vertical split, end of buffer, and message separator
set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾,diff:
" Split window below/right when creating horizontal/vertical windows
set splitbelow splitright
" Time in milliseconds to wait for a mapped sequence to complete,
" see https://unix.stackexchange.com/q/36882/221410 for more info
set timeoutlen=500
set updatetime=500 " For CursorHold events
" Clipboard settings, always use clipboard for all delete, yank, change, put
" operation, see https://stackoverflow.com/q/30691466/6064933
if !empty(provider#clipboard#Executable())
set clipboard+=unnamedplus
endif
" Disable creating swapfiles, see https://stackoverflow.com/q/821902/6064933
set noswapfile
" Ignore certain files and folders when globing
set wildignore+=*.o,*.obj,*.dylib,*.bin,*.dll,*.exe
set wildignore+=*/.git/*,*/.svn/*,*/__pycache__/*,*/build/**
set wildignore+=*.jpg,*.png,*.jpeg,*.bmp,*.gif,*.tiff,*.svg,*.ico
set wildignore+=*.pyc,*.pkl
set wildignore+=*.DS_Store
set wildignore+=*.aux,*.bbl,*.blg,*.brf,*.fls,*.fdb_latexmk,*.synctex.gz,*.xdv
set wildignorecase " ignore file and dir name cases in cmd-completion
" Set up backup directory
let g:backupdir=expand(stdpath('data') . '/backup//')
let &backupdir=g:backupdir
" Skip backup for patterns in option wildignore
let &backupskip=&wildignore
set backup " create backup for files
set backupcopy=yes " copy the original file to backupdir and overwrite it
" General tab settings
set tabstop=2 " number of visual spaces per TAB
set softtabstop=2 " number of spaces in tab when editing
set shiftwidth=2 " number of spaces to use for autoindent
set expandtab " expand tab to spaces so that tabs are spaces
" Set matching pairs of characters and highlight matching brackets
set matchpairs+=<:>,「:」,『:』,【:】,“:”,:,《:》
set number relativenumber " Show line number and relative line number
" Ignore case in general, but become case-sensitive when uppercase is present
set ignorecase smartcase
" File and script encoding settings for vim
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
" Break line at predefined characters
set linebreak
" Character to show before the lines that have been soft-wrapped
set showbreak=
" List all matches and complete till longest common string
set wildmode=list:longest
" Minimum lines to keep above and below cursor when scrolling
set scrolloff=3
" Use mouse to select and resize windows, etc.
set mouse=a " Enable mouse in several mode
set mousemodel=popup " Set the behaviour of mouse
set mousescroll=ver:1,hor:0
" Disable showing current mode on command line since statusline plugins can show it.
set noshowmode
set fileformats=unix,dos " Fileformats to use for new files
" Ask for confirmation when handling unsaved or read-only files
set confirm
set visualbell noerrorbells " Do not use visual and errorbells
set history=500 " The number of command and search history to keep
" Use list mode and customized listchars
set list listchars=tab:▸\ ,extends:,precedes:,nbsp:␣
" Auto-write the file based on some condition
set autowrite
" Show hostname, full path of file and last-mod time on the window title. The
" meaning of the format str for strftime can be found in
" http://man7.org/linux/man-pages/man3/strftime.3.html. The function to get
" lastmod time is drawn from https://stackoverflow.com/q/8426736/6064933
set title
set titlestring=
set titlestring=%{utils#Get_titlestr()}
" Persistent undo even after you close a file and re-open it
set undofile
" Do not show "match xx of xx" and other messages during auto-completion
set shortmess+=c
" Do not show search match count on bottom right (seriously, I would strain my
" neck looking at it). Using plugins like vim-anzu or nvim-hlslens is a better
" choice, IMHO.
set shortmess+=S
" Disable showing intro message (:intro)
set shortmess+=I
" Completion behaviour
" set completeopt+=noinsert " Auto select the first completion entry
set completeopt+=menuone " Show menu even if there is only one item
set completeopt-=preview " Disable the preview window
set pumheight=10 " Maximum number of items to show in popup menu
set pumblend=10 " pseudo transparency for completion menu
set winblend=0 " pseudo transparency for floating window
" Insert mode key word completion setting
set complete+=kspell complete-=w complete-=b complete-=u complete-=t
set spelllang=en,cjk " Spell languages
set spellsuggest+=9 " show 9 spell suggestions at most
" Align indent to next multiple value of shiftwidth. For its meaning,
" see http://vim.1045645.n5.nabble.com/shiftround-option-td5712100.html
set shiftround
set virtualedit=block " Virtual edit is useful for visual block edit
" Correctly break multi-byte characters such as CJK,
" see https://stackoverflow.com/q/32669814/6064933
set formatoptions+=mM
" Tilde (~) is an operator, thus must be followed by motions like `e` or `w`.
set tildeop
set synmaxcol=250 " Text after this column number is not highlighted
set nostartofline
" External program to use for grep command
if executable('rg')
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case
set grepformat=%f:%l:%c:%m
endif
" Enable true color support. Do not set this option if your terminal does not
" support true colors! For a comprehensive list of terminals supporting true
" colors, see https://github.com/termstandard/colors and https://gist.github.com/XVilka/8346728.
set termguicolors
" Set up cursor color and shape in various mode, ref:
" https://github.com/neovim/neovim/wiki/FAQ#how-to-change-cursor-color-in-the-terminal
set guicursor=n-v-c:block-Cursor/lCursor,i-ci-ve:ver25-Cursor2/lCursor2,r-cr:hor20,o:hor20
set signcolumn=yes:1
" Remove certain character from file name pattern matching
set isfname-==
set isfname-=,
" diff options
set diffopt=
set diffopt+=vertical " show diff in vertical position
set diffopt+=filler " show filler for deleted lines
set diffopt+=closeoff " turn off diff when one file window is closed
set diffopt+=context:3 " context for diff
set diffopt+=internal,indent-heuristic,algorithm:histogram
set diffopt+=linematch:60
set nowrap " do no wrap
set noruler

View file

@ -0,0 +1,391 @@
scriptencoding utf-8
" Use short names for common plugin manager commands to simplify typing.
" To use these shortcuts: first activate command line with `:`, then input the
" short alias, e.g., `pi`, then press <space>, the alias will be expanded to
" the full command automatically.
call utils#Cabbrev('pi', 'Lazy install')
call utils#Cabbrev('pud', 'Lazy update')
call utils#Cabbrev('pc', 'Lazy clean')
call utils#Cabbrev('ps', 'Lazy sync')
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" configurations for vim script plugin "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""" vlime settings """"""""""""""""""""""""""""""""
command! -nargs=0 StartVlime call jobstart(printf("sbcl --load %s/vlime/lisp/start-vlime.lisp", g:package_home))
"""""""""""""""""""""""""""""LeaderF settings"""""""""""""""""""""
" Do not use cache file
let g:Lf_UseCache = 0
" Refresh each time we call leaderf
let g:Lf_UseMemoryCache = 0
" Ignore certain files and directories when searching files
let g:Lf_WildIgnore = {
\ 'dir': ['.git', '__pycache__', '.DS_Store', '*_cache'],
\ 'file': ['*.exe', '*.dll', '*.so', '*.o', '*.pyc', '*.jpg', '*.png',
\ '*.gif', '*.svg', '*.ico', '*.db', '*.tgz', '*.tar.gz', '*.gz',
\ '*.zip', '*.bin', '*.pptx', '*.xlsx', '*.docx', '*.pdf', '*.tmp',
\ '*.wmv', '*.mkv', '*.mp4', '*.rmvb', '*.ttf', '*.ttc', '*.otf',
\ '*.mp3', '*.aac']
\}
" Do not show fancy icons for Linux server.
if g:is_linux
let g:Lf_ShowDevIcons = 0
endif
" Only fuzzy-search files names
let g:Lf_DefaultMode = 'FullPath'
" Popup window settings
let w = float2nr(&columns * 0.8)
if w > 140
let g:Lf_PopupWidth = 140
else
let g:Lf_PopupWidth = w
endif
let g:Lf_PopupPosition = [0, float2nr((&columns - g:Lf_PopupWidth)/2)]
" Do not use version control tool to list files under a directory since
" submodules are not searched by default.
let g:Lf_UseVersionControlTool = 0
" Use rg as the default search tool
let g:Lf_DefaultExternalTool = "rg"
" show dot files
let g:Lf_ShowHidden = 1
" Disable default mapping
let g:Lf_ShortcutF = ''
let g:Lf_ShortcutB = ''
" set up working directory for git repository
let g:Lf_WorkingDirectoryMode = 'a'
" Search files in popup window
nnoremap <silent> <leader>ff :<C-U>Leaderf file --popup<CR>
" Grep project files in popup window
nnoremap <silent> <leader>fg :<C-U>Leaderf rg --no-messages --popup<CR>
" Search vim help files
nnoremap <silent> <leader>fh :<C-U>Leaderf help --popup<CR>
" Search tags in current buffer
nnoremap <silent> <leader>ft :<C-U>Leaderf bufTag --popup<CR>
" Switch buffers
nnoremap <silent> <leader>fb :<C-U>Leaderf buffer --popup<CR>
" Search recent files
nnoremap <silent> <leader>fr :<C-U>Leaderf mru --popup --absolute-path<CR>
let g:Lf_PopupColorscheme = 'gruvbox_material'
" Change keybinding in LeaderF prompt mode, use ctrl-n and ctrl-p to navigate
" items.
let g:Lf_CommandMap = {'<C-J>': ['<C-N>'], '<C-K>': ['<C-P>']}
" do not preview results, it will add the file to buffer list
let g:Lf_PreviewResult = {
\ 'File': 0,
\ 'Buffer': 0,
\ 'Mru': 0,
\ 'Tag': 0,
\ 'BufTag': 1,
\ 'Function': 1,
\ 'Line': 0,
\ 'Colorscheme': 0,
\ 'Rg': 0,
\ 'Gtags': 0
\}
""""""""""""""""""""""""""""open-browser.vim settings"""""""""""""""""""
if g:is_win || g:is_mac
" Disable netrw's gx mapping.
let g:netrw_nogx = 1
" Use another mapping for the open URL method
nmap ob <Plug>(openbrowser-smart-search)
xmap ob <Plug>(openbrowser-smart-search)
endif
""""""""""""""""""""""""""" vista settings """"""""""""""""""""""""""""""""""
let g:vista#renderer#icons = {
\ 'member': '',
\ }
" Do not echo message on command line
let g:vista_echo_cursor = 0
" Stay in current window when vista window is opened
let g:vista_stay_on_open = 0
nnoremap <silent> <Space>t :<C-U>Vista!!<CR>
""""""""""""""""""""""""vim-mundo settings"""""""""""""""""""""""
let g:mundo_verbose_graph = 0
let g:mundo_width = 80
nnoremap <silent> <Space>u :MundoToggle<CR>
""""""""""""""""""""""""""""better-escape.vim settings"""""""""""""""""""""""""
let g:better_escape_interval = 200
""""""""""""""""""""""""""""vim-xkbswitch settings"""""""""""""""""""""""""
let g:XkbSwitchEnabled = 1
"""""""""""""""""""""""""""""" neoformat settings """""""""""""""""""""""
let g:neoformat_enabled_python = ['black', 'yapf']
let g:neoformat_cpp_clangformat = {
\ 'exe': 'clang-format',
\ 'args': ['--style="{IndentWidth: 4}"']
\ }
let g:neoformat_c_clangformat = {
\ 'exe': 'clang-format',
\ 'args': ['--style="{IndentWidth: 4}"']
\ }
let g:neoformat_enabled_cpp = ['clangformat']
let g:neoformat_enabled_c = ['clangformat']
"""""""""""""""""""""""""vim-markdown settings"""""""""""""""""""
" Disable header folding
let g:vim_markdown_folding_disabled = 1
" Whether to use conceal feature in markdown
let g:vim_markdown_conceal = 1
" Disable math tex conceal and syntax highlight
let g:tex_conceal = ''
let g:vim_markdown_math = 0
" Support front matter of various format
let g:vim_markdown_frontmatter = 1 " for YAML format
let g:vim_markdown_toml_frontmatter = 1 " for TOML format
let g:vim_markdown_json_frontmatter = 1 " for JSON format
" Let the TOC window autofit so that it doesn't take too much space
let g:vim_markdown_toc_autofit = 1
"""""""""""""""""""""""""markdown-preview settings"""""""""""""""""""
" Only setting this for suitable platforms
if g:is_win || g:is_mac
" Do not close the preview tab when switching to other buffers
let g:mkdp_auto_close = 0
" Shortcuts to start and stop markdown previewing
nnoremap <silent> <M-m> :<C-U>MarkdownPreview<CR>
nnoremap <silent> <M-S-m> :<C-U>MarkdownPreviewStop<CR>
endif
""""""""""""""""""""""""vim-grammarous settings""""""""""""""""""""""""""""""
if g:is_mac
let g:grammarous#languagetool_cmd = 'languagetool'
let g:grammarous#disabled_rules = {
\ '*' : ['WHITESPACE_RULE', 'EN_QUOTES', 'ARROWS', 'SENTENCE_WHITESPACE',
\ 'WORD_CONTAINS_UNDERSCORE', 'COMMA_PARENTHESIS_WHITESPACE',
\ 'EN_UNPAIRED_BRACKETS', 'UPPERCASE_SENTENCE_START',
\ 'ENGLISH_WORD_REPEAT_BEGINNING_RULE', 'DASH_RULE', 'PLUS_MINUS',
\ 'PUNCTUATION_PARAGRAPH_END', 'MULTIPLICATION_SIGN', 'PRP_CHECKOUT',
\ 'CAN_CHECKOUT', 'SOME_OF_THE', 'DOUBLE_PUNCTUATION', 'HELL',
\ 'CURRENCY', 'POSSESSIVE_APOSTROPHE', 'ENGLISH_WORD_REPEAT_RULE',
\ 'NON_STANDARD_WORD', 'AU', 'DATE_NEW_YEAR'],
\ }
augroup grammarous_map
autocmd!
autocmd FileType markdown nmap <buffer> <leader>x <Plug>(grammarous-close-info-window)
autocmd FileType markdown nmap <buffer> <c-n> <Plug>(grammarous-move-to-next-error)
autocmd FileType markdown nmap <buffer> <c-p> <Plug>(grammarous-move-to-previous-error)
augroup END
endif
""""""""""""""""""""""""unicode.vim settings""""""""""""""""""""""""""""""
nmap ga <Plug>(UnicodeGA)
""""""""""""""""""""""""""""vim-sandwich settings"""""""""""""""""""""""""""""
" Map s to nop since s in used by vim-sandwich. Use cl instead of s.
nmap s <Nop>
omap s <Nop>
""""""""""""""""""""""""""""vimtex settings"""""""""""""""""""""""""""""
if executable('latex')
" Hacks for inverse search to work semi-automatically,
" see https://jdhao.github.io/2021/02/20/inverse_search_setup_neovim_vimtex/.
function! s:write_server_name() abort
let nvim_server_file = (has('win32') ? $TEMP : '/tmp') . '/vimtexserver.txt'
call writefile([v:servername], nvim_server_file)
endfunction
augroup vimtex_common
autocmd!
autocmd FileType tex call s:write_server_name()
autocmd FileType tex nmap <buffer> <F9> <plug>(vimtex-compile)
augroup END
let g:vimtex_compiler_latexmk = {
\ 'build_dir' : 'build',
\ }
" TOC settings
let g:vimtex_toc_config = {
\ 'name' : 'TOC',
\ 'layers' : ['content', 'todo', 'include'],
\ 'resize' : 1,
\ 'split_width' : 30,
\ 'todo_sorted' : 0,
\ 'show_help' : 1,
\ 'show_numbers' : 1,
\ 'mode' : 2,
\ }
" Viewer settings for different platforms
if g:is_win
let g:vimtex_view_general_viewer = 'SumatraPDF'
let g:vimtex_view_general_options = '-reuse-instance -forward-search @tex @line @pdf'
endif
if g:is_mac
" let g:vimtex_view_method = "skim"
let g:vimtex_view_general_viewer = '/Applications/Skim.app/Contents/SharedSupport/displayline'
let g:vimtex_view_general_options = '-r @line @pdf @tex'
augroup vimtex_mac
autocmd!
autocmd User VimtexEventCompileSuccess call UpdateSkim()
augroup END
" The following code is adapted from https://gist.github.com/skulumani/7ea00478c63193a832a6d3f2e661a536.
function! UpdateSkim() abort
let l:out = b:vimtex.out()
let l:src_file_path = expand('%:p')
let l:cmd = [g:vimtex_view_general_viewer, '-r']
if !empty(system('pgrep Skim'))
call extend(l:cmd, ['-g'])
endif
call jobstart(l:cmd + [line('.'), l:out, l:src_file_path])
endfunction
endif
endif
""""""""""""""""""""""""""""vim-matchup settings"""""""""""""""""""""""""""""
" Improve performance
let g:matchup_matchparen_deferred = 1
let g:matchup_matchparen_timeout = 100
let g:matchup_matchparen_insert_timeout = 30
" Enhanced matching with matchup plugin
let g:matchup_override_vimtex = 1
" Whether to enable matching inside comment or string
let g:matchup_delim_noskips = 0
" Show offscreen match pair in popup window
let g:matchup_matchparen_offscreen = {'method': 'popup'}
"""""""""""""""""""""""""" asyncrun.vim settings """"""""""""""""""""""""""
" Automatically open quickfix window of 6 line tall after asyncrun starts
let g:asyncrun_open = 6
if g:is_win
" Command output encoding for Windows
let g:asyncrun_encs = 'gbk'
endif
""""""""""""""""""""""""""""""firenvim settings""""""""""""""""""""""""""""""
if exists('g:started_by_firenvim') && g:started_by_firenvim
if g:is_mac
set guifont=Iosevka\ Nerd\ Font:h18
else
set guifont=Consolas
endif
" general config for firenvim
let g:firenvim_config = {
\ 'globalSettings': {
\ 'alt': 'all',
\ },
\ 'localSettings': {
\ '.*': {
\ 'cmdline': 'neovim',
\ 'priority': 0,
\ 'selector': 'textarea',
\ 'takeover': 'never',
\ },
\ }
\ }
function s:setup_firenvim() abort
set signcolumn=no
set noruler
set noshowcmd
set laststatus=0
set showtabline=0
endfunction
augroup firenvim
autocmd!
autocmd BufEnter * call s:setup_firenvim()
autocmd BufEnter sqlzoo*.txt set filetype=sql
autocmd BufEnter github.com_*.txt set filetype=markdown
autocmd BufEnter stackoverflow.com_*.txt set filetype=markdown
augroup END
endif
""""""""""""""""""""""""""""""nvim-gdb settings""""""""""""""""""""""""""""""
nnoremap <leader>dp :<C-U>GdbStartPDB python -m pdb %<CR>
""""""""""""""""""""""""""""""wilder.nvim settings""""""""""""""""""""""""""""""
call timer_start(250, { -> s:wilder_init() })
function! s:wilder_init() abort
try
call wilder#setup({
\ 'modes': [':', '/', '?'],
\ 'next_key': '<Tab>',
\ 'previous_key': '<S-Tab>',
\ 'accept_key': '<C-y>',
\ 'reject_key': '<C-e>'
\ })
call wilder#set_option('pipeline', [
\ wilder#branch(
\ wilder#cmdline_pipeline({
\ 'language': 'python',
\ 'fuzzy': 1,
\ 'sorter': wilder#python_difflib_sorter(),
\ 'debounce': 30,
\ }),
\ wilder#python_search_pipeline({
\ 'pattern': wilder#python_fuzzy_pattern(),
\ 'sorter': wilder#python_difflib_sorter(),
\ 'engine': 're',
\ 'debounce': 30,
\ }),
\ ),
\ ])
let l:hl = wilder#make_hl('WilderAccent', 'Pmenu', [{}, {}, {'foreground': '#f4468f'}])
call wilder#set_option('renderer', wilder#popupmenu_renderer({
\ 'highlighter': wilder#basic_highlighter(),
\ 'max_height': 15,
\ 'highlights': {
\ 'accent': l:hl,
\ },
\ 'left': [' ', wilder#popupmenu_devicons(),],
\ 'right': [' ', wilder#popupmenu_scrollbar(),],
\ 'apply_incsearch_fix': 0,
\ }))
catch /^Vim\%((\a\+)\)\=:E117/
echohl Error |echomsg "Wilder.nvim missing"| echohl None
endtry
endfunction
""""""""""""""""""""""""""""""vim-auto-save settings""""""""""""""""""""""""""""""
let g:auto_save = 1 " enable AutoSave on Vim startup

View file

@ -0,0 +1,5 @@
_: {
home-manager.users.root.imports = [
./home-manager.nix
];
}

View file

@ -0,0 +1,81 @@
{
config,
pkgs,
lib,
...
}: let
boolToStr = b:
if b
then "true"
else "false";
boolToStr' = b:
if b
then "1"
else "0";
in {
xdg.configFile."nvim/lua/globals.lua".text = ''
local fn = vim.fn
local api = vim.api
local utils = require('utils')
-- Inspect something
function _G.inspect(item)
vim.print(item)
end
------------------------------------------------------------------------
-- custom variables --
------------------------------------------------------------------------
vim.g.is_win = ${boolToStr pkgs.stdenv.isCygwin}
vim.g.is_mac = ${boolToStr pkgs.stdenv.isDarwin}
vim.g.is_linux = ${boolToStr (!pkgs.stdenv.isCygwin && !pkgs.stdenv.isDarwin)}
vim.g.logging_level = "info"
------------------------------------------------------------------------
-- builtin variables --
------------------------------------------------------------------------
vim.g.loaded_perl_provider = 0
vim.g.loaded_ruby_provider = ${boolToStr' config.programs.neovim.withRuby}
vim.g.loaded_node_provider = ${boolToStr' config.programs.neovim.withNodeJs}
vim.g.did_install_default_menus = 1 -- do not load menu
-- 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
vim.cmd [[language en_US.UTF-8]]
-- 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
'';
}

View file

@ -0,0 +1,64 @@
{
pkgs,
config,
...
}: {
imports = [
./globals.nix
./plugins/lazy-nvim.nix
];
programs.neovim = {
plugins = with pkgs.vimPlugins; [lazy-nvim];
enable = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
defaultEditor = true;
extraLuaConfig = ''
-- This is my personal Nvim configuration supporting Mac, Linux and Windows, with various plugins configured.
-- This configuration evolves as I learn more about Nvim and become more proficient in using Nvim.
-- Since it is very long (more than 1000 lines!), you should read it carefully and take only the settings that suit you.
-- I would not recommend cloning this repo and replace your own config. Good configurations are personal,
-- built over time with a lot of polish.
--
-- Author: Jiedong Hao
-- Email: jdhao@hotmail.com
-- Blog: https://jdhao.github.io/
-- GitHub: https://github.com/jdhao
-- StackOverflow: https://stackoverflow.com/users/6064933/jdhao
local core_conf_files = {
"globals.lua", -- some global settings
"options.vim", -- setting options in nvim
"autocommands.vim", -- various autocommands
"mappings.lua", -- all the user-defined mappings
"plugins.lua",
"plugins.vim",
"colorschemes.lua", -- colorscheme settings
}
local viml_conf_dir = vim.fn.stdpath("config") .. "/viml_conf"
-- source all the core config files
for _, file_name in ipairs(core_conf_files) do
if vim.endswith(file_name, 'vim') then
local path = string.format("%s/%s", viml_conf_dir, file_name)
local source_cmd = "source " .. path
vim.cmd(source_cmd)
else
local module_name, _ = string.gsub(file_name, "%.lua", "")
package.loaded[module_name] = nil
require(module_name)
end
end
'';
withPython3 = true;
};
systemd.user.tmpfiles.rules = [
"d %h/.cache/nvim/undo-files 0700 - - mM:1w -"
"d %h/.cache/nvim/swap-files 0700 - - mM:1w -"
"d %h/.cache/nvim/backup-files 0700 - - mM:1w -"
];
xdg.configFile.nvim = {
recursive = true;
source = ./config;
};
}

View file

@ -0,0 +1,477 @@
{
pkgs,
config,
...
}: {
programs.neovim = {
plugins = with pkgs.vimPlugins;
[
(nvim-treesitter.withPlugins (p: []))
(pkgs.vimUtils.buildVimPlugin {
name = "vim-highlighturl";
src = pkgs.fetchFromGitHub {
owner = "itchyny";
repo = "vim-highlighturl";
rev = "012fee983e03913db6ba6393307eac434999b896";
sha256 = "18d72sgk44fwc91ziy54qr7vpzrs7qdlkwzlpvm9yr1d4k6329pc";
};
})
asyncrun-vim
bufferline-nvim
catppuccin-nvim
cmp-ai
cmp-buffer
cmp-emoji
cmp-nvim-lsp
cmp-omni
cmp-path
committia-vim
dashboard-nvim
delimitMate
dressing-nvim
fidget-nvim
firenvim
git-conflict-nvim
gitlinker-nvim
gitsigns-nvim
headlines-nvim
hop-nvim
indent-blankline-nvim
lazy-nvim
(LeaderF.overrideAttrs (super: {
buildInputs = [pkgs.python3 pkgs.python3Packages.setuptools];
}))
lspkind-nvim
lualine-nvim
neoformat
nvim-bqf
nvim-cmp
nvim-gdb
nvim-hlslens
nvim-lspconfig
nvim-notify
nvim-tree-lua
nvim-web-devicons
open-browser-vim
plenary-nvim
tabular
targets-vim
telescope-nvim
telescope-symbols-nvim
unicode-vim
vim-auto-save
vim-commentary
vim-eunuch
vim-flog
vim-fugitive
vim-indent-object
vim-markdown
vim-matchup
vim-mundo
vim-obsession
vim-oscyank
vim-repeat
vim-sandwich
vim-scriptease
vim-swap
vim-toml
vimtex
vista-vim
which-key-nvim
whitespace-nvim
wilder-nvim
yanky-nvim
zen-mode-nvim
]
++ (
if pkgs.targetPlatform.system != "riscv64-linux"
then [
diffview-nvim
vim-grammarous
]
else []
);
};
xdg.configFile."nvim/lua/config/lazy-nvim.lua".text = ''
local utils = require('utils')
-- check if firenvim is active
local firenvim_not_active = function()
return not vim.g.started_by_firenvim
end
require("lazy").setup({
{
"hrsh7th/nvim-cmp",
-- event = 'InsertEnter',
event = "VeryLazy",
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"onsails/lspkind-nvim",
"hrsh7th/cmp-path",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-omni",
"hrsh7th/cmp-emoji",
"tzachar/cmp-ai"
},
config = function()
require("config.nvim-cmp")
end,
},
{
"tzachar/cmp-ai",
event = "VeryLazy",
dependencies = {'nvim-lua/plenary.nvim'},
config = function()
require("config.cmp-ai")
end,
},
{
"neovim/nvim-lspconfig",
event = { "BufRead", "BufNewFile" },
config = function()
require("config.lsp")
end,
},
{
"nvim-treesitter/nvim-treesitter",
config = function()
require("config.treesitter")
end,
},
{ "machakann/vim-swap", event = "VeryLazy" },
-- Super fast buffer jump
{
"smoka7/hop.nvim",
event = "VeryLazy",
config = function()
require("config.nvim_hop")
end,
},
-- Show match number and index for searching
{
"kevinhwang91/nvim-hlslens",
branch = "main",
keys = { "*", "#", "n", "N" },
config = function()
require("config.hlslens")
end,
},
{
"Yggdroot/LeaderF",
cmd = "Leaderf",
},
"nvim-lua/plenary.nvim",
{
"nvim-telescope/telescope.nvim",
cmd = "Telescope",
dependencies = {
"nvim-telescope/telescope-symbols.nvim",
},
},
{
"lukas-reineke/headlines.nvim",
dependencies = "nvim-treesitter/nvim-treesitter",
config = true, -- or `opts = {}`
},
{ "catppuccin/nvim", name = "catppuccin", lazy = true },
{ "nvim-tree/nvim-web-devicons", event = "VeryLazy" },
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
cond = firenvim_not_active,
config = function()
require("config.statusline")
end,
},
{
"akinsho/bufferline.nvim",
event = { "BufEnter" },
cond = firenvim_not_active,
config = function()
require("config.bufferline")
end,
},
{
"nvimdev/dashboard-nvim",
cond = firenvim_not_active,
config = function()
require("config.dashboard-nvim")
end,
},
{
"lukas-reineke/indent-blankline.nvim",
event = "VeryLazy",
main = 'ibl',
config = function()
require("config.indent-blankline")
end,
},
{ "itchyny/vim-highlighturl", event = "VeryLazy" },
{
"rcarriga/nvim-notify",
event = "VeryLazy",
config = function()
require("config.nvim-notify")
end,
},
{
"tyru/open-browser.vim",
event = "VeryLazy",
},
{
"liuchengxu/vista.vim",
enabled = function()
if utils.executable("ctags") then
return true
else
return false
end
end,
cmd = "Vista",
},
-- Automatic insertion and deletion of a pair of characters
{ "Raimondi/delimitMate", event = "InsertEnter" },
-- Comment plugin
{ "tpope/vim-commentary", event = "VeryLazy" },
-- Autosave files on certain events
{ "907th/vim-auto-save", event = "InsertEnter" },
-- Show undo history visually
{ "simnalamburt/vim-mundo", cmd = { "MundoToggle", "MundoShow" } },
-- better UI for some nvim actions
{ "stevearc/dressing.nvim" },
-- Manage your yank history
{
"gbprod/yanky.nvim",
cmd = { "YankyRingHistory" },
config = function()
require("config.yanky")
end,
},
-- Handy unix command inside Vim (Rename, Move etc.)
{ "tpope/vim-eunuch", cmd = { "Rename", "Delete" } },
-- Repeat vim motions
{ "tpope/vim-repeat", event = "VeryLazy" },
-- Auto format tools
{ "sbdchd/neoformat", cmd = { "Neoformat" } },
-- Git command inside vim
{
"tpope/vim-fugitive",
event = "User InGitRepo",
config = function()
require("config.fugitive")
end,
},
-- Better git log display
{ "rbong/vim-flog", cmd = { "Flog" } },
{ "akinsho/git-conflict.nvim", version = "*", config = true },
{
"ruifm/gitlinker.nvim",
event = "User InGitRepo",
config = function()
require("config.git-linker")
end,
},
-- Show git change (change, delete, add) signs in vim sign column
{
"lewis6991/gitsigns.nvim",
config = function()
require("config.gitsigns")
end,
},
-- Better git commit experience
{ "rhysd/committia.vim", lazy = true },
${
if pkgs.targetPlatform.system != "riscv64-linux"
then '' {
"sindrets/diffview.nvim"
},''
else ""
}
{
"kevinhwang91/nvim-bqf",
ft = "qf",
config = function()
require("config.bqf")
end,
},
-- Another markdown plugin
-- { "preservim/vim-markdown", ft = { "markdown" } },
-- Vim tabular plugin for manipulate tabular, required by markdown plugins
-- { "godlygeek/tabular", cmd = { "Tabularize" } },
-- Markdown previewing (only for Mac and Windows)
--{
-- "iamcco/markdown-preview.nvim",
-- ft = { "markdown" },
--},
{
"folke/zen-mode.nvim",
cmd = "ZenMode",
config = function()
require("config.zen-mode")
end,
},
${
if pkgs.targetPlatform.system != "riscv64-linux"
then '' {
"rhysd/vim-grammarous",
ft = { "markdown" },
},''
else ""
}
{ "chrisbra/unicode.vim", event = "VeryLazy" },
-- Additional powerful text object for vim, this plugin should be studied
-- carefully to use its full power
{ "wellle/targets.vim", event = "VeryLazy" },
-- Plugin to manipulate character pairs quickly
{ "machakann/vim-sandwich", event = "VeryLazy" },
-- Add indent object for vim (useful for languages like Python)
{ "michaeljsmith/vim-indent-object", event = "VeryLazy" },
-- Only use these plugin on Windows and Mac and when LaTeX is installed
{
"lervag/vimtex",
enabled = function()
if utils.executable("latex") then
return true
end
return false
end,
ft = { "tex" },
},
-- Modern matchit implementation
{ "andymass/vim-matchup", event = "BufRead" },
{ "tpope/vim-scriptease", cmd = { "Scriptnames", "Message", "Verbose" } },
-- Asynchronous command execution
{ "skywind3000/asyncrun.vim", lazy = true, cmd = { "AsyncRun" } },
{ "cespare/vim-toml", ft = { "toml" }, branch = "main" },
-- Edit text area in browser using nvim
{
"glacambre/firenvim",
build = function()
vim.fn["firenvim#install"](0)
end,
lazy = true,
},
-- Debugger plugin
{
"sakhnik/nvim-gdb",
lazy = true,
},
-- Session management plugin
{ "tpope/vim-obsession", cmd = "Obsession" },
{
"ojroques/vim-oscyank",
enabled = function()
if vim.g.is_linux then
return true
end
return false
end,
cmd = { "OSCYank", "OSCYankReg" },
},
-- The missing auto-completion for cmdline!
{
"gelguy/wilder.nvim",
build = ":UpdateRemotePlugins",
},
-- showing keybindings
{
"folke/which-key.nvim",
event = "VeryLazy",
config = function()
require("config.which-key")
end,
},
-- show and trim trailing whitespaces
{ "jdhao/whitespace.nvim", event = "VeryLazy" },
-- file explorer
{
"nvim-tree/nvim-tree.lua",
keys = { "<space>s" },
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("config.nvim-tree")
end,
},
{
"j-hui/fidget.nvim",
event = "VeryLazy",
tag = "legacy",
config = function()
require("config.fidget-nvim")
end,
},
}, {
performance = {
reset_packpath = false,
rtp = {
reset = false,
}
},
dev = {
path = "${pkgs.vimUtils.packDir config.programs.neovim.finalPackage.passthru.packpathDirs}/pack/myNeovimPackages/start",
patterns = {
"907th",
"akinsho",
"andymass",
"catppuccin",
"cespare",
"chrisbra",
"folke",
"gbprod",
"gelguy",
"glacambre",
"godlygeek",
"honza",
"hrsh7th",
"iamcco",
"itchyny",
"j-hui",
"jdhao",
"kevinhwang91",
"lervag",
"lewis6991",
"liuchengxu",
"lukas-reineke",
"machakann",
"michaeljsmith",
"neovim",
"nvim-lua",
"nvim-lualine",
"nvim-telescope",
"nvim-tree",
"nvim-treesitter",
"nvimdev",
"ojroques",
"onsails",
"preservim",
"quangnguyen30192",
"Raimondi",
"rbong",
"rcarriga",
"rhysd",
"ruifm",
"sakhnik",
"sbdchd",
"simnalamburt",
"sindrets",
"SirVer",
"skywind3000",
"smoka7",
"stevearc",
"tpope",
"tyru",
"tzachar",
"wellle",
"Yggdroot",
},
},
install = {
missing = false,
},
ui = {
border = "rounded",
title = "Plugin Manager",
title_pos = "center",
},
})
'';
}