131 lines
3.3 KiB
Lua
131 lines
3.3 KiB
Lua
-- Set Language {{{
|
|
vim.api.nvim_exec2('language POSIX', {})
|
|
-- }}}
|
|
|
|
-- Source plugins if they exist {{{
|
|
pcall(require, 'plugins')
|
|
-- }}}
|
|
|
|
-- General Editor Settings {{{
|
|
vim.opt.number = true
|
|
vim.opt.relativenumber = true
|
|
vim.opt.cursorline = true
|
|
vim.opt.tabstop = 4
|
|
vim.opt.shiftwidth = 4
|
|
vim.opt.expandtab = false
|
|
vim.opt.list = true
|
|
vim.opt.listchars:append 'space:·'
|
|
vim.opt.path:append '**'
|
|
vim.opt.path:append '.'
|
|
vim.opt.wildmenu = true
|
|
vim.opt.wrap = false
|
|
vim.opt.clipboard = 'unnamedplus'
|
|
vim.opt.ignorecase = true
|
|
vim.opt.smartcase = true
|
|
vim.opt.updatetime = 250
|
|
vim.opt.timeoutlen = 300
|
|
vim.opt.inccommand = 'split'
|
|
vim.opt.foldmethod = 'marker'
|
|
-- }}}
|
|
|
|
-- Setup (Disable) Netrw {{{
|
|
vim.g.loaded_netrw = 1
|
|
vim.g.loaded_netrwPlugin = 1
|
|
--[[
|
|
vim.g.netrw_banner = 0
|
|
vim.g.netrw_sort_sequence = '[\\/]$'
|
|
vim.g.netrw_sort_options = 'i'
|
|
vim.g.netrw_silent = 1
|
|
]]
|
|
-- }}}
|
|
|
|
-- WriteSudo and ReadSudo hacks {{{
|
|
vim.api.nvim_create_user_command('WriteSudo', 'w !sudo tee %', {})
|
|
vim.api.nvim_create_user_command('ReadSudo', function(opts)
|
|
vim.cmd('r !sudo cat ' .. opts['args'])
|
|
end, { nargs = 1 })
|
|
-- }}}
|
|
|
|
-- Statusbar {{{
|
|
vim.opt.statusline = ' #%n %f %h%w%m%r %= %y %l:%c %p%% '
|
|
-- }}}
|
|
|
|
-- FilePicker Script {{{
|
|
local function get_list_completion(arg_lead, cmdline, cur_pos)
|
|
local cmdout = ''
|
|
if (arg_lead == '') then
|
|
cmdout = vim.trim(io.popen('rg --files'):read('*a'))
|
|
else
|
|
local tmp = arg_lead:gsub('\\', '\\\\')
|
|
cmdout = vim.trim(io.popen('rg --files | rg ' .. tmp):read('*a'))
|
|
end
|
|
return vim.split(cmdout, '\n')
|
|
end
|
|
|
|
local function cmd_handler(opts)
|
|
if vim.tbl_count(opts.fargs) == 0 then
|
|
return
|
|
end
|
|
for _, arg in ipairs(opts.fargs) do
|
|
vim.cmd.edit({args = {arg}})
|
|
end
|
|
end
|
|
|
|
vim.api.nvim_create_user_command(
|
|
'FilePick',
|
|
cmd_handler,
|
|
{ complete = get_list_completion, nargs = 1, force = true }
|
|
)
|
|
-- }}}
|
|
|
|
-- Toggle Terminal Script {{{
|
|
local term_buf = nil
|
|
local term_winid = nil
|
|
|
|
local function openTerminal()
|
|
if vim.fn.bufexists(term_buf) ~= 1 then
|
|
vim.api.nvim_command('autocmd TermOpen * setlocal nonumber norelativenumber signcolumn=no')
|
|
vim.api.nvim_command('split | wincmd J | resize 10 | term')
|
|
term_winid = vim.fn.win_getid()
|
|
term_buf = vim.fn.bufnr('%')
|
|
elseif vim.fn.win_gotoid(term_winid) ~= 1 then
|
|
vim.api.nvim_command('sbuffer ' .. term_buf .. '| wincmd J | resize 10')
|
|
term_winid = vim.fn.win_getid()
|
|
end
|
|
vim.api.nvim_command('startinsert')
|
|
end
|
|
|
|
local function hideTerminal()
|
|
if vim.fn.win_gotoid(term_winid) == 1 then
|
|
vim.api.nvim_command('hide')
|
|
end
|
|
end
|
|
|
|
function ToggleTerminal()
|
|
if vim.fn.win_gotoid(term_winid) == 1 then
|
|
hideTerminal()
|
|
else
|
|
openTerminal()
|
|
end
|
|
end
|
|
-- }}}
|
|
|
|
-- Automatic insertmode in Terminal Mode {{{
|
|
vim.api.nvim_create_autocmd({ 'TermOpen' }, {
|
|
pattern = { 'term://*' },
|
|
command = 'startinsert',
|
|
})
|
|
-- }}}
|
|
|
|
-- Keymaps {{{
|
|
vim.keymap.set('n', '<F6>', ':b#<CR>', { noremap = true, silent = true })
|
|
vim.keymap.set('n', '<F7>', ':bprevious<CR>', { noremap = true, silent = true })
|
|
vim.keymap.set('n', '<F8>', ':bnext<CR>', { noremap = true, silent = true })
|
|
--vim.keymap.set('n', '<leader>f', ':find ', { noremap = true })
|
|
--vim.keymap.set('n', '<leader>f', ':FilePick ', { noremap = true })
|
|
vim.keymap.set('n', '<leader>t', ToggleTerminal)
|
|
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>')
|
|
vim.keymap.set('n', 'x', '"_x')
|
|
vim.keymap.set('n', '<leader>b', ':buffers<CR>:buffer ', { noremap = true, silent = true })
|
|
-- }}}
|