dotfiles/.config/nvim/lua/blake/settings.lua

179 lines
5.5 KiB
Lua
Raw Normal View History

local set = vim.o
local autocmd = vim.api.nvim_create_autocmd
-- Settings
local tabsize = 3
set.tabstop = tabsize
set.softtabstop = tabsize
set.shiftwidth = tabsize
set.suffixes = '.bak,~,.o,.h,.info,.swp,.obj,.aux,.bbl,.blg,.brf,.cb,.dvi,.idx,.ilg,.ind,.inx,.jpg,.log,.out,.png,.toc'
set.expandtab = true
set.smartindent = true
set.undofile = true
set.swapfile = true
set.hlsearch = true
set.hidden = true
set.backspace = 'indent,eol,start'
set.ignorecase = true
set.smartcase = true
set.showmode = false
set.wrap = false
set.linebreak = true
set.redrawtime = 200
set.updatetime = 300
2021-11-22 01:13:34 -08:00
set.number = true
2022-07-12 14:42:27 -07:00
set.relativenumber = true
set.errorbells = false
set.encoding = 'UTF-8'
set.cursorline = true
set.mouse = 'a'
set.incsearch = true
set.scrolloff = 5
set.hidden = true
2022-08-25 18:00:18 -07:00
set.shortmess = 'filnxtToOFc' -- the funny thing is, this *is* a short mess
2021-12-02 03:01:45 -08:00
set.spell = true
set.spelllang = 'en_us'
set.showcmd = true
set.signcolumn = 'yes'
set.makeprg = 'make -j$(nproc)'
set.ruler = false
2022-08-08 17:24:59 -07:00
set.listchars = 'trail:~,tab:│ ,nbsp:␣,lead:·,extends:…,precedes:…'
set.list = false
set.mousemodel = 'extend'
2024-06-21 21:09:31 -07:00
set.exrc = true
set.secure = true
-- Disable smartindent when editing `nix` files
autocmd("BufEnter", { pattern = "*.nix", callback = function() vim.opt_local.smartindent = false end })
-- Syntax highlighting for faust files
autocmd("BufEnter", { pattern = "*.dsp", callback = function() vim.opt_local.filetype = 'c' end })
autocmd("BufEnter", { pattern = "*.lib", callback = function() vim.opt_local.filetype = 'c' end })
2021-11-22 01:13:34 -08:00
----------------------------------------------
--- Key bindings (needs to be translated?) ---
----------------------------------------------
2023-03-22 21:12:57 -07:00
vim.g.mapleader = " "
-- *sigh*...
2021-09-03 01:18:44 -07:00
vim.cmd [[
cab Q q
cab W w
cab Wq wq
cab WQ wq
cab Wa wa
cab WA wa
cab Qa qa
cab QA qa
cab Wqa wqa
cab WQa wqa
cab WQA wqa
2021-10-01 01:34:19 -07:00
]]
-- Go to previous file, but faster
vim.cmd 'cab P previous'
-- Macro for opening a terminal in a new tab
vim.cmd 'command! Term tabnew | term'
-- Genereate ctags
vim.cmd 'cab MakeTags !ctags -R .'
-- Toggle spell check with alt S
vim.cmd 'nnoremap <M-S> <cmd>set spell! spell?<CR>'
-- Toggle wrap with alt W
vim.cmd 'nnoremap <M-W> <cmd>set wrap! wrap?<CR>'
-- find + replace with alt S
vim.cmd 'nnoremap <M-s> :%s//g<Left><Left>'
2022-04-25 14:01:33 -07:00
-- find + replace a word with alt S
vim.cmd 'nnoremap <M-w> ye:%s//g<Left><Left><C-r>"/'
-- open current file with nvim in alacritty (useful if it gets opened in some other terminal)
2023-04-26 21:48:25 -07:00
vim.cmd "nnoremap <M-a> <cmd>!nohup alacritty -e nvim '%' > /dev/null 2>&1 &; disown<CR><cmd>q<CR>"
2022-04-25 14:01:33 -07:00
-- Escape to enter normal mode in the terminal
vim.cmd 'tnoremap <C-\\> <C-\\><C-n>'
vim.cmd 'nnoremap <silent> <Leader>= :exe "resize " . (winheight(0) * 3/2)<CR>'
vim.cmd 'nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>'
vim.cmd 'nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>'
-- Switch panes with ctrl hjkl
vim.cmd 'nnoremap <C-h> <C-w>h'
vim.cmd 'nnoremap <C-j> <C-w>j'
vim.cmd 'nnoremap <C-k> <C-w>k'
-- Spell correct with Q, rather than z=
2022-03-05 22:34:48 -08:00
vim.cmd 'nnoremap Q z='
2021-11-22 01:13:34 -08:00
-- Scroll full pages without moving the cursor (like it should!)
vim.cmd 'nnoremap  <C-u><C-u>'
vim.cmd 'nnoremap  <C-d><C-d>'
2021-11-22 01:13:34 -08:00
----------------------------------------------
--- Things that can't be translated to lua ---
----------------------------------------------
vim.cmd 'let g:markdown_fenced_languages = [ "bash=sh", "javascript", "cpp=cpp", "c++=cpp", "js=javascript", "json=javascript", "typescript", "ts=typescript", "php", "html", "css", "yml=yaml", "yaml" ]'
2021-11-22 01:13:34 -08:00
--- autocmd's ---
-- Set comment strings
2022-08-14 15:54:51 -07:00
vim.cmd 'autocmd FileType crontab setlocal commentstring=#%s'
-- vim.cmd 'autocmd FileType rmd set commentstring=<!--\\ %s\\ -->'
-- Enable linewrap in markdown files
vim.cmd [[ autocmd FileType markdown setlocal wrap ]]
2021-12-02 03:01:45 -08:00
-- Automatically jump to the last position in a file when opening
vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]]
2021-11-22 01:13:34 -08:00
-- Spell check in git commits by default
vim.cmd 'autocmd Filetype gitcommit setlocal spell'
-- Disable spell check in help files
vim.cmd 'autocmd FileType help setlocal nospell'
vim.cmd 'filetype plugin on'
-- .dsp and .lib files are faust
vim.cmd 'autocmd BufReadPost *.dsp setlocal ft=faust'
vim.cmd 'autocmd BufReadPost *.lib setlocal ft=faust'
2021-11-22 01:13:34 -08:00
-- Automatically disable line numbers when in terminal mode
vim.cmd 'autocmd TermOpen * setlocal nospell nonumber norelativenumber'
-- Automatically toggle relative line numbers
-- vim.cmd 'autocmd InsertEnter * :set norelativenumber '
-- vim.cmd 'autocmd InsertLeave * :set relativenumber '
2021-10-01 01:34:19 -07:00
-- Make vim a hex editor
-- Edit *.bin files as binaries rather than text files
-- (if your file isn't a .bin, do this: `ln -s $file $file.bin; vim $file`)
2021-10-01 01:34:19 -07:00
vim.cmd [[
2022-01-19 19:54:24 -08:00
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
2021-09-03 01:18:44 -07:00
]]
-- 'Visual At' plugin (https://github.com/stoeffel/.dotfiles/blob/master/vim/visual-at.vim)
-- Basically, record a macro that effects one line, select some lines, then run
-- it, and the macro will be executed on all visual selected lines individually
2021-09-03 01:18:44 -07:00
vim.cmd [[
2021-10-01 01:34:19 -07:00
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
function! ExecuteMacroOverVisualRange()
2021-12-16 14:41:57 -08:00
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
2021-10-01 01:34:19 -07:00
endfunction
2021-09-03 01:18:44 -07:00
]]
-- vim: nospell