/
common.lua
169 lines (146 loc) · 5.4 KB
/
common.lua
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
-- inoremap jk <Esc>
vim.keymap.set('i', 'jk', '<Esc>')
-- map j to gj and k to gk, so line navigation ignores line wrap
-- nnoremap j gj
-- nnoremap k gk
vim.keymap.set('n', 'j', 'gj')
vim.keymap.set('n', 'k', 'gk')
-- https://stackoverflow.com/a/30691754
-- set clipboard=unnamedplus
vim.o.clipboard = "unnamedplus"
-- set nohlsearch
vim.o.hlsearch = false
vim.o.number = true
-- set wrap " Only use a soft wrap, not a hard one
vim.o.wrap = true
-- set linebreak " Break lines at word (requires Wrap lines)
vim.o.linebreak = true
-- " https://stackoverflow.com/a/1878984/2958070
-- set tabstop=4 " The width of a TAB is set to 4. Still it is a \t. It is just that
vim.o.tabstop = 4
-- set shiftwidth=4 " Indents will have a width of 4
vim.o.shiftwidth = 4
-- set softtabstop=4 " Sets the number of columns for a TAB
vim.o.softtabstop = 4
-- set expandtab " Expand TABs to spaces
vim.o.expandtab = true
vim.o.termguicolors = true
vim.o.inccommand = "split"
vim.o.smartcase = true
-- augroup custom_filetype
-- autocmd!
-- autocmd BufNewFile,BufRead *.src set filetype=xml
-- augroup END
local bbkane_augroup = vim.api.nvim_create_augroup('bbkane_augroup', { clear = true })
vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, {
group = bbkane_augroup,
pattern = "*.src",
command = "set filetype=xml"
})
-- " http://stackoverflow.com/a/18444962/2958070
-- " custom file templates
-- augroup templates
-- au!
-- autocmd BufNewFile *.* silent! execute '0r ~/.config/nvim/templates/skeleton.'.expand("<afile>:e")
-- augroup END
vim.api.nvim_create_autocmd({ 'BufNewFile' }, {
group = bbkane_augroup,
pattern = "*.*",
command = "silent! execute '0r ~/.config/nvim/templates/skeleton.'.expand('<afile>:e')"
})
-- TODO: lua version not working...
-- " NOTE: add bottom one first to not mess up what's <line2>
-- command! -range=% -nargs=0 -bar AddCodeFence
-- \ :<line2>s:$:\r```:
-- \ | <line1>s:^:```\r:
-- vim.api.nvim_create_user_command(
-- "AddCodeFence",
-- [[:<line2>s:$:\r```:
-- \ | <line1>s:^:```\r:]],
-- { bang = true, bar = true, range = "%", nargs = 0 }
-- )
vim.cmd [[
command! -range=% -nargs=0 -bar AddCodeFence
\ :<line2>s:$:\r```:
\ | <line1>s:^:```\r:
]]
-- TODO: use subsitute function: https://jeffkreeftmeijer.com/vim-reformat-dates/
-- " The 'e' on the end of the substitute ignores errors
-- " -range=% means without a visual selection the whole buffer is selected
-- " Special thanks to a @jfim for the link substitution line
-- " Note that top level lists can be represented by ^-, not ^*
-- " TODO: handle ^# substitution in code blocks
-- command! -range=% -nargs=0 -bar MarkdownToJira
-- \ :<line1>,<line2>s:^ - :** :e
-- \ | <line1>,<line2>s:^ - :*** :e
-- \ | <line1>,<line2>s:^```$:{code}:e
-- \ | <line1>,<line2>s:^```\(.\+\):{code\:\1}:e
-- \ | <line1>,<line2>s:^# :h1. :e
-- \ | <line1>,<line2>s:^## :h2. :e
-- \ | <line1>,<line2>s:^### :h3. :e
-- \ | <line1>,<line2>s: `: {{:eg
-- \ | <line1>,<line2>s:^`:{{:e
-- \ | <line1>,<line2>s:` :}} :eg
-- \ | <line1>,<line2>s:`$:}}:eg
-- \ | <line1>,<line2>s:`\.:}}.:eg
-- \ | <line1>,<line2>s:^\d\+\. :# :e
-- \ | <line1>,<line2>s/\v\[([^\]]*)\]\(([^\)]*)\)/[\1|\2]/ge
vim.api.nvim_create_user_command(
"MarkdownToJira",
[=[:<line1>,<line2>s:^ - :** :e
\ | <line1>,<line2>s:^ - :*** :e
\ | <line1>,<line2>s:^```$:{code}:e
\ | <line1>,<line2>s:^```\(.\+\):{code\:\1}:e
\ | <line1>,<line2>s:^# :h1. :e
\ | <line1>,<line2>s:^## :h2. :e
\ | <line1>,<line2>s:^### :h3. :e
\ | <line1>,<line2>s: `: {{:eg
\ | <line1>,<line2>s:^`:{{:e
\ | <line1>,<line2>s:` :}} :eg
\ | <line1>,<line2>s:`$:}}:eg
\ | <line1>,<line2>s:`\.:}}.:eg
\ | <line1>,<line2>s:^\d\+\. :# :e
\ | <line1>,<line2>s/\v\[([^\]]*)\]\(([^\)]*)\)/[\1|\2]/ge
\]=],
{ bang = true, bar = true, range = "%", nargs = 0 }
)
-- function! RenameFile()
-- let old_name = expand('%')
-- let new_name = input('New file name: ', expand('%'), 'file')
-- if new_name != '' && new_name != old_name
-- exec ':saveas ' . new_name
-- exec ':silent !rm ' . old_name
-- redraw!
-- endif
-- endfunction
-- command! RenameFile :call RenameFile()
-- https://github.com/richardmarbach/dotfiles/blob/7912ba284aac6cc005b9dfe35349bf1e5d50f1fe/config/nvim/lua/utils/file.lua#L5
vim.api.nvim_create_user_command(
"RenameFile",
function(args)
local old_name = vim.fn.expand("%")
local new_name = vim.fn.input("New file name: ", old_name, "file")
if new_name ~= '' and new_name ~= old_name then
vim.api.nvim_command(' saveas ' .. new_name)
-- TODO: https://unix.stackexchange.com/a/562421/185953
vim.api.nvim_command(' silent !rm ' .. old_name)
vim.cmd('redraw!')
end
end,
{ bang = true }
)
-- " https://askubuntu.com/a/686806/483521
-- " :lua =os.date('%Y/%m/%d %H:%M:%S')
-- command! InsertDate :execute 'norm i' .
-- \ substitute(system("date '+%a %b %d - %Y-%m-%d %H:%M:%S %Z'"), '\n\+$', '', '')
vim.api.nvim_create_user_command(
"InsertDate",
function(args)
local today = os.date('%a %b %d - %Y-%m-%d %H:%M:%S %Z')
vim.api.nvim_command('norm i ' .. today)
end,
{ bang = true }
)
vim.cmd [[
command! -range FormatShellCmd <line1>!format_shell_cmd.py
]]