neovim: add indent-blankline, use which-key for mappings

Also add more nord highlight groups
This commit is contained in:
FollieHiyuki 2021-07-08 23:08:10 +03:00
parent 26d870a30a
commit 8396fe1ae1
No known key found for this signature in database
GPG Key ID: 813CF484F4993419
14 changed files with 312 additions and 147 deletions

View File

@ -1,18 +1,13 @@
local M = {}
local function hi(group, guifg, guibg, attr, guisp)
if guifg ~= '' then
vim.cmd('hi ' .. group .. ' guifg=' .. guifg)
end
if guibg ~= '' then
vim.cmd('hi ' .. group .. ' guibg=' .. guibg)
end
if attr ~= '' then
vim.cmd('hi ' .. group .. ' gui=' .. attr)
end
if guisp ~= '' then
vim.cmd('hi ' .. group .. ' guisp=' .. guisp)
end
local fg = guifg ~= '' and 'guifg=' .. guifg or 'guifg=NONE'
local bg = guibg ~= '' and 'guibg=' .. guibg or 'guibg=NONE'
local style = attr ~= '' and 'gui=' .. attr or 'gui=NONE'
local sp = guisp ~= '' and 'guisp=' .. guisp or ''
local hl = 'hi ' .. group .. ' ' .. fg .. ' ' .. bg .. ' ' .. style .. ' ' .. sp
vim.cmd(hl)
end
M.colors = {
@ -33,8 +28,7 @@ M.colors = {
yellow = '#EBCB8B',
green = '#A3BE8C',
purple = '#B48EAD',
highlight = '#7B88A1',
none = 'NONE'
highlight = '#7B88A1'
}
local c = M.colors
@ -57,14 +51,14 @@ function M.highlight()
-- Editor
hi('ColorColumn', '' , c.grey1, '', '')
hi('Cursor' , c.black , c.fg , '', '')
hi('CursorLine' , c.grey1 , '' , 'NONE', '')
hi('CursorLine' , c.grey1 , '' , '', '')
hi('Error' , c.fg , c.red , '', '')
hi('iCursor' , c.black , c.fg , '', '')
hi('LineNr' , c.grey3 , c.none , '', '')
hi('LineNr' , c.grey3 , '' , '', '')
hi('MatchParen' , c.cyan , c.grey3, '', '')
hi('NonText' , c.grey2 , '' , '', '')
hi('Normal' , c.fg , c.black, '', '')
hi('Pmenu' , c.fg , c.grey2, 'NONE', '')
hi('Pmenu' , c.fg , c.grey2, '', '')
hi('PmenuSbar' , c.fg , c.grey2, '', '')
hi('PmenuSel' , c.cyan , c.grey3, '', '')
hi('PmenuThumb' , c.cyan , c.grey3, '', '')
@ -83,8 +77,8 @@ function M.highlight()
-- Gutter
hi('CursorColumn', c.grey1, '' , '', '')
hi('CursorLineNr', c.fg , '' , 'NONE', '')
hi('Folded' , c.grey3, c.grey1, 'bold', '')
hi('CursorLineNr', c.fg , '' , '', '')
hi('Folded' , c.grey3, c.grey1, '', '')
hi('FoldColumn' , c.grey3, c.black, '', '')
hi('SignColumn' , c.grey1, c.black, '', '')
@ -101,23 +95,23 @@ function M.highlight()
hi('WildMenu' , c.cyan , c.grey1 , '', '')
-- Statusline
hi('StatusLine' , c.cyan, c.grey3, 'NONE', '')
hi('StatusLineNC' , c.fg , c.grey3, 'NONE', '')
hi('StatusLineTerm' , c.cyan, c.grey3, 'NONE', '')
hi('StatusLineTermNC', c.fg , c.grey3, 'NONE', '')
hi('StatusLine' , c.cyan, c.grey3, '', '')
hi('StatusLineNC' , c.fg , c.grey3, '', '')
hi('StatusLineTerm' , c.cyan, c.grey3, '', '')
hi('StatusLineTermNC', c.fg , c.grey3, '', '')
-- Search
hi('IncSearch', c.white2, c.dark_blue, 'underline', '')
hi('Search' , c.grey1 , c.cyan , 'NONE' , '')
hi('Search' , c.grey1 , c.cyan , '' , '')
-- Tabline
hi('TabLine' , c.fg , c.grey1, 'NONE', '')
hi('TabLineFill', c.fg , c.grey1, 'NONE', '')
hi('TabLineSel' , c.cyan, c.grey3, 'NONE', '')
hi('TabLine' , c.fg , c.grey1, '', '')
hi('TabLineFill', c.fg , c.grey1, '', '')
hi('TabLineSel' , c.cyan, c.grey3, '', '')
-- Window
hi('Title', c.fg, '', 'NONE', '')
hi('VertSplit', c.grey2, c.black, 'NONE', '')
hi('Title', c.fg, '', '', '')
hi('VertSplit', c.grey2, c.black, '', '')
--------------------------
-- Language base groups --
@ -133,13 +127,13 @@ function M.highlight()
hi('Exception', c.blue, '', '', '')
hi('Float', c.purple, '', '', '')
hi('Function', c.cyan, '', '', '')
hi('Identifier', c.fg, '', 'NONE', '')
hi('Identifier', c.fg, '', '', '')
hi('Include', c.blue, '', '', '')
hi('Keyword', c.blue, '', '', '')
hi('Label', c.blue, '', '', '')
hi('Number', c.purple, '', '', '')
hi('Operator', c.blue, '', 'NONE', '')
hi('PreProc', c.blue, '', 'NONE', '')
hi('Operator', c.blue, '', '', '')
hi('PreProc', c.blue, '', '', '')
hi('Repeat', c.blue, '', '', '')
hi('Special', c.fg, '', '', '')
hi('SpecialChar', c.yellow, '', '', '')
@ -149,8 +143,8 @@ function M.highlight()
hi('String', c.green, '', '', '')
hi('Structure', c.blue, '', '', '')
hi('Tag', c.fg, '', '', '')
hi('Todo', c.yellow, c.none, '', '')
hi('Type', c.blue, '', 'NONE', '')
hi('Todo', c.yellow, '', '', '')
hi('Type', c.blue, '', '', '')
hi('Typedef', c.blue, '', '', '')
vim.cmd('hi! link Macro Define')
vim.cmd('hi! link PreCondit PreProc')
@ -189,6 +183,15 @@ function M.highlight()
hi('DiffChange', c.yellow, c.grey1, '', '')
hi('DiffDelete', c.red , c.grey1, '', '')
hi('DiffText' , c.blue , c.grey1, '', '')
-- Legacy diff groups for some plugins
hi('diffOldFile', c.dark_blue, c.grey1, '', '')
hi('diffNewFile', c.blue, c.grey1, '', '')
hi('diffFile', c.cyan, c.grey1, '', '')
hi('diffLine', c.purple, c.grey1, '', '')
hi('diffIndexLine', c.fg, c.grey1, '', '')
vim.cmd('hi! link diffAdded DiffAdd')
vim.cmd('hi! link diffRemoved DiffDelete')
vim.cmd('hi! link diffChanged DiffChange')
---------------------
-- Plugins' groups --
@ -198,12 +201,41 @@ function M.highlight()
hi('GitSignsChangeNr', c.yellow, '', '', '')
hi('GitSignsDeleteNr', c.red , '', '', '')
-- BufferLine
hi('BufferLineIndicatorSelected', c.black, '', '', '')
hi('BufferLineFill', c.black, '', '', '')
-- Dashboard
hi('DashboardHeader' , c.cyan , '', 'bold' , '')
hi('DashboardCenter' , c.blue , '', 'bold' , '')
hi('DashboardShortcut', c.grey_bright, '', 'bold,italic', '')
hi('DashboardFooter' , c.green , '', 'bold' , '')
-- NvimTree
hi('NvimTreeRootFolder' , c.teal , '', 'bold', '')
hi('NvimTreeGitDirty' , c.yellow , '', '', '')
hi('NvimTreeGitNew' , c.green , '', '', '')
hi('NvimTreeImageFile' , c.purple , '', '', '')
hi('NvimTreeExecFile' , c.green , '', '', '')
hi('NvimTreeSpecialFile' , c.dark_blue, '', 'underline', '')
hi('NvimTreeFolderName' , c.blue , '', '', '')
hi('NvimTreeEmptyFolderName', c.grey3 , '', '', '')
hi('NvimTreeFolderIcon' , c.fg , '', '', '')
hi('NvimTreeIndentMarker' , c.grey3 , '', '', '')
hi('NvimTreeNormal' , c.fg , c.black, '', '')
-- WhichKey
hi('WhichKey' , c.green , '', 'bold', '')
hi('WhichKeyGroup' , c.cyan , '', '' , '')
hi('WhichKeyDesc' , c.blue , '', '' , '')
hi('WhichKeySeperator', c.grey3 , '', '' , '')
hi('WhichKeyFloating' , c.fg , '', '' , '')
hi('WhichKeyFloat' , c.grey_bright, '', '' , '')
-- Indent Blankline
hi('IndentBlanklineChar', c.grey1, '', '', '')
hi('IndentBlanklineContextChar', c.grey1, '', '', '')
-- ts-rainbow
hi('rainbowcol1', c.red, '', 'bold', '')
hi('rainbowcol2', c.orange, '', 'bold', '')
@ -212,6 +244,39 @@ function M.highlight()
hi('rainbowcol5', c.cyan, '', 'bold', '')
hi('rainbowcol6', c.blue, '', 'bold', '')
hi('rainbowcol7', c.purple, '', 'bold', '')
-- Treesitter
hi('TSAnnotation' , c.orange, '', '', '')
hi('TSCharacter' , c.fg , '', '', '')
hi('TSConstructor' , c.blue , '', '', '')
hi('TSConstant' , c.fg , '', '', '')
hi('TSFloat' , c.purple, '', '', '')
hi('TSNumber' , c.purple, '', '', '')
hi('TSString' , c.green , '', '', '')
hi('TSAttribute' , c.purple, '', '', '')
hi('TSBoolean' , c.blue , '', '', '')
hi('TSConstBuiltin', c.teal , '', '', '')
hi('TSConstMacro' , c.teal , '', '', '')
hi('TSError' , c.fg , c.red, '', '')
hi('TSException' , c.red , '', 'underline', '')
hi('TSField' , c.fg , '', '', '')
hi('TSFuncMacro' , c.cyan , '', '', '')
hi('TSInclude' , c.teal , '', '', '')
hi('TSLabel' , c.blue , '', '', '')
hi('TSNamespace' , c.teal , '', '', '')
hi('TSOperator' , c.blue , '', '', '')
hi('TSParameter' , c.dark_blue, '', '', '')
hi('TSParameterReference', c.dark_blue, '', '', '')
hi('TSProperty' , c.fg , '', '', '')
hi('TSPunctDelimiter', c.white2, '', '', '')
hi('TSPunctBracket', c.white2, '', '', '')
hi('TSPunctSpecial', c.white2 , '', '', '')
hi('TSStringRegex' , c.teal, '', '', '')
hi('TSStringEscape', c.grey2, '', '', '')
hi('TSSymbol' , c.purple, '', '', '')
hi('TSType' , c.blue , '', '', '')
hi('TSTypeBuiltin' , c.blue, '', '', '')
hi('TSTag' , c.teal, '', '', '')
end
return M

View File

@ -1,18 +1,13 @@
local M = {}
local function hi(group, guifg, guibg, attr, guisp)
if guifg ~= '' then
vim.cmd('hi ' .. group .. ' guifg=' .. guifg)
end
if guibg ~= '' then
vim.cmd('hi ' .. group .. ' guibg=' .. guibg)
end
if attr ~= '' then
vim.cmd('hi ' .. group .. ' gui=' .. attr)
end
if guisp ~= '' then
vim.cmd('hi ' .. group .. ' guisp=' .. guisp)
end
local fg = guifg ~= '' and 'guifg=' .. guifg or 'guifg=NONE'
local bg = guibg ~= '' and 'guibg=' .. guibg or 'guibg=NONE'
local style = attr ~= '' and 'gui=' .. attr or 'gui=NONE'
local sp = guisp ~= '' and 'guisp=' .. guisp or ''
local hl = 'hi ' .. group .. ' ' .. fg .. ' ' .. bg .. ' ' .. style .. ' ' .. sp
vim.cmd(hl)
end
M.colors = {
@ -34,8 +29,7 @@ M.colors = {
yellow = '#E5C07B',
green = '#98C379',
purple = '#C678DD',
highlight = '#9CA0A4',
none = 'NONE'
highlight = '#9CA0A4'
}
local c = M.colors

View File

@ -22,8 +22,11 @@ end
function M.load_autocmds()
local definitions = {
packer = {
{"BufWritePost", "*.lua", "lua require('events').packer_compile()"}
plugins = {
-- Re-compile packer on config changed
{"BufWritePost", "*.lua", "lua require('events').packer_compile()"},
-- Blankline is lazy-load
{"CursorMoved", [[* IndentBlanklineRefresh]]}
},
-- Edit binary files in hex with xxd (:%!xxd and :%!xxd -r)

View File

@ -1,47 +1,45 @@
local function map(mode, lhs, rhs, opts)
local options = {noremap = true, silent = true}
if opts then
options = vim.tbl_extend('force', options, opts)
end
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end
local opt = {}
local api = vim.api
local wk = require('which-key')
--------------------
-- Basic bindings --
--------------------
-- No one likes Esc
map('i', 'jk', [[<Esc>]], opt)
api.nvim_set_keymap('i', 'jk', [[<Esc>]], {noremap = true, silent = true})
-- Better Y
map('n', 'Y', [[y$]], opt)
-- Escape to normal mode in terminal buffer
api.nvim_set_keymap('t', '<Esc>', '<C-\\><C-n>', {noremap = true, silent = true})
-- Continuous indent
map('v', '<', '<gv', opt)
map('v', '>', '>gv', opt)
api.nvim_set_keymap('v', '<', '<gv', {noremap = true, silent = true})
api.nvim_set_keymap('v', '>', '>gv', {noremap = true, silent = true})
-- Escape mode in terminal buffer
map('t', '<Esc>', '<C-\\><C-n>', opt)
-- Normal mode
wk.register({
-- Better Y
Y = {'y$', 'Yank to eol'},
-- Copy the whole buffer
map('n', '<C-a>', [[ <Cmd> %y+<CR>]], opt)
-- 'Legacy' save file
-- map('n', '<C-s>', ':w <CR>', opt)
['<C-a>'] = {'<Cmd>%y+<CR>', 'Copy whole buffer'},
-- 'Legacy' save buffer
-- ['<C-s>'] = {':w<CR>', 'Write buffer'},
-- Close buffer
map('n', '<C-x>', ':bd!<CR>', opt)
['<C-x>'] = {':bd!<CR>', 'Close buffer'},
-- Remove trailing whitespace
map('n', '<A-w>', ':%s/\\s\\+$//e<CR>', opt)
['<A-w>'] = {':%s/\\s\\+$//e<CR>', 'Remove trailing'},
-- Resize buffer
map('n', '<A-j>', ':resize -2<CR>', opt)
map('n', '<A-k>', ':resize +2<CR>', opt)
map('n', '<A-h>', ':vertical resize -2<CR>', opt)
map('n', '<A-l>', ':vertical resize +2<CR>', opt)
['<A-j>'] = {':resize -2<CR>', 'Resize vertical -2'},
['<A-k>'] = {':resize +2<CR>', 'Resize vertical +2'},
['<A-h>'] = {':vertical resize -2<CR>', 'Resize horizontal -2'},
['<A-l>'] = {':vertical resize +2<CR>', 'Resize horizontal +2'},
-- Switch between tabs and spaces
function toggleIndentStyle()
['<A-t>'] = {
function()
if vim.o.expandtab == true then
vim.cmd('set noexpandtab nosmarttab softtabstop& shiftwidth&')
vim.cmd('echomsg "Switched to indent with tabs"')
@ -52,23 +50,23 @@ function toggleIndentStyle()
vim.opt.shiftwidth = 4
vim.cmd('echomsg "Switched to indent with 4 spaces"')
end
end
map('n', '<A-t>', ':lua toggleIndentStyle()<CR>', opt)
end,
'Switch indent style'
},
-- Move between tabs
map('n', '<TAB>', [[<Cmd>BufferLineCycleNext<CR>]], opt)
map('n', '<S-TAB>', [[<Cmd>BufferLineCyclePrev<CR>]], opt)
-- Naming common keys
['['] = {name = 'Block motions (previous)'},
[']'] = {name = 'Block motions (next)'},
g = {name = 'Goto motions'},
z = {name = 'Misc utils'}
})
-- NvimTree
map('n', '<C-n>', ':NvimTreeToggle<CR>', opt)
---------------
-- Which-key --
---------------
local wk = require('which-key')
-- Don't need to show bufferline numbers
-------------
-- Plugins --
-------------
-- Normal mode
wk.register({
-- Don't need to show bufferline numbers
['<leader>1'] = 'which_key_ignore',
['<leader>2'] = 'which_key_ignore',
['<leader>3'] = 'which_key_ignore',
@ -77,7 +75,51 @@ wk.register({
['<leader>6'] = 'which_key_ignore',
['<leader>7'] = 'which_key_ignore',
['<leader>8'] = 'which_key_ignore',
['<leader>9'] = 'which_key_ignore'
})
['<leader>9'] = 'which_key_ignore',
-- Move between tabs
['<TAB>'] = {'<Cmd>BufferLineCycleNext<CR>', 'Next buffer'},
['<S-TAB>'] = {'<Cmd>BufferLineCyclePrev<CR>', 'Previous buffer'},
-- NvimTree
['<C-n>'] = {':NvimTreeToggle<CR>', 'NvimTree'},
-- ToggleTerm
['<C-\\>'] = 'Toggle terminal',
})
-- With leader key (normal mode)
wk.register({
-- GitSigns
g = {
name = 'Git',
b = 'Blame current line',
i = 'Preview hunk',
n = 'Next hunk',
p = 'Previous hunk',
r = 'Reset hunk',
R = 'Reset all hunks in buffer',
s = 'Stage hunk',
u = 'Undo hunk'
},
-- Telescope
f = {
name = 'Telescope'
},
b = {
name = 'Buffer',
n = {':DashboardNewFile<CR>', 'New file'}
}
}, {prefix = '<leader>'})
-- With leader key (visual mode)
wk.register({
-- GitSigns
g = {
name = 'Git',
r = 'Reset hunk',
s = 'Stage hunk'
}
}, {mode = 'v', prefix = '<leader>'})

View File

@ -0,0 +1,45 @@
local function blankline_options()
vim.g.indent_blankline_char = ''
vim.g.indent_blankline_show_first_indent_level = true
vim.g.indent_blankline_filetype_exclude = {
'startify',
'dashboard',
'dotooagenda',
'log',
'fugitive',
'gitcommit',
'packer',
'vimwiki',
'markdown',
'json',
'txt',
'vista',
'help',
'todoist',
'NvimTree',
'peekaboo',
'git',
'TelescopePrompt',
'undotree',
'flutterToolsOutline',
'' -- for all buffers without a file type
}
vim.g.indent_blankline_buftype_exclude = {'terminal', 'nofile'}
vim.g.indent_blankline_show_trailing_blankline_indent = false
vim.g.indent_blankline_show_current_context = true
vim.g.indent_blankline_context_patterns = {
'class',
'function',
'method',
'block',
'list_literal',
'selector',
'^if',
'^table',
'if_statement',
'while',
'for'
}
end
blankline_options()

View File

@ -1,4 +1,4 @@
return require('colorizer').setup(
return require('colorizer').setup {
{'*'},
{
RGB = true, -- #RGB hex codes
@ -11,4 +11,4 @@ return require('colorizer').setup(
css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn
mode = 'background' -- Set the display mode.
}
)
}

View File

@ -10,8 +10,7 @@ local function dashboard_options()
b = {description = {' Recents SPC f o'}, command = 'Telescope oldfiles'},
c = {description = {' Find Word SPC f w'}, command = 'Telescope live_grep'},
d = {description = {'洛 New File SPC b n'}, command = 'DashboardNewFile'},
e = {description = {' Bookmarks SPC f m'}, command = 'Telescope marks'},
f = {description = {' Load Last Session SPC s l'}, command = 'SessionLoad'}
e = {description = {' Bookmarks SPC f m'}, command = 'Telescope marks'}
}
vim.g.dashboard_custom_header = {
" ",

View File

@ -12,8 +12,8 @@ return require('gitsigns').setup {
noremap = true,
buffer = true,
['n ]c'] = { expr = true, '&diff ? \']c\' : \'<cmd>lua require"gitsigns.actions".next_hunk()<CR>\''},
['n [c'] = { expr = true, '&diff ? \'[c\' : \'<cmd>lua require"gitsigns.actions".prev_hunk()<CR>\''},
['n <leader>gn'] = {expr = true, '&diff ? \'<leader>gn\' : \'<cmd>lua require"gitsigns.actions".next_hunk()<CR>\''},
['n <leader>gp'] = {expr = true, '&diff ? \'<leader>gp\' : \'<cmd>lua require"gitsigns.actions".prev_hunk()<CR>\''},
['n <leader>gs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
['v <leader>gs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
@ -21,7 +21,7 @@ return require('gitsigns').setup {
['n <leader>gr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
['v <leader>gr'] = '<cmd>lua require"gitsigns".reset_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
['n <leader>gR'] = '<cmd>lua require"gitsigns".reset_buffer()<CR>',
['n <leader>gp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
['n <leader>gi'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
['n <leader>gb'] = '<cmd>lua require"gitsigns".blame_line(true)<CR>'
},
watch_index = {

View File

@ -1,7 +1,4 @@
local M = {}
M.config = function()
require('toggleterm').setup {
return require('toggleterm').setup {
open_mapping = [[<c-\>]],
shade_terminals = false,
float_opts = {
@ -15,6 +12,3 @@ M.config = function()
}
}
}
end
return M

View File

@ -0,0 +1,16 @@
return require('which-key').setup {
plugins = {
spelling = {
enabled = true,
suggestions = 30
}
},
icons = {
breadcrumb = "»",
separator = "",
group = "+"
},
layout = {
align = 'center'
}
}

View File

@ -6,7 +6,7 @@ local function load_options()
vim.cmd('set iskeyword+=-')
-- General settings
opt.mouse = 'a'
opt.mouse = 'nv'
opt.errorbells = false
opt.visualbell = false
opt.hidden = true

View File

@ -43,14 +43,16 @@ return packer.startup(
}
use {
'folke/which-key.nvim',
require('which-key').setup()
config = function()
require('modules.whichkey')
end
}
-- Utils
use {
'akinsho/nvim-toggleterm.lua',
config = function()
require('modules.terminal').config()
require('modules.terminal')
end
}
@ -72,6 +74,12 @@ return packer.startup(
vim.cmd('ColorizerReloadAllBuffers')
end
}
use {
'lukas-reineke/indent-blankline.nvim',
config = function()
require('modules.blankline')
end
}
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate',

View File

@ -304,7 +304,6 @@ disabled = false
python_binary = "python3"
pyenv_version_name = false
pyenv_prefix = "pyenv"
scan_for_pyfiles = true
symbol = " "
style = "yellow bold"
format = "via [${symbol}${pyenv_prefix}${version}( \\($virtualenv\\))]($style) "