178 lines
5.5 KiB
Lua
178 lines
5.5 KiB
Lua
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
|
||
set.number = true
|
||
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
|
||
set.shortmess = 'filnxtToOFc' -- the funny thing is, this *is* a short mess
|
||
set.spell = true
|
||
set.spelllang = 'en_us'
|
||
set.showcmd = true
|
||
set.signcolumn = 'yes'
|
||
set.makeprg = 'make -j$(nproc)'
|
||
set.ruler = false
|
||
set.listchars = 'trail:~,tab:│ ,nbsp:␣,lead:·,extends:…,precedes:…'
|
||
set.list = false
|
||
set.mousemodel = 'extend'
|
||
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 })
|
||
|
||
----------------------------------------------
|
||
--- Key bindings (needs to be translated?) ---
|
||
----------------------------------------------
|
||
|
||
vim.g.mapleader = " "
|
||
|
||
-- *sigh*...
|
||
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
|
||
]]
|
||
|
||
-- 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>'
|
||
|
||
-- 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)
|
||
vim.cmd "nnoremap <M-a> <cmd>!nohup alacritty -e nvim '%' > /dev/null 2>&1 &; disown<CR><cmd>q<CR>"
|
||
|
||
-- 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=
|
||
vim.cmd 'nnoremap Q z='
|
||
|
||
-- Scroll full pages without moving the cursor (like it should!)
|
||
vim.cmd 'nnoremap <C-u><C-u>'
|
||
vim.cmd 'nnoremap <C-d><C-d>'
|
||
|
||
----------------------------------------------
|
||
--- 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" ]'
|
||
|
||
--- autocmd's ---
|
||
-- Set comment strings
|
||
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 ]]
|
||
|
||
-- 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 ]]
|
||
|
||
-- 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'
|
||
|
||
-- 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 '
|
||
|
||
-- 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`)
|
||
vim.cmd [[
|
||
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
|
||
]]
|
||
|
||
-- '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
|
||
vim.cmd [[
|
||
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
|
||
function! ExecuteMacroOverVisualRange()
|
||
echo "@".getcmdline()
|
||
execute ":'<,'>normal @".nr2char(getchar())
|
||
endfunction
|
||
]]
|
||
|
||
-- vim: nospell
|