move init.lua
This commit is contained in:
@ -1,22 +0,0 @@
|
||||
local use_google = require("utils").use_google
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
if not vim.loop.fs_stat(lazypath) then
|
||||
vim.fn.system({
|
||||
"git",
|
||||
"clone",
|
||||
"--filter=blob:none",
|
||||
"https://github.com/folke/lazy.nvim.git",
|
||||
lazypath,
|
||||
})
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
package.path = package.path .. ";" .. vim.env.HOME .. "/.vim/lua/?.lua"
|
||||
|
||||
local plugins = {
|
||||
-- this entry tells lazy.nvim to load the list of of *.lua files from plugins/
|
||||
{ import = "plugins" },
|
||||
}
|
||||
require("lazy").setup(plugins)
|
||||
require("config.clipboard")
|
||||
require("config.zip")
|
@ -1,16 +1,16 @@
|
||||
local use_google = require("utils").use_google
|
||||
|
||||
return {
|
||||
{
|
||||
"cmdtree",
|
||||
dir = "~/cmdtree",
|
||||
},
|
||||
-- {
|
||||
-- "cmdtree",
|
||||
-- dir = "~/cmdtree",
|
||||
-- },
|
||||
{
|
||||
"nvim-neo-tree/neo-tree.nvim",
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
"MunifTanjim/nui.nvim",
|
||||
"~/cmdtree",
|
||||
-- "~/cmdtree",
|
||||
},
|
||||
cmd = {
|
||||
"Neotree",
|
||||
@ -28,7 +28,7 @@ return {
|
||||
"filesystem",
|
||||
"buffers",
|
||||
"git_status",
|
||||
"cmdtree",
|
||||
--"cmdtree",
|
||||
-- ...and any additional source
|
||||
},
|
||||
window = {
|
||||
|
@ -4,55 +4,61 @@ local TableConcat = require("utils").TableConcat
|
||||
local scopes = require("neoscopes")
|
||||
|
||||
_G.find_files = function(search_dirs)
|
||||
require("telescope.builtin").find_files({
|
||||
search_dirs = search_dirs,
|
||||
})
|
||||
require("telescope.builtin").find_files({
|
||||
search_dirs = search_dirs,
|
||||
})
|
||||
end
|
||||
-- Helper functions to fetch the current scope and set `search_dirs`
|
||||
_G.find_dotfiles = function()
|
||||
require("telescope.builtin").git_files({
|
||||
cwd = vim.fn.expand("$HOME/dotfiles"),
|
||||
})
|
||||
require("telescope.builtin").git_files({
|
||||
cwd = vim.fn.expand("$HOME/dotfiles"),
|
||||
})
|
||||
end
|
||||
|
||||
_G.search_cwd = function()
|
||||
local builtin = require("telescope.builtin")
|
||||
local utils = require("telescope.utils")
|
||||
builtin.find_files({ cwd = utils.buffer_dir() })
|
||||
local builtin = require("telescope.builtin")
|
||||
local utils = require("telescope.utils")
|
||||
builtin.find_files({ cwd = utils.buffer_dir() })
|
||||
end
|
||||
|
||||
_G.live_grep = function(search_dirs)
|
||||
require("telescope.builtin").live_grep({
|
||||
search_dirs = search_dirs,
|
||||
})
|
||||
require("telescope.builtin").live_grep({
|
||||
search_dirs = search_dirs,
|
||||
})
|
||||
end
|
||||
|
||||
_G.live_grep_cword = function(search_dirs)
|
||||
require("telescope.builtin").live_grep({
|
||||
search_dirs = search_dirs,
|
||||
})
|
||||
end
|
||||
|
||||
local function exe(cmd)
|
||||
return vim.split(vim.fn.system(cmd), "\n")
|
||||
return vim.split(vim.fn.system(cmd), "\n")
|
||||
end
|
||||
|
||||
local function get_visual_selection()
|
||||
-- Yank current visual selection into the 'v' register
|
||||
--
|
||||
-- Note that this makes no effort to preserve this register
|
||||
vim.cmd('noau normal! "vy"')
|
||||
-- Yank current visual selection into the 'v' register
|
||||
--
|
||||
-- Note that this makes no effort to preserve this register
|
||||
vim.cmd('noau normal! "vy"')
|
||||
|
||||
return vim.fn.getreg("v")
|
||||
return vim.fn.getreg("v")
|
||||
end
|
||||
|
||||
function fig_modified()
|
||||
return exe("hg pstatus -ma -n --no-status --template= | sort")
|
||||
return exe("hg pstatus -ma -n --no-status --template= | sort")
|
||||
end
|
||||
|
||||
function fig_all_modified()
|
||||
return exe("hg status -ma -n --rev p4base --no-status --template= | sort")
|
||||
return exe("hg status -ma -n --rev p4base --no-status --template= | sort")
|
||||
end
|
||||
|
||||
-- stylua: ignore
|
||||
local keys = {
|
||||
{ "<leader>e", ":lua search_cwd()<CR>", desc = "Find Files in Buffer Directory" },
|
||||
{ "<leader>ts.", ":lua live_grep({vim.fn.getcwd()})<CR>", desc = "Search in CWD" },
|
||||
{ "<leader>ts", ':lua live_grep({vim.fn.expand("%%")})<CR>', desc = "Search in Buffer Directory" },
|
||||
{ "<leader>ts", require('telescope.builtin').live_grep },
|
||||
{ "<leader>TS", [[<cmd>lua require('telescope.builtin').live_grep{default_text = vim.fn.expand("<cword>")}<CR>]], },
|
||||
{ "<leader>t.", ":lua find_dotfiles()<CR>", desc = "Find Dotfiles" },
|
||||
{ "<leader>tc", ":Telescope textcase<CR>", desc = "Text case" },
|
||||
{ "<leader>tC", ":CritiqueUnresolvedCommentsTelescope<CR>", desc = "Critique unresolved comments" },
|
||||
@ -62,9 +68,6 @@ local keys = {
|
||||
{ "<leader>tk", ":Telescope keymaps<CR>", desc = "Keymaps" },
|
||||
{ "<leader>tn", ":Telescope notify<CR>", desc = "Notifications" },
|
||||
{ "<leader>tr", ":Telescope resume<CR>", desc = "Telescope Resume" },
|
||||
--
|
||||
-- { "<leader>tdc", ":Telescope dap commands" },
|
||||
-- { "<leader>tdc", ":Telescope dap configurations" },
|
||||
}
|
||||
|
||||
if use_google() then
|
||||
@ -82,144 +85,144 @@ if use_google() then
|
||||
end
|
||||
|
||||
return {
|
||||
{
|
||||
"aznhe21/actions-preview.nvim",
|
||||
config = function()
|
||||
require("actions-preview").setup({
|
||||
telescope = {
|
||||
sorting_strategy = "ascending",
|
||||
layout_strategy = "vertical",
|
||||
layout_config = {
|
||||
width = 0.8,
|
||||
height = 0.9,
|
||||
prompt_position = "top",
|
||||
preview_cutoff = 20,
|
||||
preview_height = function(_, _, max_lines)
|
||||
return max_lines - 15
|
||||
end,
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
keys = {
|
||||
{ "?", "<cmd>lua require('actions-preview').code_actions()<cr>" },
|
||||
},
|
||||
},
|
||||
{
|
||||
"smartpde/telescope-recent-files",
|
||||
config = function()
|
||||
require("telescope").load_extension("recent_files")
|
||||
end,
|
||||
keys = {
|
||||
{ "<leader>to", [[<cmd>lua require('telescope').extensions.recent_files.pick()<CR>]] },
|
||||
},
|
||||
},
|
||||
{
|
||||
"piersolenski/telescope-import.nvim",
|
||||
dependencies = "nvim-telescope/telescope.nvim",
|
||||
config = function()
|
||||
require("telescope").load_extension("import")
|
||||
end,
|
||||
keys = function()
|
||||
if not use_google() then
|
||||
return {
|
||||
{ "<leader>i", ":Telescope import<CR>" },
|
||||
}
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-telescope/telescope.nvim",
|
||||
dependencies = {
|
||||
"mfussenegger/nvim-dap",
|
||||
"smartpde/telescope-recent-files",
|
||||
"rcarriga/nvim-dap-ui",
|
||||
},
|
||||
config = function()
|
||||
require("telescope").setup({
|
||||
defaults = {
|
||||
-- The vertical layout strategy is good to handle long paths like those in
|
||||
-- google3 repos because you have nearly the full screen to display a file path.
|
||||
-- The caveat is that the preview area is smaller.
|
||||
layout_strategy = "vertical",
|
||||
-- Common paths in google3 repos are collapsed following the example of Cider
|
||||
-- It is nice to keep this as a user config rather than part of
|
||||
-- telescope-codesearch because it can be reused by other telescope pickers.
|
||||
path_display = function(opts, path)
|
||||
-- Do common substitutions
|
||||
path = path:gsub("^/google/src/cloud/[^/]+/[^/]+/google3/", "google3/", 1)
|
||||
path = path:gsub("^google3/java/com/google/", "//j/c/g/", 1)
|
||||
path = path:gsub("^google3/javatests/com/google/", "//jt/c/g/", 1)
|
||||
path = path:gsub("^google3/third_party/", "//3p/", 1)
|
||||
path = path:gsub("^google3/", "//", 1)
|
||||
{
|
||||
"aznhe21/actions-preview.nvim",
|
||||
config = function()
|
||||
require("actions-preview").setup({
|
||||
telescope = {
|
||||
sorting_strategy = "ascending",
|
||||
layout_strategy = "vertical",
|
||||
layout_config = {
|
||||
width = 0.8,
|
||||
height = 0.9,
|
||||
prompt_position = "top",
|
||||
preview_cutoff = 20,
|
||||
preview_height = function(_, _, max_lines)
|
||||
return max_lines - 15
|
||||
end,
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
keys = {
|
||||
{ "?", "<cmd>lua require('actions-preview').code_actions()<cr>" },
|
||||
},
|
||||
},
|
||||
{
|
||||
"smartpde/telescope-recent-files",
|
||||
config = function()
|
||||
require("telescope").load_extension("recent_files")
|
||||
end,
|
||||
keys = {
|
||||
{ "<leader>to", [[<cmd>lua require('telescope').extensions.recent_files.pick()<CR>]] },
|
||||
},
|
||||
},
|
||||
{
|
||||
"piersolenski/telescope-import.nvim",
|
||||
dependencies = "nvim-telescope/telescope.nvim",
|
||||
config = function()
|
||||
require("telescope").load_extension("import")
|
||||
end,
|
||||
keys = function()
|
||||
if not use_google() then
|
||||
return {
|
||||
{ "<leader>i", ":Telescope import<CR>" },
|
||||
}
|
||||
end
|
||||
end,
|
||||
},
|
||||
{
|
||||
"nvim-telescope/telescope.nvim",
|
||||
dependencies = {
|
||||
"mfussenegger/nvim-dap",
|
||||
"smartpde/telescope-recent-files",
|
||||
"rcarriga/nvim-dap-ui",
|
||||
},
|
||||
config = function()
|
||||
require("telescope").setup({
|
||||
defaults = {
|
||||
-- The vertical layout strategy is good to handle long paths like those in
|
||||
-- google3 repos because you have nearly the full screen to display a file path.
|
||||
-- The caveat is that the preview area is smaller.
|
||||
layout_strategy = "vertical",
|
||||
-- Common paths in google3 repos are collapsed following the example of Cider
|
||||
-- It is nice to keep this as a user config rather than part of
|
||||
-- telescope-codesearch because it can be reused by other telescope pickers.
|
||||
path_display = function(opts, path)
|
||||
-- Do common substitutions
|
||||
path = path:gsub("^/google/src/cloud/[^/]+/[^/]+/google3/", "google3/", 1)
|
||||
path = path:gsub("^google3/java/com/google/", "//j/c/g/", 1)
|
||||
path = path:gsub("^google3/javatests/com/google/", "//jt/c/g/", 1)
|
||||
path = path:gsub("^google3/third_party/", "//3p/", 1)
|
||||
path = path:gsub("^google3/", "//", 1)
|
||||
|
||||
-- Do truncation. This allows us to combine our custom display formatter
|
||||
-- with the built-in truncation.
|
||||
-- `truncate` handler in transform_path memoizes computed truncation length in opts.__length.
|
||||
-- Here we are manually propagating this value between new_opts and opts.
|
||||
-- We can make this cleaner and more complicated using metatables :)
|
||||
local new_opts = {
|
||||
path_display = {
|
||||
truncate = true,
|
||||
},
|
||||
__length = opts.__length,
|
||||
}
|
||||
path = require("telescope.utils").transform_path(new_opts, path)
|
||||
opts.__length = new_opts.__length
|
||||
return path
|
||||
end,
|
||||
mappings = {
|
||||
n = {
|
||||
["<C-c>"] = "close",
|
||||
["<Esc>"] = "close"
|
||||
},
|
||||
i = {
|
||||
-- ["<cr>"] = function(bufnr)
|
||||
-- require("telescope.actions.set").edit(bufnr, "tab drop")
|
||||
-- end,
|
||||
["<C-c>"] = "close",
|
||||
["<Esc>"] = "close",
|
||||
["<S-Down>"] = "cycle_history_next",
|
||||
["<S-Up>"] = "cycle_history_prev",
|
||||
},
|
||||
},
|
||||
},
|
||||
extensions = {
|
||||
codesearch = {
|
||||
experimental = true, -- enable results from google3/experimental
|
||||
},
|
||||
recent_files = {
|
||||
-- This function rewrites all file paths to the current workspace.
|
||||
-- For example, if w2 is the current workspace, then
|
||||
-- /google/.../w1/google3/my_file.cc becomes /google/.../w2/google3/my_file.cc,
|
||||
transform_file_path = function(path)
|
||||
local neocitc = require("neocitc")
|
||||
local path_func = neocitc.path_in_current_workspace_or_head
|
||||
or neocitc.path_in_current_workspace
|
||||
return path_func(path)
|
||||
end,
|
||||
-- This is a useful option to speed up Telescope by avoiding the check
|
||||
-- for file existence.
|
||||
stat_files = false,
|
||||
-- Ignore common patterns that can show up from other google plugins
|
||||
ignore_patterns = {
|
||||
"/%.git/COMMIT_EDITING$",
|
||||
"/%.git/COMMIT_EDITMSG$",
|
||||
"/%.git/MERGE_MSG$",
|
||||
"^/tmp/%.pipertmp-",
|
||||
"/Related_Files$",
|
||||
"^term:",
|
||||
";#toggleterm#",
|
||||
},
|
||||
},
|
||||
persisted = {},
|
||||
import = {
|
||||
-- Add imports to the top of the file keeping the cursor in place
|
||||
insert_at_top = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
keys = keys,
|
||||
},
|
||||
-- Do truncation. This allows us to combine our custom display formatter
|
||||
-- with the built-in truncation.
|
||||
-- `truncate` handler in transform_path memoizes computed truncation length in opts.__length.
|
||||
-- Here we are manually propagating this value between new_opts and opts.
|
||||
-- We can make this cleaner and more complicated using metatables :)
|
||||
local new_opts = {
|
||||
path_display = {
|
||||
truncate = true,
|
||||
},
|
||||
__length = opts.__length,
|
||||
}
|
||||
path = require("telescope.utils").transform_path(new_opts, path)
|
||||
opts.__length = new_opts.__length
|
||||
return path
|
||||
end,
|
||||
mappings = {
|
||||
n = {
|
||||
["<C-c>"] = "close",
|
||||
["<Esc>"] = "close",
|
||||
},
|
||||
i = {
|
||||
-- ["<cr>"] = function(bufnr)
|
||||
-- require("telescope.actions.set").edit(bufnr, "tab drop")
|
||||
-- end,
|
||||
["<C-c>"] = "close",
|
||||
["<Esc>"] = "close",
|
||||
["<S-Down>"] = "cycle_history_next",
|
||||
["<S-Up>"] = "cycle_history_prev",
|
||||
},
|
||||
},
|
||||
},
|
||||
extensions = {
|
||||
codesearch = {
|
||||
experimental = true, -- enable results from google3/experimental
|
||||
},
|
||||
recent_files = {
|
||||
-- This function rewrites all file paths to the current workspace.
|
||||
-- For example, if w2 is the current workspace, then
|
||||
-- /google/.../w1/google3/my_file.cc becomes /google/.../w2/google3/my_file.cc,
|
||||
transform_file_path = function(path)
|
||||
local neocitc = require("neocitc")
|
||||
local path_func = neocitc.path_in_current_workspace_or_head
|
||||
or neocitc.path_in_current_workspace
|
||||
return path_func(path)
|
||||
end,
|
||||
-- This is a useful option to speed up Telescope by avoiding the check
|
||||
-- for file existence.
|
||||
stat_files = false,
|
||||
-- Ignore common patterns that can show up from other google plugins
|
||||
ignore_patterns = {
|
||||
"/%.git/COMMIT_EDITING$",
|
||||
"/%.git/COMMIT_EDITMSG$",
|
||||
"/%.git/MERGE_MSG$",
|
||||
"^/tmp/%.pipertmp-",
|
||||
"/Related_Files$",
|
||||
"^term:",
|
||||
";#toggleterm#",
|
||||
},
|
||||
},
|
||||
persisted = {},
|
||||
import = {
|
||||
-- Add imports to the top of the file keeping the cursor in place
|
||||
insert_at_top = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
keys = keys,
|
||||
},
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
" DO NOT PLACE PLUGIN RELATED MAPPINGS HERE
|
||||
|
||||
" jk is escape -.-
|
||||
inoremap jk <esc>
|
||||
|
||||
@ -43,63 +41,3 @@ nnoremap / /\v
|
||||
vnoremap / /\v
|
||||
|
||||
nnoremap <silent> <leader>ww :call WindowSwap#EasyWindowSwap()<CR>
|
||||
|
||||
function! s:createHabitsMappings(keys, message) abort
|
||||
for key in a:keys
|
||||
call nvim_set_keymap('n', key, ':call BreakHabitsWindow(' . string(a:message). ')<CR>', {'silent': v:true, 'nowait': v:true, 'noremap': v:true})
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! BreakHabitsWindow(message) abort
|
||||
" Define the size of the floating window
|
||||
let width = 50
|
||||
let height = 10
|
||||
|
||||
" Create the scratch buffer displayed in the floating window
|
||||
let buf = nvim_create_buf(v:false, v:true)
|
||||
|
||||
" create the lines to draw a box
|
||||
let horizontal_border = '+' . repeat('-', width - 2) . '+'
|
||||
let empty_line = '|' . repeat(' ', width - 2) . '|'
|
||||
let lines = flatten([horizontal_border, map(range(height-2), 'empty_line'), horizontal_border])
|
||||
" set the box in the buffer
|
||||
call nvim_buf_set_lines(buf, 0, -1, v:false, lines)
|
||||
|
||||
" Create the lines for the centered message and put them in the buffer
|
||||
let offset = 0
|
||||
for line in a:message
|
||||
let start_col = (width - len(line))/2
|
||||
let end_col = start_col + len(line)
|
||||
let current_row = height/2-len(a:message)/2 + offset
|
||||
let offset = offset + 1
|
||||
call nvim_buf_set_text(buf, current_row, start_col, current_row, end_col, [line])
|
||||
endfor
|
||||
|
||||
" Set mappings in the buffer to close the window easily
|
||||
let closingKeys = ['<Esc>', '<CR>', '<Leader>']
|
||||
for closingKey in closingKeys
|
||||
call nvim_buf_set_keymap(buf, 'n', closingKey, ':close<CR>', {'silent': v:true, 'nowait': v:true, 'noremap': v:true})
|
||||
endfor
|
||||
|
||||
" Create the floating window
|
||||
let ui = nvim_list_uis()[0]
|
||||
let opts = {'relative': 'editor',
|
||||
\ 'width': width,
|
||||
\ 'height': height,
|
||||
\ 'col': (ui.width/2) - (width/2),
|
||||
\ 'row': (ui.height/2) - (height/2),
|
||||
\ 'anchor': 'NW',
|
||||
\ 'style': 'minimal',
|
||||
\ }
|
||||
let win = nvim_open_win(buf, 1, opts)
|
||||
|
||||
" Change highlighting
|
||||
" call nvim_win_set_option(win, 'winhl', 'Normal:ErrorFloat')
|
||||
|
||||
highlight CustomFloatingWindow ctermbg=11 guibg=black ctermfg=10 guifg=red
|
||||
call nvim_win_set_option(win, 'winhl', 'Normal:CustomFloatingWindow')
|
||||
endfunction
|
||||
|
||||
" let windowHabitsKeys = [":w<cr>"]
|
||||
" let windowHabitsMessage = ["USE < SPACE SPACE > INSTEAD", "BREAK BAD HABITS"]
|
||||
" call s:createHabitsMappings(windowHabitsKeys, windowHabitsMessage)
|
||||
|
Reference in New Issue
Block a user