nvim/lua/settings.lua

162 lines
4.9 KiB
Lua

-- Personal Configuration keymaps etc.
-- 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
-- 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
-- Decrease update time
vim.o.updatetime = 250
vim.wo.signcolumn = 'yes'
vim.opt.showmode = false
-- Set colorscheme
vim.o.termguicolors = true
vim.cmd [[colorscheme gruvbones]]
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.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.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
-- 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 and pdf
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.tex -o %.pdf<CR>", opts)
map("n", "<leader>zz", ":ZenMode<CR>", opts)
--
-- open my main notes file
if os == "Windows_NT" then
map("n", "<leader>ww", ":e ~/Appdata/Local/nvim/notes/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 ~/.config/nvim/notes/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", "<leader>ps", ":PackerSync<CR>", opts)
map("n", "<M-x>", ":!", opts) -- Meta X like emacs. This is blasphemy....
map("n", "<leder>hrr", ":so%<CR>", opts)
map("n", "<C-n>", ":enew<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>?", ":Telescope oldfiles theme=get_ivy<CR>", opts)
map("n", "<leader><leader>", ":Telescope buffers theme=get_ivy<CR>", opts)
vim.cmd([[hi tkLink ctermfg=Blue 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 = '*',
})