migrated filetype specific mappings from autocommands to ftplugin directory

This commit is contained in:
pr0c3550r 2023-01-16 22:40:43 +01:00
parent 1a490801ab
commit c59c9c8036
4 changed files with 20 additions and 47 deletions

View file

@ -0,0 +1,5 @@
-- Compile c from file
vim.api.nvim_buf_set_keymap(0, "n", "<leader>c", ":exec 'w' <bar> :exec '!gcc % -o %<'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F5>", ":exec 'w' <bar> :exec '!gcc % -o %<'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F5>", ":exec 'w' <bar> :exec '!gcc % -o %<'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", ":exec 'w' <bar> :exec '!gcc % -o %<'<cr>", {})

View file

@ -0,0 +1,5 @@
-- Run python from file
vim.api.nvim_buf_set_keymap(0, "n", "<leader>c", ":exec 'w' <bar> :exec '!python3 %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F5>", ":exec 'w' <bar> :exec '!python3 %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F5>", ":exec 'w' <bar> :exec '!python3 %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", ":exec 'w' <bar> :exec '!python3 %'<cr>", {})

View file

@ -0,0 +1,10 @@
-- Compile LaTeX from file
vim.api.nvim_buf_set_keymap(0, "n", "<leader>c", ":exec 'w' <bar> :exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F5>", ":exec 'w' <bar> :exec 'w' <bar> :exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F5>", ":exec 'w' <bar> :exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", ":exec 'w' <bar> :exec '!xelatex %'<cr>", {})
-- Open PDF-Viewer from LaTeX-file
vim.api.nvim_buf_set_keymap(0, "n", "<F6>", ":silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {})

View file

@ -7,50 +7,3 @@ vim.api.nvim_create_autocmd("Filetype", {
command = "setlocal formatoptions-=c formatoptions-=r formatoptions-=o" command = "setlocal formatoptions-=c formatoptions-=r formatoptions-=o"
}) })
-- Filetype specific mappings
-- Compile and show LaTeX
vim.api.nvim_create_autocmd("Filetype", {
pattern = "tex",
callback = function()
vim.api.nvim_buf_set_keymap(0, "n", "<leader>c", ":exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F5>", ":exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F5>", ":exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", ":exec '!xelatex %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F6>", ":silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F6>", "<esc> :silent !zathura --fork %:r.pdf& <cr>", {})
end
})
-- Compile C
vim.api.nvim_create_autocmd("Filetype", {
pattern = "c",
callback = function()
vim.api.nvim_buf_set_keymap(0, "n", "<leader>c", ":exec '!gcc % -o %<'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F5>", ":exec '!gcc % -o %<'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F5>", ":exec '!gcc % -o %<'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", ":exec '!gcc % -o %<'<cr>", {})
end
})
-- run Python
vim.api.nvim_create_autocmd("Filetype", {
pattern = "python",
callback = function()
vim.api.nvim_buf_set_keymap(0, "n", "<leader>c", ":exec '!python3 %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "n", "<F5>", ":exec '!python3 %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "i", "<F5>", ":exec '!python3 %'<cr>", {})
vim.api.nvim_buf_set_keymap(0, "v", "<F5>", ":exec '!python3 %'<cr>", {})
end
})
-- Close nvim if only Nvim-Tree is open
vim.api.nvim_create_autocmd("BufEnter", {
nested = true,
callback = function()
if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then
vim.cmd "quit"
end
end
})