summary refs log tree commit diff
path: root/.vim/init.lua
blob: 600a76b8d26c2c60547373a42ab933d4798b6b54 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
local cmd = vim.cmd
local g = vim.g

g.mapleader = ' ' -- <leader> key to <space>
g.maplocalleader = '\\'

require('plugins')
require('hardmode')

-- OPTIONS -- {{{
local opt = vim.opt

opt.backspace = 'indent,eol,start'
opt.clipboard:prepend { 'unnamedplus' }
opt.cmdheight = 1
opt.colorcolumn = {80} -- depends on 'textwidth'
opt.complete = '.,w,b,u'
opt.completeopt = 'menuone,noinsert,noselect'
opt.concealcursor = ''
opt.conceallevel = 2
opt.cursorline = true
opt.expandtab = true
opt.exrc = true
opt.fillchars = 'fold:─'
opt.foldenable = true
opt.foldlevel = 0
opt.foldmethod = 'marker'
opt.hidden = true
opt.inccommand = 'split'
opt.incsearch = true
opt.laststatus = 2
opt.lazyredraw = true
opt.list = true
opt.listchars:append { trail = '¬', tab = '> ' }
opt.mouse = 'a'
opt.number = true
opt.ruler = true
opt.scrolloff = 3
opt.shiftround = true
opt.shortmess:append { c = true }
opt.showbreak = '↪ '
opt.showcmd = false
opt.showmode = true
opt.signcolumn = 'auto:1'
opt.smartcase = true
opt.spell = false
opt.spelloptions = 'camel'
opt.statusline = '%!luaeval("statusline()")'
opt.termguicolors = true
opt.textwidth = 0
opt.title = true
opt.undolevels = 1000
opt.updatetime = 300
opt.wrap = true
-- }}}

-- COLORS -- {{{
-- g.nihoncolors_transparent_background = true
cmd [[ colorscheme lush ]]
-- }}}

-- KEY BINDS -- {{{
local nnoremap = require('astronauta.keymap').nnoremap
local inoremap = require('astronauta.keymap').inoremap
local vnoremap = require('astronauta.keymap').vnoremap
local tnoremap = require('astronauta.keymap').tnoremap

nnoremap { 'Q', function() cmd [[ quitall ]] end, silent = false }
nnoremap { 'gb', function() cmd [[ bnext ]] end }
nnoremap { 'gB', function() cmd [[ bprevious ]] end }

-- terminal
tnoremap { '<esc>', [[ <c-\><c-n> ]] }
tnoremap { '<leader>qq', [[ <c-\><c-n> :bdelete!<cr> ]] }

nnoremap { 'gf', function() require('misc').open_under_cursor('open') end }
nnoremap { 'gF', function() require('misc').open_under_cursor() end }
nnoremap { 'gx', function() require('misc').open_under_cursor('url-launcher') end }
nnoremap { 'gGw', function() require('misc').word_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end }
nnoremap { 'gGe', function() require('misc').expr_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end }
nnoremap { 'gGf', function() require('misc').file_under_cursor(function(s) require('telescope.builtin.files').grep_string({ search = s }) end) end }
nnoremap { 'gs', function() require('misc').word_under_cursor(function(s) vim.fn.feedkeys(':%s/' .. s .. '//g'); cmd [[ call feedkeys("\<left>\<left>") ]] end) end }

nnoremap { '<leader>gg', function() require('neogit').open({ kind = "split" }) end }
nnoremap { 'gm', function() cmd [[ GitMessenger ]] end }
vnoremap { 'T', function() cmd [[ retab! | call feedkeys("\<esc>") ]] end }
-- }}}

local u = require('utils')

-- AUTO GROUPS -- {{{
u.augroup2 {
  yank_highlight = {{ 'TextYankPost', '*', [[ silent! lua require("vim.highlight").on_yank() ]] }},
  obvious_active_win = {
    { 'WinEnter', '*', 'set cul' },
    { 'WinLeave', '*', 'set nocul' }
  },
  c_makeprg = {{'BufRead', '*.c', [[ set makeprg=ninja\ -C\ build ]] }},
}
-- }}}

-- USER COMMANDS -- {{{
u.def('BalenaDiagnosticsFold', [[ call balena_diagnostics_fold#apply() ]])
u.def('SortLine', [[ call setline(".", join(sort(split(getline("."), " ")), " ")) ]])
-- }}}

-- STATUS LINE -- {{{
statusline = function()
  local sl = ''
  -- left
  sl = sl .. statusline_color(vim.fn.mode())
  sl = sl .. [[ ⢷ %<%F %-m %-r ]]
  -- right
  sl = sl .. [[ %=  %l:%v %y ]]
  return sl
end
statusline_color = function(mode)
  local hi = '%*'
  if mode == 'i' then
    hi = '%#StatusLineInsert#'
  elseif mode == 'c' then
    hi = '%#StatusLineCommand#'
  elseif mode == 'v' or mode == 'V' or mode == '' then
    hi = '%#StatusLineVisual#'
  elseif mode == 'R' or mode == 'Rv' then
    hi = '%#StatusLineReplace#'
  end
  -- return '%{g:actual_curwin==win_getid()?'.. hi ..':%#StatusLineNC#}'
  return hi
end
-- }}}

-- source .nvimrc if it exists
local local_vimrc = vim.fn.getcwd()..'/.nvimrc'
if vim.loop.fs_stat(local_vimrc) then
  cmd('source ' .. local_vimrc)
end