nvim: Reorganization - moved all config files to one folder (minus the init.lua)

This commit is contained in:
PowerUser64 2021-09-24 21:20:05 -07:00
parent 9161bd14d9
commit 5927e8c247
5 changed files with 17 additions and 17 deletions

View file

@ -0,0 +1,290 @@
local M = {}
-- lsp_signature >>>
M.signature = function()
require "lsp_signature".setup()
cfg = {
Gse_lspsaga = true
}
end -- <<<
-- lspinstall >>>
M.lspinstall = function() --
local function setup_servers()
require'lspinstall'.setup()
local servers = require'lspinstall'.installed_servers()
for _, server in pairs(servers) do
require'lspconfig'[server].setup{}
end
end
setup_servers()
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
require'lspinstall'.post_install_hook = function ()
setup_servers() -- reload installed servers
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
end
end -- <<<
-- treesitter >>>
M.treesitter = function()
require('nvim-treesitter.configs').setup {
highlight = {
enable = true, -- false will disable the whole extension
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = 'gnn',
node_incremental = 'grn',
scope_incremental = 'grc',
node_decremental = 'grm',
},
},
indent = {
enable = true,
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
},
}
-- require'nvim-treesitter.configs'.setup {
-- ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
-- --ignore_install = { "javascript", "java" }, -- List of parsers to ignore installing
-- highlight = {
-- enable = true, -- false will disable the whole extension
-- -- disable = { "c", "rust" }, -- list of language that will be disabled
-- -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- -- Using this option may slow down your editor, and you may see some duplicate highlights.
-- -- Instead of true it can also be a list of languages
-- additional_vim_regex_highlighting = false,
-- },
-- indent = {
-- enable = true
-- }
-- }
end -- <<<
-- cmp >>>
M.cmp = function()
-- nvim-cmp supports additional completion capabilities
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- luasnip setup
-- local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
-- expand = function(args)
-- require('luasnip').lsp_expand(args.body)
-- end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
['<Tab>'] = function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n')
-- elseif luasnip.expand_or_jumpable() then
-- vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '')
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n')
-- elseif luasnip.jumpable(-1) then
-- vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '')
else
fallback()
end
end,
},
sources = {
{ name = 'path' },
{ name = 'buffer' },
{ name = 'calc' },
-- { name = 'luasnip' },
{ name = 'nvim_lsp' },
{ name = 'nvim_lua' },
{ name = 'spell' },
{ name = 'treesitter' },
{ name = 'emoji' },
},
formatting = {
format = function(entry, vim_item)
-- fancy icons and a name of kind
vim_item.kind = require("lspkind").presets.default[vim_item.kind] .. " " .. vim_item.kind
-- set a name for each source
vim_item.menu = ({
path = "[Path]",
buffer = "[Buffer]",
calc = "[Calc]",
-- luasnip = "[LuaSnip]",
nvim_lsp = "[LSP]",
nvim_lua = "[Lua]",
spell = "[Spell]",
treesitter = "[TS]",
})[entry.source.name]
return vim_item
end,
},
}
end -- <<<
-- lspconfig >>>
M.lspconfig = function()
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local lsp_servers = {
clangd = 'clangd',
html = 'vscode-html-language-server',
}
for lsp, exe in pairs(lsp_servers) do
if (vim.fn.executable(exe) == 1) then
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
end
end -- <<<
-- DAP: Debug Adapter Protocol >>>
M.dap = function()
-- keybinds
vim.cmd [[
" Debugger movement
nnoremap <silent> <leader>d<space> <cmd>lua require'dap'.continue()<CR>
nnoremap <silent> <leader>dj <cmd>lua require'dap'.step_over()<CR>
nnoremap <silent> <leader>dl <cmd>lua require'dap'.step_into()<CR>
nnoremap <silent> <leader>dh <cmd>lua require'dap'.step_out()<CR>
" Breakpoints
nnoremap <silent> <leader>dbb <cmd>lua require'dap'.toggle_breakpoint()<CR>
nnoremap <silent> <leader>dbc <cmd>lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition<cmd> '))<CR>
nnoremap <silent> <leader>dbl <cmd>lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message<cmd> '))<CR>
" Extra
nnoremap <silent> <leader>dp <cmd>lua require'dap'.run_last()<CR>
nnoremap <silent> <leader>dr <cmd>lua require'dap'.repl.open()<CR>
]]
-- vim.fn.sign_define('DapBreakpoint', {text='B', texthl='', linehl='', numhl=''}) -- custom attributes of breakpointed lines (use an emoji?)
vim.cmd "au FileType dap-repl lua require('dap.ext.autocompl').attach()"
-- per-language config:
local dap = require('dap')
-- c++ dap congiguration >>>
dap.configurations.cpp = {
{
name = "Launch file",
type = "cppdbg",
request = "launch",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
stopOnEntry = true,
},
}
dap.adapters.cppdbg = {
type = 'executable',
command = '/home/blake/.local/share/nvim/dapinstall/ccppr_vsc/extension/debugAdapters/bin/OpenDebugAD7',
}
-- <<<
end -- <<<
-- DAP installer >>>
M.dapinstall = function()
local dap_install = require("dap-install")
dap_install.setup({
installation_path = vim.fn.stdpath("data") .. "/dapinstall/",
})
end -- <<<
return M
-- vim:fdm=marker:fmr=>>>,<<<:expandtab:tabstop=3:sw=3

View file

@ -0,0 +1,195 @@
local M = {}
-- nvimtree >>>
M.nvimtree = function ()
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
-- default mappings
vim.g.nvim_tree_bindings = {
{ key = {"<CR>", "o", "<2-LeftMouse>"}, cb = tree_cb("edit") },
{ key = {"<2-RightMouse>", "<C-]>"}, cb = tree_cb("cd") },
{ key = "<C-v>", cb = tree_cb("vsplit") },
{ key = "<C-x>", cb = tree_cb("split") },
{ key = "<C-t>", cb = tree_cb("tabnew") },
{ key = "<", cb = tree_cb("prev_sibling") },
{ key = ">", cb = tree_cb("next_sibling") },
{ key = "P", cb = tree_cb("parent_node") },
{ key = "<BS>", cb = tree_cb("close_node") },
{ key = "<S-CR>", cb = tree_cb("close_node") },
{ key = "<Tab>", cb = tree_cb("preview") },
{ key = "K", cb = tree_cb("first_sibling") },
{ key = "J", cb = tree_cb("last_sibling") },
{ key = "I", cb = tree_cb("toggle_ignored") },
{ key = "H", cb = tree_cb("toggle_dotfiles") },
{ key = "R", cb = tree_cb("refresh") },
{ key = "a", cb = tree_cb("create") },
{ key = "d", cb = tree_cb("remove") },
{ key = "r", cb = tree_cb("rename") },
{ key = "<C-r>", cb = tree_cb("full_rename") },
{ key = "x", cb = tree_cb("cut") },
{ key = "c", cb = tree_cb("copy") },
{ key = "p", cb = tree_cb("paste") },
{ key = "y", cb = tree_cb("copy_name") },
{ key = "Y", cb = tree_cb("copy_path") },
{ key = "gy", cb = tree_cb("copy_absolute_path") },
{ key = "[c", cb = tree_cb("prev_git_item") },
{ key = "]c", cb = tree_cb("next_git_item") },
{ key = "-", cb = tree_cb("dir_up") },
{ key = "s", cb = tree_cb("system_open") },
{ key = "q", cb = tree_cb("close") },
{ key = "g?", cb = tree_cb("toggle_help") },
}
end -- <<<
-- toggleterm >>>
M.toggleterm = function()
require("toggleterm").setup{
-- size can be a number or function which is passed the current terminal
size = function(term)
if term.direction == "horizontal" then
return 15
elseif term.direction == "vertical" then
return vim.o.columns * 0.4
end
end,
open_mapping = [[<F12>]],
hide_numbers = true, -- hide the number column in toggleterm buffers
shade_filetypes = {},
shade_terminals = true,
shading_factor = '1', -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light
start_in_insert = true,
insert_mappings = true, -- whether or not the open mapping applies in insert mode
persist_size = true,
direction = 'float', -- vertical, horizontal, window, or float
close_on_exit = true, -- close the terminal window when the process exits
-- shell = vim.o.shell, -- change the default shell
-- This field is only relevant if direction is set to 'float'
float_opts = {
-- The border key is *almost* the same as 'nvim_open_win'
-- see :h nvim_open_win for details on borders however
-- the 'curved' border is a custom border type
-- not natively supported but implemented in this plugin.
border = 'curved', -- single, double, shadow, or curved
width = 200,
height = 50,
winblend = 10, -- transparancy
highlights = {
border = "Normal",
background = "Normal",
}
}
}
end -- <<<
-- gitsigns >>>
M.gitsigns = function()
require('gitsigns').setup {
signs = {
add = {hl = 'GitSignsAdd' , text = '', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'},
change = {hl = 'GitSignsChange', text = '', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
topdelete = {hl = 'GitSignsDelete', text = '', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
},
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
keymaps = {
-- Default keymap options
noremap = true,
['n ]c'] = { expr = true, "&diff ? ']c' : '<cmd>lua require\"gitsigns.actions\".next_hunk()<CR>'"},
['n [c'] = { expr = true, "&diff ? '[c' : '<cmd>lua require\"gitsigns.actions\".prev_hunk()<CR>'"},
['n <leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
['n <leader>hu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
['n <leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
['v <leader>hs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['v <leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['n <leader>hp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
['n <leader>hb'] = '<cmd>lua require"gitsigns".blame_line(true)<CR>',
['n <leader>hS'] = '<cmd>lua require"gitsigns".stage_buffer()<CR>',
['n <leader>hR'] = '<cmd>lua require"gitsigns".reset_buffer()<CR>',
['n <leader>hU'] = '<cmd>lua require"gitsigns".reset_buffer_index()<CR>',
-- Text objects
['o ih'] = '<cmd><C-U>lua require"gitsigns.actions".select_hunk()<CR>',
['x ih'] = '<cmd><C-U>lua require"gitsigns.actions".select_hunk()<CR>'
},
watch_index = {
interval = 1000,
follow_files = true
},
attach_to_untracked = true,
current_line_blame = false, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = 'eol', -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
},
current_line_blame_formatter_opts = {
relative_time = false
},
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000,
preview_config = {
-- Options passed to nvim_open_win
border = 'single',
style = 'minimal',
relative = 'cursor',
row = 0,
col = 1
},
yadm = {
enable = false
},
}
end -- <<<
-- neoscroll for smooth scrolling >>>
M.neoscroll = function()
require('neoscroll').setup({
-- All these keys will be mapped to their corresponding default scrolling animation
mappings = {'<C-u>', '<C-d>', '<C-b>', '<C-f>',
'<C-y>', '<C-e>', 'zt', 'zz', 'zb',},
hide_cursor = true, -- Hide cursor while scrolling
stop_eof = true, -- Stop at <EOF> when scrolling downwards
use_local_scrolloff = false, -- Use the local scope of scrolloff instead of the global scope
respect_scrolloff = false, -- Stop scrolling when the cursor reaches the scrolloff margin of the file
cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further
easing_function = 'sine', -- use sine easing function
pre_hook = nil, -- Function to run before the scrolling animation starts
post_hook = nil, -- Function to run after the scrolling animation ends
})
end
-- <<<
-- Autosession >>>
M.autosession = function()
local opts = {
log_level = 'info',
auto_session_enable_last_session = true,
auto_session_root_dir = vim.fn.stdpath('data').."/sessions/",
auto_session_enabled = true,
auto_save_enabled = false,
auto_restore_enabled = true,
auto_session_suppress_dirs = nil,
}
require('auto-session').setup(opts)
-- save some more things. notably options, resize, winpos, and terminal
vim.o.sessionoptions="blank,buffers,curdir,folds,help,options,tabpages,winsize,resize,winpos,terminal"
-- So I don't forget which one it is
vim.cmd 'command! SessionSave SaveSession'
vim.cmd 'command! SessionDelete DeleteSession'
vim.cmd 'command! SessionRestore RestoreSession'
end -- <<<
return M
-- vim:fdm=marker:fmr=>>>,<<<:expandtab:tabstop=3:sw=3

View file

@ -0,0 +1,185 @@
-- Load plugins
-- Bootstrap packer if needed {
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd 'packadd packer.nvim'
end
-- }
return require('packer').startup(function()
-- Packer
use { -- packer
'wbthomason/packer.nvim'
}
-- Colors
use { -- syntax highlighting
'nvim-treesitter/nvim-treesitter', run = ':TSUpdate',
config = function()
require("blake.lsp").treesitter()
end,
}
use { -- onedark theme
'navarasu/onedark.nvim',
config = function()
-- vim.g.onedark_transparent_background = true,
require('onedark').setup()
end
}
use { -- color tag highlighter
'norcalli/nvim-colorizer.lua'
}
-- IDE features
---- LSP
use { -- lsp installer
"kabouzeid/nvim-lspinstall",
-- opt = true,
-- setup = function()
-- require("blake.other").packer_lazy_load "nvim-lspinstall"
-- -- reload the current file so lsp actually starts for it
-- vim.defer_fn(function()
-- vim.cmd "silent! e %"
-- end, 0)
-- end,
}
use { -- DAP: Debug Adapter Protocol
"mfussenegger/nvim-dap",
config = function()
require("blake.lsp").dap()
end
}
use { -- DAP adapter installer
"Pocco81/DAPInstall.nvim",
config = function()
require("blake.lsp").dapinstall()
end
}
use { -- Default LSP configs
"neovim/nvim-lspconfig",
after = "nvim-lspinstall",
config = function()
require("blake.lsp").lspconfig()
end
}
use { -- Icons for each entry in the completion menu
"onsails/lspkind-nvim",
}
use { -- compe
"hrsh7th/nvim-cmp",
config = function()
require('blake.lsp').cmp()
end,
requires = { -- nvim-cmp sources
-- "saadparwaiz1/cmp_luasnip", --luasnip integration
"hrsh7th/cmp-path",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-nvim-lua",
"hrsh7th/cmp-latex-symbols",
"hrsh7th/cmp-emoji",
"hrsh7th/cmp-calc",
"hrsh7th/cmp-look",
}
}
-- use { -- code snippits
-- "L3MON4D3/LuaSnip",
-- -- "hrsh7th/vim-vsnip",
-- -- "rafamadriz/friendly-snippets",
-- }
use { -- function parameter previews
"ray-x/lsp_signature.nvim",
after = "nvim-lspconfig",
config = function()
require("blake.lsp").signature()
end,
}
use { -- Use the % key for more things
"andymass/vim-matchup",
-- setup = function()
-- require("blake.other").packer_lazy_load "vim-matchup"
-- end,
}
use { -- ALE: Support for lots of linters, etc
'dense-analysis/ale',
ft = {'sh', 'zsh', 'bash', 'html', 'markdown', 'racket', 'vim', 'tex'},
config = function()
vim.g.ale_disable_lsp = 1
end
}
---- Other IDE features
use { -- git integration
'lewis6991/gitsigns.nvim',
requires = {
'nvim-lua/plenary.nvim'
},
config = function()
require('blake.other').gitsigns()
end,
}
use { -- file manager
'kyazdani42/nvim-tree.lua',
requires = 'kyazdani42/nvim-web-devicons',
config = function()
require('blake.other').nvimtree()
end
}
use { -- terminal
"akinsho/toggleterm.nvim",
config = function()
require('blake.other').toggleterm()
end
}
use { -- Smooth Scrolling
"karb94/neoscroll.nvim",
config = function()
require('blake.other').neoscroll()
end,
}
use { -- automatic session management
'rmagatti/auto-session',
config = function()
require('blake.other').autosession()
end
}
use { -- Markdown preview
'ellisonleao/glow.nvim',
ft = { 'md', 'markdown', }
}
-- Conveniences
use { -- Undo tree
'mbbill/undotree',
config = function()
vim.cmd 'nnoremap <F5> <cmd>UndotreeToggle<CR>'
vim.api.nvim_set_keymap("n", "<F5>", "<cmd>UndotreeToggle<CR>", { noremap = true, silent = true, })
end
}
use { -- Quote pairing
'jiangmiao/auto-pairs'
}
use { -- Alignment
'junegunn/vim-easy-align',
}
use { -- tpope: Quote/parenthesis changing
'tpope/vim-surround'
}
use { -- tpope: Comments
'tpope/vim-commentary'
}
use { -- tpope: git integration
'tpope/vim-fugitive'
}
use { -- tpope: Repeatability for various tpope plugins
'tpope/vim-repeat',
}
use { -- cheat.sh integration
"dbeniamine/cheat.sh-vim",
}
end)
-- vim:fdm=marker:fmr={,}:expandtab:tabstop=3:sw=3

View file

@ -0,0 +1,131 @@
-- TODO: translate this to lua
vim.cmd [[
""" Settings
set suffixes+=.aux,.bbl,.blg,.brf,.cb,.dvi,.idx,.ilg,.ind,.inx,.jpg,.log,.out,.png,.toc
set suffixes-=.h
set suffixes-=.obj
set tabstop=3 softtabstop=3
set shiftwidth=3
set expandtab
set smartindent
" set foldmethod=indent
" set foldlevel=0
set undodir=~/.vim/undo
set undofile
set noswapfile
set hlsearch
set hidden
set ignorecase
set smartcase
set wrap
set linebreak
" set guicursor= " always use the block cursor
syntax on
set redrawtime=1000 " max syntax highlight time
set number relativenumber
autocmd InsertEnter * :set norelativenumber " Automatically toggle line numbers
autocmd InsertLeave * :set relativenumber
set noerrorbells
set encoding=UTF-8
set cursorline
set mouse=a
set incsearch
set scrolloff=5
" set wildmenu
" set wildmode=full
" TextEdit might fail if hidden is not set.
set hidden
set cmdheight=1 " Give more space for displaying messages.
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Spell check!
set spelllang=en_us
" spell check in git commits
autocmd Filetype gitcommit setlocal spell
set showcmd
set signcolumn=yes
" disable spell check in help files
autocmd FileType help setlocal nospell
filetype plugin on
" Macro for opening a new terminal with spell check off
command! Term tabnew | setlocal nospell | term
autocmd FileType help setlocal nospell
" test whitespace ->
" more test whitespace ->
" Indented text
" even more test whitespace ->
""" Key bindings
let mapleader = " "
" *sigh*...
command! Q q
command! W w
command! Wq wq
command! WQ wq
" Press Alt h to toggle highlighting on/off, and show current value.
noremap <M-h> <cmd>set hlsearch! hlsearch?<CR>
noremap <M-S> <cmd>set spell! spell?<CR>
" Escape to enter normal mode in the terminal
tnoremap <Esc> <C-\><C-n>
" Replace with alt S
nnoremap <M-s> :%s//g<Left><Left>
" Move lines around in visual mode with J and K
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" Make vim a hex editor
" Edit *.bin files as binaries rather than text files (if your file isn't a .bin,
" make a symlink that points to it with the .bin extension and edit the symlink ;)
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
colorscheme slate
]]
vim.cmd [[
""""""" Quality of life things that aren't one line (also from stack overflow and stuff)
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
if (empty($TMUX))
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
endif
]]
-- 'Visual At' plugin (https://github.com/stoeffel/.dotfiles/blob/master/vim/visual-at.vim)
vim.cmd [[
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction
]]
-- 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 ]]