nvim/lua/settings.lua

237 lines
8.0 KiB
Lua

-- Personal Configuration keymaps
-- Variables declarations
-- [[ Setting options ]]
-- See `:help vim.o`
-- Set highlight on search
vim.o.hlsearch = false
-- Make line numbers default
vim.wo.number = true
vim.wo.relativenumber = true
-- vim.wo.conceallevel = 2
-- Enable mouse mode
vim.o.mouse = 'a'
-- Enable break indent
vim.o.breakindent = true
-- Save undo history
vim.o.undofile = true
-- Case insensitive searching UNLESS /C or capital in search
vim.o.ignorecase = true
vim.o.smartcase = true
vim.cmd([[highlight clear LineNr]])
vim.cmd([[highlight clear SignColumn]])
-- Decrease update time
vim.o.updatetime = 250
vim.wo.signcolumn = 'yes'
vim.opt.showmode = false
-- Set colorscheme
vim.o.termguicolors = true
vim.cmd([[colorscheme jpbones]])
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
local os = vim.loop.os_uname().sysname
vim.keymap.set("n", "<bs>", ":edit #<cr>", { silent = true })
-- Blink cursor:
vim.cmd([[set guicursor+=a:-blinkwait175-blinkoff150-blinkon175]])
-- vim.cmd([[let g:vim_markdown_conceal = 2]])
vim.cmd([[hi Normal guibg=NONE ctermbg=NONE]])
vim.opt.scrolloff = 5
vim.opt.splitbelow = true
vim.opt.splitright = true
vim.opt.colorcolumn = "81"
vim.opt.clipboard = "unnamedplus"
vim.opt.autochdir = true
vim.opt.showtabline = 1
vim.opt.conceallevel = 2
-- vim.opt.syntax = "on"
-- vim.opt.concealcursor = 'nc'
-- vim.cmd(':hi CursorLineNr gui=None ctermfg=11 guifg=foreground')
vim.opt.cursorline = false
-- Do not load tohtml.vim
vim.g.loaded_2html_plugin = 1
-- Tabs keys
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
vim.g.rst_syntax_code_list = { "python", "lua" }
-- 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
-- Keymaps
-- git
map("n", "<leader>gs", ":Telescope git_status<cr>", opts)
map("n", "<leader>gc", ":Telescope git_commits<cr>", opts)
map("n", "<leader>gb", ":Telescope git_branches<cr>", opts)
-- Personal things
-- Move windows:
map("n", "<C-h>", "<C-W>h", opts)
map("n", "<C-j>", "<C-W>j", opts)
map("n", "<C-k>", "<C-W>k", opts)
map("n", "<C-l>", "<C-W>l", opts)
-- Move in insert mode like in nirmal mode hjkl:
map("i", "<C-h>", "<Left>", opts)
map("i", "<C-j>", "<Down>", opts)
map("i", "<C-k>", "<Up>", opts)
map("i", "<C-l>", "<Right>", opts)
-- barbar mappings --
-- Move to previous/next
map("n", "<A-,>", ":bprevious<CR>", opts)
map("n", "<A-.>", ":bnext<CR>", opts)
map("n", "<A-q>", ":bd<CR>", opts)
-- documents markdown, pdf & norg files.
map("n", "<leader>pdf", ":silent ! latexpdf % <CR>", opts)
map("n", "<leader>md", ":MarkdownPreview<CR>", opts)
map("n", "<leader>doc",
":silent ! pandoc ./% --pdf-engine=xelatex --template eisvogel -o ./format/pdf/%.pdf<CR>", opts)
map("n", "<leader>ne", ":Neorg export to-file<CR>", opts)
map("n", "<leader>zz", ":ZenMode<CR>", opts)
--
-- open my main notes file
if os == "Windows_NT" then
map("n", "<leader>ww", ":e ~/zet/index.md<CR> :cd <CR>", opts)
map("n", "<leader>ecf", ":e ~/Appdata/Local/nvim/init.lua<CR> :cd<CR>", opts)
elseif os == "Linux" then
map("n", "<leader>ww", ":e ~/zet/index.md<CR> :cd<CR>", opts)
map("n", "<leader>ecf", ":e ~/.config/nvim/init.lua<CR> :cd<CR>", opts)
end
map("n", "<C-S>", ":%s/\\<<C-r><C-w>\\>//gI<Left><Left><Left>", opts)
map("v", "<", "<gv", opts)
map("v", ">", ">gv", opts)
map("n", "<M-x>", ":!", opts) -- Meta X like emacs. This is blasphemy....
map("n", "<leder>hrr", ":so%<CR>", opts)
map("i", "jk", "<Esc>l", opts)
map("i", "jj", "<Esc>l", opts)
map("i", "qw", "<Esc>$", opts)
map("n", "cw", "ciw", opts)
map("n", "vw", "viw", opts)
map("n", "<esc>", ":noh<return><esc>", opts)
map("n", "<f12>", ":!python %<CR>", opts)
map("n", "<f9>", ":setlocal spell! spelllang=en<CR>", opts)
map("n", "<f10>", ":setlocal spell! spelllang=es<CR>", opts)
map("i", "<M->>", "<C-x>s", opts)
map("n", "<leader><leader>e", ":Ex<CR>", opts)
map("n", "<leader>ni", ":Neorg index<CR>", opts)
map("n", "<leader>?", ":Telescope oldfiles theme=get_ivy<CR>", opts)
map("n", "<leader>,", ":Telescope buffers theme=get_ivy<CR>", opts)
vim.cmd([[hi tkLink ctermfg=Cyan cterm=bold,underline guifg=blue gui=bold,underline]])
vim.cmd([[hi tkBrackets ctermfg=gray guifg=gray]])
-- Keymaps for better default experience
-- See `:help vim.keymap.set()`
-- vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- [[ Highlight on yank ]]
-- See `:help vim.highlight.on_yank()`
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
group = highlight_group,
pattern = '*',
})
-- [[ LSP diagnositcs ]]
vim.api.nvim_set_keymap('n', '<leader>do', '<cmd>lua vim.diagnostic.open_float()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>d[', '<cmd>lua vim.diagnostic.goto_prev()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('n', '<leader>d]', '<cmd>lua vim.diagnostic.goto_next()<CR>', { noremap = true, silent = true })
-- The following command requires plug-ins "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim", and optionally "kyazdani42/nvim-web-devicons" for icon support
vim.api.nvim_set_keymap('n', '<leader>dd', '<cmd>Telescope diagnostics<CR>', { noremap = true, silent = true })
-- If you don't want to use the telescope plug-in but still want to see all the errors/warnings, comment out the telescope line and uncomment this:
-- vim.api.nvim_set_keymap('n', '<leader>dd', '<cmd>lua vim.diagnostic.setloclist()<CR>', { noremap = true, silent = true })
vim.keymap.set(
"",
"<Leader>l",
require("lsp_lines").toggle,
{ desc = "Toggle lsp_lines" }
)
-- [[ Terminal ]]
map("n", "<leader>.", ":ToggleTerm direction=float<CR>", opts)
-- [[ nvim-tree ]]
map("n", "<leader><leader>", ":NvimTreeToggle<CR>", opts)
vim.api.nvim_create_autocmd("QuitPre", {
callback = function()
local invalid_win = {}
local wins = vim.api.nvim_list_wins()
for _, w in ipairs(wins) do
local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w))
if bufname:match("NvimTree_") ~= nil then
table.insert(invalid_win, w)
end
end
if #invalid_win == #wins - 1 then
-- Should quit, so we close all invalid windows.
for _, w in ipairs(invalid_win) do vim.api.nvim_win_close(w, true) end
end
end
})
-- [[ Venn.nvim ]]
function _G.Toggle_venn()
local venn_enabled = vim.inspect(vim.b.venn_enabled)
if venn_enabled == "nil" then
vim.b.venn_enabled = true
vim.cmd [[setlocal ve=all]]
-- draw a line on HJKL keystokes
vim.api.nvim_buf_set_keymap(0, "n", "J", "<C-v>j:VBox<CR>", { noremap = true })
vim.api.nvim_buf_set_keymap(0, "n", "K", "<C-v>k:VBox<CR>", { noremap = true })
vim.api.nvim_buf_set_keymap(0, "n", "L", "<C-v>l:VBox<CR>", { noremap = true })
vim.api.nvim_buf_set_keymap(0, "n", "H", "<C-v>h:VBox<CR>", { noremap = true })
-- draw a box by pressing "f" with visual selection
vim.api.nvim_buf_set_keymap(0, "v", "f", ":VBox<CR>", { noremap = true })
else
vim.cmd [[setlocal ve=]]
vim.cmd [[mapclear <buffer>]]
vim.b.venn_enabled = nil
end
end
-- toggle keymappings for venn using <leader>v
vim.api.nvim_set_keymap('n', '<leader>v', ":lua Toggle_venn()<CR>", { noremap = true })