mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-12-12 09:08:21 -05:00
405 lines
15 KiB
Lua
405 lines
15 KiB
Lua
local api = vim.api
|
|
local wk = require('which-key')
|
|
|
|
local function pandoc_convert(ofiletype)
|
|
if ofiletype == nil then
|
|
ofiletype = 'html'
|
|
end
|
|
|
|
local ifilename = vim.fn.expand('%:p')
|
|
local ofilename = vim.fn.expand('%:p:r') .. '.' .. ofiletype
|
|
local cmd
|
|
|
|
if ofiletype == 'pdf' then
|
|
cmd = string.format('pandoc %s -o %s --pdf-engine=xelatex -V "mainfont:Iosevka Etoile" -V "sansfont:Iosevka Aile" -V "monofont:Iosevka" -V "geometry:margin=1in"', ifilename, ofilename)
|
|
else
|
|
cmd = string.format('pandoc %s -o %s', ifilename, ofilename)
|
|
end
|
|
vim.fn.jobstart(cmd)
|
|
end
|
|
|
|
-- No one likes Esc
|
|
api.nvim_set_keymap('i', 'jk', [[<Esc>]], {noremap = true, silent = true})
|
|
|
|
-- Escape to normal mode in terminal buffer
|
|
api.nvim_set_keymap('t', '<Esc>', '<C-\\><C-n>', {noremap = true, silent = true})
|
|
|
|
-- Continuous indent
|
|
api.nvim_set_keymap('v', '<', '<gv', {noremap = true, silent = true})
|
|
api.nvim_set_keymap('v', '>', '>gv', {noremap = true, silent = true})
|
|
|
|
-- vim-eft
|
|
api.nvim_set_keymap('n', 'f', '<Plug>(eft-f)', {})
|
|
api.nvim_set_keymap('x', 'f', '<Plug>(eft-f)', {})
|
|
api.nvim_set_keymap('n', 'F', '<Plug>(eft-F)', {})
|
|
api.nvim_set_keymap('x', 'F', '<Plug>(eft-F)', {})
|
|
api.nvim_set_keymap('n', 't', '<Plug>(eft-t)', {})
|
|
api.nvim_set_keymap('x', 't', '<Plug>(eft-t)', {})
|
|
api.nvim_set_keymap('n', 'T', '<Plug>(eft-T)', {})
|
|
api.nvim_set_keymap('x', 'T', '<Plug>(eft-T)', {})
|
|
api.nvim_set_keymap('n', ';', '<Plug>(eft-repeat)', {})
|
|
api.nvim_set_keymap('x', ';', '<Plug>(eft-repeat)', {})
|
|
|
|
-----------------
|
|
-- Normal mode --
|
|
-----------------
|
|
wk.register({
|
|
-- Better Y
|
|
Y = {'y$', 'Yank to eol'},
|
|
|
|
-- Easier start and end of line
|
|
H = {'^', 'Start of the line'},
|
|
L = {'$', 'End of the line'},
|
|
|
|
-- Easier moving between windows
|
|
['<C-h>'] = {'<C-w>h', 'Go to the left window'},
|
|
['<C-l>'] = {'<C-w>l', 'Go to the right window'},
|
|
['<C-j>'] = {'<C-w>j', 'Go to the down window'},
|
|
['<C-k>'] = {'<C-w>k', 'Go to the up window'},
|
|
['<C-q>'] = {'<C-w>q', 'Quit a window'},
|
|
|
|
-- Copy the whole buffer
|
|
['<C-a>'] = {'<Cmd>%y+<CR>', 'Copy whole buffer'},
|
|
|
|
-- Close buffer
|
|
['<C-x>'] = {':bd!<CR>', 'Close buffer'},
|
|
|
|
-- Remove trailing whitespace
|
|
['<A-w>'] = {':%s/\\s\\+$//e<CR>', 'Remove trailing'},
|
|
|
|
-- Resize buffer
|
|
['<A-j>'] = {':resize -2<CR>', 'Resize vertical -2'},
|
|
['<A-k>'] = {':resize +2<CR>', 'Resize vertical +2'},
|
|
['<A-h>'] = {':vertical resize -2<CR>', 'Resize horizontal -2'},
|
|
['<A-l>'] = {':vertical resize +2<CR>', 'Resize horizontal +2'},
|
|
|
|
-- Switch between tabs and spaces
|
|
['<A-t>'] = {
|
|
function()
|
|
if vim.o.expandtab == true then
|
|
vim.api.nvim_command('set noexpandtab nosmarttab softtabstop& shiftwidth&')
|
|
vim.api.nvim_command('echomsg "Switched to indent with tabs"')
|
|
else
|
|
vim.opt.expandtab = true
|
|
vim.opt.smarttab = true
|
|
vim.opt.softtabstop = 4
|
|
vim.opt.shiftwidth = 4
|
|
vim.api.nvim_command('echomsg "Switched to indent with 4 spaces"')
|
|
end
|
|
end,
|
|
'Switch indent style'
|
|
},
|
|
|
|
-- Naming common keys
|
|
['['] = {
|
|
name = 'Block motions (previous)',
|
|
d = 'Previous diagnostics',
|
|
g = 'Previous git hunk'
|
|
},
|
|
[']'] = {
|
|
name = 'Block motions (next)',
|
|
d = 'Next diagnostics',
|
|
g = 'Next git hunk'
|
|
},
|
|
g = {
|
|
name = 'Goto motions',
|
|
d = 'Go to definition',
|
|
D = 'Go to declaration',
|
|
i = 'Go to implementation',
|
|
r = 'Go to references',
|
|
R = {'<Cmd>TroubleToggle lsp_references<CR>', 'Reference list'}
|
|
},
|
|
K = {name = 'Hover'},
|
|
z = {name = 'Misc utils'},
|
|
|
|
-- Move between tabs
|
|
['<TAB>'] = {'<Cmd>BufferLineCycleNext<CR>', 'Next buffer'},
|
|
['<S-TAB>'] = {'<Cmd>BufferLineCyclePrev<CR>', 'Previous buffer'},
|
|
|
|
-- NvimTree
|
|
['<C-n>'] = {':NvimTreeToggle<CR>', 'NvimTree'},
|
|
|
|
-- ToggleTerm
|
|
['<C-\\>'] = {':ToggleTerm<CR>', 'Toggle terminal'},
|
|
['<A-\\>'] = {':ToggleTerm direction=float<CR>', 'Toggle float terminal'},
|
|
|
|
-- hop.nvim
|
|
S = {':HopWord<CR>', 'Hop to word'},
|
|
['<C-s>'] = {':HopChar1<CR>', 'Hop to character'},
|
|
['<A-s>'] = {':HopPattern<CR>', 'Hop to pattern'}
|
|
})
|
|
|
|
-----------------------------------
|
|
-- Normal mode (with leader key) --
|
|
-----------------------------------
|
|
wk.register({
|
|
a = {':EasyAlign<CR>', 'Align'},
|
|
|
|
b = {
|
|
name = 'Buffer/Tab',
|
|
c = {':ColorizerToggle<CR>', 'Colorizer'},
|
|
d = {':bdelete<CR>', 'Close buffer'},
|
|
j = {':BufferLineCyclePrev<CR>', 'Previous buffer'},
|
|
k = {':BufferLineCycleNext<CR>', 'Next buffer'},
|
|
n = {':enew<CR>', 'New buffer'},
|
|
u = {':UndotreeToggle<CR>', 'Undotree'},
|
|
z = {':ZenMode<CR>', 'Zen mode'},
|
|
D = {'<Cmd>tabclose<CR>', 'Close tab'},
|
|
J = {'<Cmd>tabprev<CR>', 'Previous tab'},
|
|
K = {'<Cmd>tabnext<CR>', 'Next tab'},
|
|
N = {'<Cmd>tabnew<CR>', 'New tab'},
|
|
v = {
|
|
name = 'Convert',
|
|
m = {function() pandoc_convert('md') end, 'To Markdown'},
|
|
o = {function() pandoc_convert('org') end, 'To Org'},
|
|
p = {function() pandoc_convert('pdf') end, 'To PDF'},
|
|
r = {function() pandoc_convert('rst') end, 'To RST'},
|
|
t = {function() pandoc_convert('tex') end, 'To LaTeX'},
|
|
w = {function() pandoc_convert('html') end, 'To HTML'}
|
|
}
|
|
},
|
|
|
|
d = {
|
|
name = 'DAP',
|
|
b = {':lua require("dap").toggle_breakpoint()<CR>', 'Toggle breakpoint'},
|
|
c = {':lua require("dapui").close()<CR>', 'Close UI'},
|
|
e = {':lua require("dapui").eval()<CR>', 'Evaluate cursorword'},
|
|
f = {':lua require("dapui").float_element()<CR>', 'Float elements'},
|
|
i = {':lua require("dap").repl.open()<CR>', 'Inspect via REPL'},
|
|
n = {':lua require("dap").step_into()<CR>', 'Step through code'},
|
|
o = {':lua require("dapui").open()<CR>', 'Open UI'},
|
|
s = {':lua require("dap").continue()<CR>', 'Debug session'},
|
|
t = {':lua require("dapui").open()<CR>', 'Toggle UI'}
|
|
},
|
|
|
|
e = {
|
|
name = 'Session',
|
|
s = {':lua require("persistence").save()<CR>', 'Save session for current directory'},
|
|
d = {':lua require("persistence").stop()<CR>', 'Stop automatically saving'},
|
|
l = {':lua require("persistence").load({last = true})<CR>', 'Load last session'},
|
|
r = {':lua require("persistence").load()<CR>', 'Load session for current directory'}
|
|
},
|
|
|
|
-- Telescope
|
|
f = {
|
|
name = 'Telescope',
|
|
a = {':Telescope autocommands<CR>', 'Autocommands'},
|
|
b = {':Telescope buffers<CR>', 'Buffers'},
|
|
c = {':Telescope commands<CR>', 'Commands'},
|
|
d = {':Telescope projects<CR>', 'Recent directories'},
|
|
e = {':Telescope file_browser<CR>', 'File browser'},
|
|
f = {':Telescope find_files<CR>', 'Find files'},
|
|
g = {':Telescope live_grep<CR>', 'Live grep'},
|
|
h = {':Telescope help_tags<CR>', 'Help tags'},
|
|
i = {':Telescope highlights<CR>', 'Highlight groups'},
|
|
j = {':Telescope symbols<CR>', 'Pick emojis'},
|
|
k = {':Telescope keymaps<CR>', 'Normal keymaps'},
|
|
m = {':Telescope marks<CR>', 'Bookmarks'},
|
|
n = {':Telescope man_pages<CR>', 'Man pages'},
|
|
o = {':Telescope oldfiles<CR>', 'Recent files'},
|
|
p = {':Telescope project display_type=full<CR>', 'Projects'},
|
|
r = {':Telescope reloader<CR>', 'Reload lua modules'},
|
|
s = {':Telescope treesitter<CR>', 'Treesitter'},
|
|
t = {':Telescope<CR>', 'Telescope'},
|
|
u = {':Telescope current_buffer_fuzzy_find<CR>', 'Search current buffer'},
|
|
v = {':Telescope vim_options<CR>', 'Vim options'},
|
|
y = {':Telescope filetypes<CR>', 'Filetypes'},
|
|
z = {':Telescope registers<CR>', 'Vim registers'}
|
|
},
|
|
|
|
-- Git
|
|
g = {
|
|
name = 'Git',
|
|
b = 'Blame current line',
|
|
p = 'Preview hunk',
|
|
r = 'Reset hunk',
|
|
R = 'Reset all hunks in buffer',
|
|
s = 'Stage hunk',
|
|
S = 'Stage buffer',
|
|
u = 'Undo hunk',
|
|
U = 'Reset buffer index',
|
|
n = {':Neogit<CR>', 'Neogit'},
|
|
f = {
|
|
name = 'Telescope',
|
|
a = {':Telescope git_stash<CR>', 'Stash'},
|
|
b = {':Telescope git_bcommits<CR>', 'Buffer commits'},
|
|
c = {':Telescope git_commits<CR>', 'Commits'},
|
|
m = {':Telescope git_branches<CR>', 'Branches'},
|
|
s = {':Telescope git_status<CR>', 'Status'}
|
|
}
|
|
},
|
|
|
|
-- translate-shell.vim
|
|
j = {
|
|
name = 'Translate',
|
|
t = {':Trans<CR>', 'Translate'},
|
|
d = {':TransSelectDirection<CR>', 'Translate with direction'},
|
|
r = {'cw<C-R>=system(\'trans -brief -no-ansi\', getreg(""))[:-2]<CR>', 'Translate and replace'},
|
|
c = {'cw<C-R>=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]<S-Left><S-Left><Right>', 'Translate and replace with direction'}
|
|
},
|
|
|
|
l = {
|
|
name = 'LSP',
|
|
a = 'Add workspace folder',
|
|
d = 'Type definition',
|
|
e = 'Line diagnostics',
|
|
l = 'Set diagnostics loclist',
|
|
n = 'Rename in buffer',
|
|
o = 'Format buffer',
|
|
r = 'Remove workspace folder',
|
|
w = 'List workspace folders',
|
|
x = 'Signature help',
|
|
f = {
|
|
name = 'Telescope',
|
|
a = {':Telescope lsp_code_actions<CR>', 'Code actions'},
|
|
A = {':Telescope lsp_range_code_actions<CR>', 'Range code actions'},
|
|
d = {':Telescope lsp_document_diagnostics<CR>', 'Buffer diagnostics'},
|
|
D = {':Telescope lsp_workspace_diagnostics<CR>', 'Workspace diagnostics'},
|
|
e = {':Telescope lsp_dynamic_workspace_symbols<CR>', 'Dynamic workspace symbols'},
|
|
i = {':Telescope lsp_implementations<CR>', 'Implementations'},
|
|
n = {':Telescope lsp_definitions<CR>', 'Definitions'},
|
|
r = {':Telescope lsp_references<CR>', 'References'},
|
|
s = {':Telescope lsp_document_symbols<CR>', 'Buffer symbols'},
|
|
S = {':Telescope lsp_workspace_symbols<CR>', 'Workspace symbols'}
|
|
},
|
|
g = {':SymbolsOutline<CR>', 'Symbol outline'},
|
|
t = {
|
|
name = 'Trouble',
|
|
d = {':TroubleToggle lsp_definitions<CR>', 'Definition list'},
|
|
e = {':TroubleToggle lsp_document_diagnostics<CR>', 'Document diagnostics list'},
|
|
w = {':TroubleToggle lsp_workspace_diagnostics<CR>', 'Workspace diagnostics list'},
|
|
l = {':TroubleToggle loclist<CR>', 'Location list items'},
|
|
q = {':TroubleToggle quickfix<CR>', 'Quickfix list'},
|
|
t = {':TroubleToggle<CR>', 'Summary'}
|
|
}
|
|
},
|
|
|
|
r = {
|
|
name = 'REST',
|
|
c = {'<Plug>RestNvim', 'Run request under cursor'},
|
|
p = {'<Plug>RestNvimPreview', 'Preview request cURL command'},
|
|
l = {'<Plug>RestNvimLast', 'Re-run last request'}
|
|
},
|
|
|
|
s = {
|
|
name = 'Find/Replace',
|
|
o = {':lua require("spectre").open()<CR>', 'Open spectre'},
|
|
p = {'viw:lua require("spectre").open_file_search()<CR>', 'Search in current file'},
|
|
w = {':lua require("spectre").open_visual({select_word = true})<CR>', 'Find/replace cursorword'},
|
|
},
|
|
|
|
-- t = {
|
|
-- name = 'Todo',
|
|
-- f = {':TodoQuickFix<CR>', 'Quick fix'},
|
|
-- l = {':TodoLocList<CR>', 'Loclist'},
|
|
-- t = {':TodoTrouble<CR>', 'Open in Trouble'},
|
|
-- z = {':TodoTelescope<CR>', 'Open in Telescope'}
|
|
-- },
|
|
|
|
y ={
|
|
name = 'Figlet',
|
|
s = {':.!figlet -f standard<CR>', 'standard'},
|
|
l = {':.!figlet -f slant<CR>', 'slant'},
|
|
b = {':.!figlet -f banner<CR>', 'banner'},
|
|
e = {':.!figlet -f lean<CR>', 'lean'},
|
|
p = {':.!figlet -f speed<CR>', 'speed'},
|
|
r = {':.!figlet -f roman<CR>', 'roman'},
|
|
d = {':.!figlet -f doh<CR>', 'doh'},
|
|
w = {':.!figlet -f starwars<CR>', 'starwars'},
|
|
m = {':.!figlet -f morse<CR>', 'morse'},
|
|
x = {':.!toilet -f term -F border<CR>', 'border'}
|
|
}
|
|
}, {prefix = '<leader>'})
|
|
|
|
-----------------------------------
|
|
-- Visual mode (with leader key) --
|
|
-----------------------------------
|
|
wk.register({
|
|
a = {':EasyAlign<CR>', 'Range align'},
|
|
|
|
d = {
|
|
name = 'DAP',
|
|
e = {':lua require("dapui").eval()<CR>', 'Evaluate highlighted text'}
|
|
},
|
|
|
|
g = {
|
|
name = 'Git',
|
|
r = 'Reset hunk',
|
|
s = 'Stage hunk'
|
|
},
|
|
|
|
j = {
|
|
name = 'Translate',
|
|
t = {':Trans<CR>', 'Translate'},
|
|
d = {':TransSelectDirection<CR>', 'Translate with direction'},
|
|
r = {'c<C-R>=system(\'trans -brief -no-ansi\', getreg(""))[:-2]<CR>', 'Translate and replace'},
|
|
c = {'c<C-R>=system(\'trans -brief -no-ansi :\', getreg(""))[:-2]<S-Left><S-Left><Right>', 'Translate and replace with direction'}
|
|
},
|
|
|
|
s = {':lua require("spectre").open_visual()<CR>', 'Find/Replace'}
|
|
}, {mode = 'v', prefix = '<leader>'})
|
|
|
|
------------------------
|
|
-- Filetype specified --
|
|
------------------------
|
|
vim.api.nvim_command [[
|
|
autocmd FileType org lua whichkeyOrg()
|
|
autocmd FileType markdown lua whichkeyMarkdown()
|
|
autocmd FileType html lua whichkeyHtml()
|
|
]]
|
|
|
|
_G.whichkeyOrg = function()
|
|
wk.register({
|
|
['<leader>o'] = {
|
|
name = 'Org',
|
|
a = 'Agenda',
|
|
A = 'Toggle ARCHIVE',
|
|
c = 'Capture',
|
|
e = 'Export',
|
|
i = {
|
|
name = 'Insert',
|
|
h = 'Add headline',
|
|
t = 'Add TODO heading and content',
|
|
T = 'Add TODO heading',
|
|
},
|
|
J = 'Move subtree down',
|
|
K = 'Move subtree up',
|
|
o = 'Open at point',
|
|
r = 'Refile',
|
|
t = 'Set tags',
|
|
['$'] = 'Archive current headline'
|
|
},
|
|
['<leader><CR>'] = 'Org meta return',
|
|
['<C-a>'] = 'Org increase date',
|
|
['<C-x>'] = 'Org decrease date',
|
|
['cid'] = 'Org change date',
|
|
['cit'] = 'Org TODO',
|
|
['ciT'] = 'Org TODO prev',
|
|
['<C-Space>'] = 'Org toggle checkbox',
|
|
['<TAB>'] = 'Org cycle folding',
|
|
['<S-TAB>'] = 'Org cycle global folding',
|
|
['<<'] = 'Org promote headline',
|
|
['>>'] = 'Org demote headline',
|
|
['<s'] = 'Org prmote subtree',
|
|
['>s'] = 'Org demote subtree',
|
|
['}'] = 'Org next visible heading',
|
|
['{'] = 'Org previous visible heading',
|
|
[']]'] = 'Org forward heading',
|
|
['[['] = 'Org backward heading',
|
|
['g{'] = 'Org parent heading',
|
|
['?'] = 'Org help'
|
|
})
|
|
end
|
|
|
|
_G.whichkeyMarkdown = function()
|
|
wk.register({
|
|
['<leader>bp'] = {':MarkdownPreviewToggle<CR>', 'Preview markdown'}
|
|
})
|
|
end
|
|
|
|
_G.whichkeyHtml = function()
|
|
wk.register({
|
|
['<leader>bp'] = {':Bracey<CR>', 'Preview html'}
|
|
})
|
|
end
|