kickstart.nvim/lua/custom/plugins/base.lua

75 lines
2.1 KiB
Lua
Raw Normal View History

-- Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
2023-04-12 11:12:31 +02:00
vim.o.wrap = true
-- Copy to clipboard
2023-04-12 11:12:31 +02:00
local has_unnamedplus = vim.fn.has 'unnamedplus'
if has_unnamedplus then
2023-04-12 11:12:31 +02:00
vim.o.clipboard = 'unnamedplus'
end
vim.api.nvim_buf_set_keymap(0, 'n', 'y', '"+y', { noremap = true, silent = true })
vim.api.nvim_buf_set_keymap(0, 'n', 'p', '"+p', { noremap = true, silent = true })
local function set_json_filetype()
2023-04-12 11:12:31 +02:00
if string.match(vim.api.nvim_buf_get_name(0), '%.geojson$') or string.match(vim.api.nvim_buf_get_name(0), '%.json$') then
-- vim.filetype('json')
vim.api.nvim_buf_set_option(0, 'filetype', 'json')
end
end
2023-04-12 11:12:31 +02:00
vim.api.nvim_create_autocmd({ 'BufReadPost' }, { pattern = { '*.geojson', '*.bson' }, callback = set_json_filetype })
function Format()
2023-04-12 11:12:31 +02:00
vim.lsp.buf.format(nil, 100)
end
2023-04-12 11:12:31 +02:00
vim.api.nvim_create_autocmd({ 'BufWritePre' }, { pattern = { '*' }, callback = Format })
function Macos()
2023-04-12 11:12:31 +02:00
return vim.fn.has 'mac' == 1
end
function Linux()
2023-04-12 11:12:31 +02:00
if package.os == 'Linux' then
return true
end
if vim.fn.has 'unix' and not vim.fn.has 'macunix' and not vim.fn.has 'win32unix' and not vim.fn.has 'win64unix' then
return true
end
return false
end
function Windows()
2023-04-12 11:12:31 +02:00
return vim.fn.has 'win32' == 1 or vim.fn.has 'win64' == 1
end
function OpenBuffer()
2023-04-12 11:12:31 +02:00
if Macos() then
vim.cmd('silent !open ' .. vim.fn.expand '%:p')
-- vim.cmd('silent !open -a "Google Chrome" ' .. vim.fn.expand('%:p'))
elseif Linux() then
vim.cmd('silent !xdg-open ' .. vim.fn.expand '%:p')
elseif Windows() then
vim.cmd('silent !start ' .. vim.fn.expand '%:p')
end
end
2023-04-12 11:12:31 +02:00
vim.keymap.set('n', '<leader>vob', OpenBuffer, { noremap = true })
-- vim.keymap.set("n", "<leader>e", vim.lsp.diagnostic.show_line_diagnostics, { noremap = true, silent = true })
--
local function prettify_json()
2023-04-12 11:12:31 +02:00
vim.api.nvim_command '%!jq .'
end
local function uglify_json()
2023-04-12 11:12:31 +02:00
vim.api.nvim_command '%!jq -c .'
end
2023-04-12 11:12:31 +02:00
vim.keymap.set('n', '<leader>jq', prettify_json, { noremap = true })
vim.keymap.set('n', '<leader>ujq', uglify_json, { noremap = true })
return {}