Skip to content

Instantly share code, notes, and snippets.

@namachan10777
Created August 6, 2022 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namachan10777/8751bce94182da55d93f5dc8758d02bb to your computer and use it in GitHub Desktop.
Save namachan10777/8751bce94182da55d93f5dc8758d02bb to your computer and use it in GitHub Desktop.
-- Bootstrap {{{
local function exists(file)
local ok, err, code = os.rename(file, file)
if not ok then if code == 13 then return true end end
return ok, err
end
local install_path = vim.fn.stdpath('data') .. '/site/pack/packer/opt/'
if not exists(install_path .. 'packer.nvim') then
vim.cmd('!git clone https://github.com/wbthomason/packer.nvim ' ..
install_path .. 'packer.nvim')
end
vim.api.nvim_command('packadd ' .. 'packer.nvim')
-- }}}
UseBuiltinLSP = false
local packer = require('packer')
packer.startup(function()
-- a package manager
use {'wbthomason/packer.nvim', opt = true}
-- lua utility library
use 'nvim-lua/plenary.nvim'
-- useful mapping for neovim api
use 'norcalli/nvim.lua'
-- popup_menu
use 'nvim-lua/popup.nvim'
-- fuzzy-finder
use 'nvim-telescope/telescope.nvim'
-- filer
use 'kyazdani42/nvim-tree.lua'
-- cli icons
use 'kyazdani42/nvim-web-devicons'
-- colorscheme
use 'namachan10777/nvim-highlite-otynium'
-- git plugin
use 'lambdalisue/gina.vim'
-- quickhl
use 't9md/vim-quickhl'
-- easymotion
use 'phaazon/hop.nvim'
-- treesitter
use 'nvim-treesitter/nvim-treesitter'
-- coloring parentesis with nest level by treesitter
use 'p00f/nvim-ts-rainbow'
-- use 'romgrk/nvim-treesitter-context'
-- realtime replacing preview
use 'markonm/traces.vim'
-- hls utility
use 'kevinhwang91/nvim-hlslens'
-- statusline
use 'glepnir/galaxyline.nvim'
-- align
use 'h1mesuke/vim-alignta'
-- language specific
use {'martinda/Jenkinsfile-vim-syntax', ft = 'jenkinsfile'}
use {'euclidianAce/BetterLua.vim', ft = 'lua'}
use {'pest-parser/pest.vim', ft = 'pest'}
use {'ElmCast/elm-vim', ft = 'elm'}
use {'namachan10777/tml.vim', ft = 'tml' }
use {'gutenye/json5.vim', ft = 'json5' }
use {'google/vim-jsonnet', ft = 'jsonnet'}
use {'vim-scripts/nginx.vim', ft = 'nginx'}
use {
'prettier/vim-prettier',
ft = {'typescript', 'javascript', 'typescriptreact'}
}
use {'jalvesaq/Nvim-R', ft = 'R'}
use {'qnighy/satysfi.vim', ft = 'satysfi'}
use {'cespare/vim-toml', ft = 'toml'}
use {'qnighy/lalrpop.vim', ft = 'lalrpop'}
use {'ron-rs/ron.vim', ft = 'ron'}
use {'npxbr/glow.nvim', ft = 'markdown'}
use {'dag/vim-fish', ft = 'fish'}
use {'jxnblk/vim-mdx-js', ft = 'mdx'}
use {'earthly/earthly.vim', ft = 'earthfile'}
end)
-- require {{{
local nvim = require('nvim')
local treesitter = require('nvim-treesitter.configs')
-- }}}
-- utilities {{{
local function augroup(name, hook)
nvim.ex.augroup(name)
nvim.ex.autocmd_()
hook()
nvim.ex.augroup("END")
end
local function set_indents(configs)
augroup("ExtIndent", function ()
nvim.ex.autocmd_()
for i = 1, #configs do
local config = configs[i]
local exts = "*." .. config.exts[1]
for j = 2, #config.exts do
exts = exts .. ",*." .. config["exts"][j]
end
if config["expand"] then
nvim.ex.autocmd("BufRead,BufNewFile", exts, "setlocal", ("shiftwidth=" .. tostring(config["w"])), ("tabstop=" .. tostring(config["w"])), "expandtab")
else
nvim.ex.autocmd("BufRead,BufNewFile", exts, "setlocal", ("shiftwidth="..tostring(config["w"])), ("tabstop="..tostring(config["w"])), "noexpandtab")
end
end
end)
end
-- }}}
-- coc {{{
function CheckBackSpace()
local col = nvim.fn.col(".") - 1
return col == 0 or
string.match(string.sub(nvim.fn.getline("."), col, col), "%s") ==
nil
end
-- }}}
-- nvim-lsp {{{
-- TODO completion.nvimが暴走する
if UseBuiltinLSP then
-- Lsp
local lsp_config = require('lspconfig')
local sumneko_root_path = vim.fn.stdpath('cache')..'/lspconfig/sumneko_lua/lua-language-server'
local sumneko_binary = sumneko_root_path.."/bin/Linux/lua-language-server"
lsp_config.sumneko_lua.setup {
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"};
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
path = vim.split(package.path, ';'),
},
diagnostics = {
globals = {'vim', 'use'},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = {
[vim.fn.expand('$VIMRUNTIME/lua')] = true,
[vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
},
},
},
},
}
lsp_config.rust_analyzer.setup{}
augroup("CompletionConfig", function()
nvim.ex.autocmd("BufEnter", "*", "lua require'completion'.on_attach()")
end)
end
-- }}}
-- galaxyline {{{
local gl = require('galaxyline')
local gls = gl.section
gl.short_line_list = {'LuaTree', 'vista', 'dbui'}
local colors = {
bg = '#282c34',
yellow = '#fabd2f',
cyan = '#008080',
darkblue = '#081633',
green = '#afd700',
orange = '#FF8800',
purple = '#5d4d7a',
magenta = '#d16d9e',
grey = '#c0c0c0',
blue = '#0087d7',
red = '#ec5f67'
}
local buffer_not_empty = function()
if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then return true end
return false
end
gls.left[1] = {
FirstElement = {
provider = function() return '▋' end,
highlight = {colors.blue, colors.yellow}
}
}
gls.left[2] = {
ViMode = {
provider = function()
local alias = {
n = 'NORMAL',
i = 'INSERT',
c = 'COMMAND',
V = 'VISUAL',
[''] = 'VISUAL'
}
return alias[vim.fn.mode()]
end,
separator = ' ',
separator_highlight = {
colors.yellow, function()
if not buffer_not_empty() then
return colors.purple
end
return colors.darkblue
end
},
highlight = {colors.magenta, colors.yellow, 'bold'}
}
}
gls.left[3] = {
FileIcon = {
provider = 'FileIcon',
condition = buffer_not_empty,
highlight = {
require('galaxyline.provider_fileinfo').get_file_icon_color,
colors.darkblue
}
}
}
gls.left[4] = {
FileName = {
provider = {'FileName', 'FileSize'},
condition = buffer_not_empty,
separator = ' ',
separator_highlight = {colors.purple, colors.darkblue},
highlight = {colors.magenta, colors.darkblue}
}
}
gls.left[5] = {
GitIcon = {
provider = function() return '  ' end,
condition = buffer_not_empty,
highlight = {colors.orange, colors.purple}
}
}
gls.left[6] = {
GitBranch = {
provider = 'GitBranch',
condition = buffer_not_empty,
highlight = {colors.grey, colors.purple}
}
}
local checkwidth = function()
local squeeze_width = vim.fn.winwidth(0) / 2
if squeeze_width > 40 then return true end
return false
end
gls.left[7] = {
DiffAdd = {
provider = 'DiffAdd',
condition = checkwidth,
icon = ' ',
highlight = {colors.green, colors.purple}
}
}
gls.left[8] = {
DiffModified = {
provider = 'DiffModified',
condition = checkwidth,
icon = ' ',
highlight = {colors.orange, colors.purple}
}
}
gls.left[9] = {
DiffRemove = {
provider = 'DiffRemove',
condition = checkwidth,
icon = ' ',
highlight = {colors.red, colors.purple}
}
}
gls.left[10] = {
LeftEnd = {
provider = function() return ' ' end,
separator = ' ',
separator_highlight = {colors.purple, colors.bg},
highlight = {colors.purple, colors.purple}
}
}
gls.left[11] = {
DiagnosticError = {
provider = 'DiagnosticError',
icon = '  ',
highlight = {colors.red, colors.bg}
}
}
gls.left[12] = {Space = {provider = function() return ' ' end}}
gls.left[13] = {
DiagnosticWarn = {
provider = 'DiagnosticWarn',
icon = '  ',
highlight = {colors.blue, colors.bg}
}
}
gls.right[1] = {
FileFormat = {
provider = 'FileFormat',
separator = ' ',
separator_highlight = {colors.bg, colors.purple},
highlight = {colors.grey, colors.purple}
}
}
gls.right[2] = {
LineInfo = {
provider = 'LineColumn',
separator = ' | ',
separator_highlight = {colors.darkblue, colors.purple},
highlight = {colors.grey, colors.purple}
}
}
gls.right[3] = {
PerCent = {
provider = 'LinePercent',
separator = ' ',
separator_highlight = {colors.darkblue, colors.purple},
highlight = {colors.grey, colors.darkblue}
}
}
gls.right[4] = {
ScrollBar = {
provider = 'ScrollBar',
highlight = {colors.yellow, colors.purple}
}
}
gls.short_line_left[1] = {
BufferType = {
provider = 'FileTypeName',
separator = ' ',
separator_highlight = {colors.purple, colors.bg},
highlight = {colors.grey, colors.purple}
}
}
gls.short_line_right[1] = {
BufferIcon = {
provider = 'BufferIcon',
separator = ' ',
separator_highlight = {colors.purple, colors.bg},
highlight = {colors.grey, colors.purple}
}
}
-- }}}
-- keymaps {{{
nvim.set_keymap("n", "j", "gj", {noremap = true})
nvim.set_keymap("n", "k", "gk", {noremap = true})
nvim.set_keymap("t", "<C-j>", "<C-\\><C-n>", {noremap = true})
nvim.ex.inoremap([[<silent><expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" ]])
nvim.ex.inoremap([[<silent><expr> <S-Tab> pumvisible() ? "\<C-n>" : "\<S-Tab>"]])
-- NvimTree <Space>t でトグル
nvim.set_keymap("n", "<space>t", ":NvimTreeToggle<CR>", {noremap = true, silent = true})
nvim.set_keymap("x", "<space>t", ":NvimTreeToggle<CR>", {noremap = true, silent = true})
-- Telescope <Space>f* で開く
nvim.set_keymap("n", "<Space>ff",
"<cmd>lua require('telescope.builtin').find_files()<CR>",
{noremap = true})
nvim.set_keymap("n", "<Space>fg",
"<cmd>lua require('telescope.builtin').live_grep()<CR>",
{noremap = true})
nvim.set_keymap("n", "<Space>fb",
"<cmd>lua require('telescope.builtin').buffers()<CR>",
{noremap = true})
nvim.set_keymap("n", "<Space>ft",
"<cmd>lua require('telescope.builtin').treesitter()<CR>",
{noremap = true})
nvim.set_keymap("n", "<Space>fh",
"<cmd>lua require('telescope.builtin').help_tags()<CR>",
{noremap = true})
-- Quickhl <Space>mでハイライト、<Space>Mでクリア
nvim.set_keymap("n", "<Space>m", "<Plug>(quickhl-manual-this)",
{noremap = false})
nvim.set_keymap("x", "<Space>m", "<Plug>(quickhl-manual-this)",
{noremap = false})
nvim.set_keymap("n", "<Space>M", "<Plug>(quickhl-manual-reset)",
{noremap = false})
nvim.set_keymap("x", "<Space>M", "<Plug>(quickhl-manual-reset)",
{noremap = false})
-- Glow
nvim.set_keymap("n", "<Space>p", ":Glow<CR>", {noremap = true})
nvim.set_keymap("x", "<Space>p", ":Glow<CR>", {noremap = true})
-- }}}
-- autocmds {{{
augroup("SaveEditPos", function ()
nvim.ex.autocmd("BufReadPost", "*", "if line(\"'\\\"\") > 1 && line(\"'\\\"\") <= line(\"$\") | exe \"normal! g`\\\"\" | endif")
end)
augroup("OptimizeCmdWindow", function ()
nvim.ex.autocmd("CmdwinEnter", "[:\\/\\?=]", "setlocal", "nonumber")
nvim.ex.autocmd("CmdwinEnter", "[:\\/\\?=]", "setlocal", "signcolumn=no")
-- 2字以下のコマンドをコマンドウィンドウから削除
nvim.ex.autocmd("CmdwinEnter", ":", "g/^..\\?$/d")
end)
nvim.ex.autocmd("BufRead,BufNewFile", "tsconfig.json", "setlocal filetype=json5")
set_indents({
{ exts={"lua","css"}, w = 4, expand = true },
{ exts={"tml"}, w = 2, expand = true},
{ exts={"saty"}, w = 2, expand = true },
{ exts={"sh" }, w = 2, expand = true },
{ exts={"html", "yml", "yaml", "graphql" }, w = 2, expand = true },
{ exts={"js", "ts", "mjs", "tsx", "jsx", "json"}, w = 2, expand = true },
})
-- }}}
-- options {{{
vim.opt.wildmenu = true
-- シンタックスハイライトの有効化
-- Neovimはデフォルトで有効化されるはずだがそうならないファイルがある?
vim.opt.syntax = "on"
-- udoファイルを用意
vim.opt.undofile = true
-- デフォルトの折りたたみ方式をmarkerに
vim.opt.foldmethod = "marker"
-- udoの最大値
vim.opt.undolevels = 1024
vim.opt.undoreload = 8192
-- スワップファイルとバックアップファイルを消す
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.writebackup = false
-- デフォルトのインデント設定(最初のバッファに設定すると引き継がれる?)
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = false
vim.opt.autoindent = true
-- guiと同じく2^24色使えるように(一応)
vim.opt.termguicolors = true
-- 行番号をrelativeumberで表示
vim.opt.number = true
vim.opt.relativenumber = true
-- コマンド欄(下の2行)を2行に設定
vim.opt.cmdheight = 2
-- 検索中のハイライトの有効化
vim.opt.hls = true
-- 不可視文字を可視化
vim.opt.list = true
vim.opt.listchars = "tab:»-,trail:-,eol:↲,extends:»,precedes:«,nbsp:%"
-- Coc推奨設定(わからん)
vim.opt.hidden = true
vim.opt.updatetime = 300
-- カラースキーム
nvim.ex.colorscheme("otynium")
-- }}}
-- treesitter {{{
treesitter.setup {
highlight = {
enable = true,
},
indent = {
enable = true,
},
ensure_installed = 'all',
rainbow = {
enable = true,
},
}
-- }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment