-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua.bak
165 lines (135 loc) · 4.68 KB
/
init.lua.bak
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
local opt = vim.opt
local fn = vim.fn
local api = vim.api
local M = {}
opt.foldenable = false
opt.visualbell = true
opt.relativenumber = true
opt.inccommand = 'nosplit'
opt.cursorline = false
opt.cursorcolumn = false
opt.number = true
opt.confirm = true
opt.hidden = false
opt.clipboard:append({"unnamedplus"})
opt.listchars = { tab = ' ', trail = '·', eol = '¬' }
opt.wrap = false
opt.path:prepend({"**"})
-- Fuzzy matching
opt.wildmenu = true
opt.wildignore:append({"**/node_modules/**", "**/.git/**", "**/build/**", "**/dist/**"})
-- Backups
opt.swapfile = false
opt.backup = false
-- Indentation
opt.autoindent = true
opt.smartindent = true
opt.smarttab = true
opt.shiftwidth = 2
opt.softtabstop = 2
opt.tabstop = 2
opt.expandtab = true
-- Nodejs host
if fn.executable('volta') == 1 then
vim.g.neovim_node_host = fn.trim(fn.system('volta which neovim-node-host'))
end
vim.g.mapleader = ','
vim.g.maplocalleader = ' '
vim.api.nvim_create_user_command('Frt', ':normal gg O# frozen_string_literal: true<CR><ESC>x', {})
function M.copyCurrentFilenameToClipboard()
local filename = fn.expand('%:p')
vim.fn.setreg('+', filename)
print('Filename copied to clipboard: ' .. filename)
end
vim.keymap.set('n', '<leader>cfp', M.copyCurrentFilenameToClipboard)
function M.CloseCurrentBuffer()
local buffers = fn.getbufinfo({buflisted = 1})
if #buffers == 1 then
api.nvim_command('enew')
else
api.nvim_command('bp')
end
api.nvim_buf_delete(fn.bufnr('#'), {})
end
function M.DeleteHiddenBuffers()
local buffers = fn.getbufinfo({buflisted = 1})
local currentBufferNumber = fn.bufnr('%')
for _, buffer in ipairs(buffers) do
if buffer.hidden and buffer.bufnr ~= currentBufferNumber then
api.nvim_buf_delete(buffer.bufnr, {})
end
end
print('Hidden buffers deleted')
end
vim.keymap.set('n', '<leader>q', M.CloseCurrentBuffer, { silent = true })
vim.keymap.set('n', '<leader>d', M.DeleteHiddenBuffers, { silent = true })
if fn.has('persistent_undo') == 1 then
opt.undodir = '/Users/random/.vim/backups'
opt.undofile = true
end
vim.cmd("let $NVIM_TUI_ENABLE_TRUE_COLOR=1")
opt.termguicolors = true
opt.background = 'dark'
vim.cmd('colorscheme gruvbox')
vim.keymap.set('n', '<leader>v', ':e $MYVIMRC<CR>')
vim.keymap.set('n', '<leader><c-v>', ':e /Users/random/.config/nvim/lua/plugins.lua<CR>')
vim.keymap.set('n', '<leader>V', ':source $MYVIMRC<CR>')
vim.keymap.set('n', '<leader>un', ':syntax sync fromstart<CR>:redraw!<CR>')
vim.keymap.set('n', '<leader>fef', ':normal! gg=G``<CR>')
vim.keymap.set('n', '<C-k>', '<C-w><Up>', { silent = true })
vim.keymap.set('n', '<C-j>', '<C-w><Down>', { silent = true })
vim.keymap.set('n', '<C-l>', '<C-w><Right>', { silent = true })
vim.keymap.set('n', '<C-h>', '<C-w><Left>', { silent = true })
local filetypesMapping = {
css = '_cs',
coffee = '_co',
html = '_ht',
slim = '_sl',
javascript = '_js',
markdown = '_md',
ruby = '_rb',
sh = '_sh',
vim = '_vi',
yaml = '_an',
dockerfile = '_dc',
}
for lang, mapping in pairs(filetypesMapping) do
local command = function() vim.api.nvim_command(string.format('setlocal filetype=%s', lang)) end
vim.keymap.set('n', mapping, command, { silent = true })
end
vim.keymap.set('n', '<Up>', ':resize +2<CR>', { silent = true })
vim.keymap.set('n', '<Down>', ':resize -2<CR>', { silent = true })
vim.keymap.set('n', '<Left>', ':vertical resize +2<CR>', { silent = true })
vim.keymap.set('n', '<Right>', ':vertical resize -2<CR>', { silent = true })
vim.keymap.set('t', '<C-o>', [[<C-\><C-n>]], { silent = false, noremap = false })
vim.keymap.set('n', 'Q', '@q', { silent = true })
vim.keymap.set('v', 'Q', ':norm @q<CR>', { silent = true })
vim.keymap.set('v', '//', 'y/<C-R>"<CR>', { silent = true })
vim.keymap.set('n', '//', ':nohlsearch<CR>', { silent = true })
-- vim.keymap.set('n', '<C-c>', '<Esc><Esc>', { silent = true })
function M.contains(list, x)
for _, v in pairs(list) do
if v == x then return true end
end
return false
end
function M.addDebuggerToNextLine()
local filetype = vim.bo.filetype
if filetype == 'lua' then
vim.api.nvim_command('normal obinding.pry<Esc>')
elseif M.contains({'svelte', 'js', 'ts'}, filetype) then
vim.api.nvim_command('normal odebugger<Esc>')
else
vim.api.nvim_command('normal obinding.pry<Esc>')
end
end
vim.keymap.set('n', '<leader>/', M.addDebuggerToNextLine, { silent = true })
function M.copyLinterError()
local current_line = vim.api.nvim_win_get_cursor(0)[1] - 1
local result = vim.diagnostic.get(fn.bufnr('%'), { lnum = current_line })
vim.fn.setreg('+', result[1].code)
end
vim.keymap.set('n', '<leader>cle', M.copyLinterError, { silent = true })
vim.g.loaded_sql_completion = 0
vim.g.omni_sql_no_default_maps = 1
require('plugins')