Skip to content

Instantly share code, notes, and snippets.

@huytd
Last active October 14, 2023 03:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huytd/7a74f048dd10926a9334ae5b22109fee to your computer and use it in GitHub Desktop.
Save huytd/7a74f048dd10926a9334ae5b22109fee to your computer and use it in GitHub Desktop.
My latest Vim config in Lua
" Hiccup Theme for Vim
" Author: Huy Tran
" License: BSD 3 Clauses
" Put this file to: colors/hiccup.vim
highlight clear
if exists('syntax_on')
syntax reset
endif
set background=dark
let g:colors_name = 'hiccup'
" Color Palette
let s:foreground = '#b7c5d3'
let s:gray1 = '#20242e'
let s:gray2 = '#2a3139'
let s:gray3 = '#333a45'
let s:gray4 = '#546072'
let s:gray5 = '#d8e2ec'
" Github Dark
let s:error = '#d98285'
let s:red = '#d98285'
let s:green = '#85e89d'
let s:yellow = '#ffab70'
let s:blue = '#92b9f0'
let s:purple = '#8acfbb'
let s:cyan = '#73daca'
let s:orange = '#ffab70'
let s:indigo = '#e1e4e8'
function! s:HL(group, fg, bg, attr)
let l:attr = a:attr
if !empty(a:fg)
exec 'hi ' . a:group . ' guifg=' . a:fg
endif
if !empty(a:bg)
exec 'hi ' . a:group . ' guibg=' . a:bg
endif
if !empty(a:attr)
exec 'hi ' . a:group . ' gui=' . l:attr . ' cterm=' . l:attr
endif
endfun
call s:HL('Bold', '', '', 'bold')
call s:HL('Italic', '', '', 'italic')
" Vim Editor
call s:HL('ColorColumn', '', s:gray2, '')
call s:HL('Cursor', s:gray2, s:foreground, '')
call s:HL('CursorColumn', '', s:gray2, '')
call s:HL('CursorLine', '', s:gray2, 'none')
call s:HL('CursorLineNr', s:cyan, s:gray2, 'none')
call s:HL('Directory', s:blue, '', '')
call s:HL('DiffAdd', s:green, s:gray2, 'none')
call s:HL('DiffChange', s:yellow, s:gray2, 'none')
call s:HL('DiffDelete', s:error, s:gray2, 'none')
call s:HL('DiffText', s:blue, s:gray2, 'none')
call s:HL('ErrorMsg', s:error, s:gray1, 'bold')
call s:HL('FoldColumn', s:gray4, s:gray1, '')
call s:HL('Folded', s:gray3, s:gray1, '')
call s:HL('IncSearch', s:yellow, '', '')
call s:HL('LineNr', s:gray3, s:gray1, '')
call s:HL('MatchParen', s:gray4, s:cyan, 'bold')
call s:HL('ModeMsg', s:green, '', '')
call s:HL('MoreMsg', s:green, '', '')
call s:HL('NonText', s:gray4, s:gray1, 'none')
call s:HL('Normal', s:foreground, s:gray1, 'none')
call s:HL('Pmenu', s:foreground, s:gray3, '')
call s:HL('PmenuSbar', '', s:gray2, '')
call s:HL('PmenuSel', s:gray2, s:cyan, '')
call s:HL('PmenuThumb', '', s:gray4, '')
call s:HL('Question', s:blue, '', 'none')
call s:HL('Search', s:gray1, s:yellow, '')
call s:HL('SignColumn', s:foreground, s:gray1, '')
call s:HL('SpecialKey', s:gray4, '', '')
call s:HL('SpellCap', s:blue, s:gray2, 'undercurl')
call s:HL('SpellBad', s:error, s:gray2, 'undercurl')
call s:HL('StatusLine', s:gray4, s:gray3, 'none')
call s:HL('StatusLineNC', s:gray2, s:gray4, '')
call s:HL('TabLine', s:gray4, s:gray2, 'none')
call s:HL('TabLineFill', s:gray4, s:gray2, 'none')
call s:HL('TabLineSel', s:yellow, s:gray3, 'none')
call s:HL('Title', s:green, '', 'none')
call s:HL('VertSplit', s:gray3, s:gray1, 'none')
call s:HL('Visual', s:foreground, s:gray3, '')
call s:HL('WarningMsg', s:error, '', '')
call s:HL('WildMenu', s:gray2, s:cyan, '')
call s:HL('EndOfBuffer', s:gray3, s:gray1, 'none')
" Standard Syntax
call s:HL('Boolean', s:orange, '', '')
call s:HL('Delimiter', s:indigo, '', '')
call s:HL('Float', s:cyan, '', '')
call s:HL('Number', s:cyan, '', '')
call s:HL('Keyword', s:blue, '', '')
call s:HL('StorageClass', s:blue, '', '')
call s:HL('Tag', s:orange, '', '')
call s:HL('Comment', s:gray4, '', 'italic')
call s:HL('Constant', s:purple, '', '')
call s:HL('String', s:green, '', '')
call s:HL('Character', s:green, '', '')
call s:HL('Identifier', s:purple, '', 'none')
call s:HL('Function', s:indigo, '', '')
call s:HL('Statement', s:blue, '', 'none')
call s:HL('Operator', s:red, '', '')
call s:HL('PreProc', s:cyan, '', '')
call s:HL('Include', s:blue, '', '')
call s:HL('Define', s:blue, '', 'none')
call s:HL('Type', s:purple, '', 'none')
call s:HL('Typedef', s:purple, '', 'none')
call s:HL('Structure', s:purple, '', '')
call s:HL('Special', s:indigo, '', '')
call s:HL('Underlined', s:blue, '', 'none')
call s:HL('Error', s:error, s:gray1, 'bold')
call s:HL('Todo', s:orange, s:gray1, 'bold')
hi! link Macro Define
hi! link PreCondit PreProc
" CSS
call s:HL('cssAttrComma', s:gray5, '', '')
call s:HL('cssPseudoClassId', s:green, '', '')
call s:HL('cssBraces', s:gray5, '', '')
call s:HL('cssClassName', s:blue, '', '')
call s:HL('cssClassNameDot', s:gray5, '', '')
call s:HL('cssFunctionName', s:blue, '', '')
call s:HL('cssImportant', s:red, '', '')
call s:HL('cssIncludeKeyword', s:red, '', '')
call s:HL('cssTagName', s:red, '', '')
call s:HL('cssMediaType', s:green, '', '')
call s:HL('cssProp', s:blue, '', '')
call s:HL('cssSelectorOp', s:cyan, '', '')
call s:HL('cssSelectorOp2', s:cyan, '', '')
" Commit Messages (Git)
call s:HL('gitcommitHeader', s:purple, '', '')
call s:HL('gitcommitUnmerged', s:green, '', '')
call s:HL('gitcommitSelectedFile', s:green, '', '')
call s:HL('gitcommitDiscardedFile', s:error, '', '')
call s:HL('gitcommitUnmergedFile', s:yellow, '', '')
call s:HL('gitcommitSelectedType', s:green, '', '')
call s:HL('gitcommitSummary', s:blue, '', '')
call s:HL('gitcommitDiscardedType', s:error, '', '')
hi link gitcommitNoBranch gitcommitBranch
hi link gitcommitUntracked gitcommitComment
hi link gitcommitDiscarded gitcommitComment
hi link gitcommitSelected gitcommitComment
hi link gitcommitDiscardedArrow gitcommitDiscardedFile
hi link gitcommitSelectedArrow gitcommitSelectedFile
hi link gitcommitUnmergedArrow gitcommitUnmergedFile
" HTML
call s:HL('htmlEndTag', s:blue, '', '')
call s:HL('htmlLink', s:red, '', '')
call s:HL('htmlTag', s:blue, '', '')
call s:HL('htmlTitle', s:gray5, '', '')
call s:HL('htmlSpecialTagName', s:blue, '', '')
" Javascript
call s:HL('javaScriptBraces', s:gray5, '', '')
call s:HL('javaScriptNull', s:orange, '', '')
call s:HL('javaScriptIdentifier', s:blue, '', '')
call s:HL('javaScriptNumber', s:orange, '', '')
call s:HL('javaScriptRequire', s:cyan, '', '')
call s:HL('javaScriptReserved', s:blue, '', '')
" pangloss/vim-javascript
call s:HL('jsArrowFunction', s:blue, '', '')
call s:HL('jsAsyncKeyword', s:blue, '', '')
call s:HL('jsExtendsKeyword', s:red, '', '')
call s:HL('jsClassKeyword', s:red, '', '')
call s:HL('jsDocParam', s:green, '', '')
call s:HL('jsDocTags', s:cyan, '', '')
call s:HL('jsForAwait', s:blue, '', '')
call s:HL('jsFlowArgumentDef', s:yellow, '', '')
call s:HL('jsFrom', s:blue, '', '')
call s:HL('jsImport', s:red, '', '')
call s:HL('jsExport', s:red, '', '')
call s:HL('jsExportDefault', s:red, '', '')
call s:HL('jsFuncCall', s:blue, '', '')
call s:HL('jsFunction', s:blue, '', '')
call s:HL('jsGlobalObjects', s:yellow, '', '')
call s:HL('jsGlobalNodeObjects', s:yellow, '', '')
call s:HL('jsModuleAs', s:blue, '', '')
call s:HL('jsNull', s:orange, '', '')
call s:HL('jsStorageClass', s:blue, '', '')
call s:HL('jsTemplateBraces', s:red, '', '')
call s:HL('jsTemplateExpression', s:red, '', '')
call s:HL('jsThis', s:red, '', '')
call s:HL('jsUndefined', s:orange, '', '')
" JSON
call s:HL('jsonBraces', s:gray5, '', '')
" Less
call s:HL('lessAmpersand', s:red, '', '')
call s:HL('lessClassChar', s:yellow, '', '')
call s:HL('lessCssAttribute', s:gray5, '', '')
call s:HL('lessFunction', s:blue, '', '')
call s:HL('lessVariable', s:purple, '', '')
" Markdown
call s:HL('markdownBold', s:yellow, '', 'bold')
call s:HL('markdownCode', s:cyan, '', '')
call s:HL('markdownCodeBlock', s:cyan, '', '')
call s:HL('markdownCodeDelimiter', s:cyan, '', '')
call s:HL('markdownHeadingDelimiter', s:green, '', '')
call s:HL('markdownHeadingRule', s:gray4, '', '')
call s:HL('markdownId', s:purple, '', '')
call s:HL('markdownItalic', s:blue, '', 'italic')
call s:HL('markdownListMarker', s:orange, '', '')
call s:HL('markdownOrderedListMarker', s:orange, '', '')
call s:HL('markdownRule', s:gray4, '', '')
call s:HL('markdownUrl', s:purple, '', '')
call s:HL('markdownUrlTitleDelimiter', s:green, '', '')
" Ruby
call s:HL('rubyInterpolation', s:cyan, '', '')
call s:HL('rubyInterpolationDelimiter', s:indigo, '', '')
call s:HL('rubyRegexp', s:cyan, '', '')
call s:HL('rubyRegexpDelimiter', s:indigo, '', '')
call s:HL('rubyStringDelimiter', s:green, '', '')
" Sass
call s:HL('sassAmpersand', s:red, '', '')
call s:HL('sassClassChar', s:yellow, '', '')
call s:HL('sassMixinName', s:blue, '', '')
call s:HL('sassVariable', s:purple, '', '')
" Vim-Fugitive
call s:HL('diffAdded', s:green, '', '')
call s:HL('diffRemoved', s:error, '', '')
" Vim-Gittgutter
call s:HL('GitGutterAdd', s:green, '', '')
call s:HL('GitGutterChange', s:yellow, '', '')
call s:HL('GitGutterChangeDelete', s:orange, '', '')
call s:HL('GitGutterDelete', s:error, '', '')
" Vim-Signify
hi link SignifySignAdd GitGutterAdd
hi link SignifySignChange GitGutterChange
hi link SignifySignDelete GitGutterDelete
" XML
call s:HL('xmlAttrib', s:yellow, '', '')
call s:HL('xmlEndTag', s:blue, '', '')
call s:HL('xmlTag', s:blue, '', '')
call s:HL('xmlTagName', s:blue, '', '')
hi! link awkArrayElement Identifier
hi! link awkBoolLogic Keyword
hi! link awkBrktRegExp SpecialChar
hi! link awkComma Delimiter
hi! link awkExpression Keyword
hi! link awkFieldVars Identifier
hi! link awkLineSkip Keyword
hi! link awkOperator Operator
hi! link awkRegExp SpecialChar
hi! link awkSearch Keyword
hi! link awkSemicolon Delimiter
hi! link awkSpecialCharacter SpecialChar
hi! link awkSpecialPrintf SpecialChar
hi! link awkVariables Identifier
hi! link cOperator Operator
hi! link cPreCondit PreCondit
hi! link csPreCondit PreCondit
hi! link csType Type
hi! link csXmlTag SpecialComment
hi! link cssAttr Keyword
hi! link cssBraces Delimiter
hi! link cssClassName cssDefinition
hi! link cssColor Number
hi! link cssProp cssDefinition
hi! link cssPseudoClass cssDefinition
hi! link cssPseudoClassId cssPseudoClass
hi! link cssVendor Keyword
" Neovim terminal colors
if has('nvim')
let g:terminal_color_0 = s:gray1
let g:terminal_color_1 = s:red
let g:terminal_color_2 = s:green
let g:terminal_color_3 = s:yellow
let g:terminal_color_4 = s:blue
let g:terminal_color_5 = s:purple
let g:terminal_color_6 = s:cyan
let g:terminal_color_7 = s:gray5
let g:terminal_color_8 = s:gray3
let g:terminal_color_9 = s:red
let g:terminal_color_10 = s:green
let g:terminal_color_11 = s:yellow
let g:terminal_color_12 = s:blue
let g:terminal_color_13 = s:purple
let g:terminal_color_14 = s:cyan
let g:terminal_color_15 = s:gray4
let g:terminal_color_background = g:terminal_color_0
let g:terminal_color_foreground = g:terminal_color_7
endif
-- Install Packer
local install_path = vim.fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
vim.fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.api.nvim_command('packadd packer.nvim')
end
-- Plugins
require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use 'thinca/vim-quickrun'
use 'williamboman/mason.nvim'
use 'williamboman/mason-lspconfig.nvim'
use 'neovim/nvim-lspconfig'
use 'nvim-lua/lsp-status.nvim'
use 'nvim-lua/plenary.nvim'
use 'nvim-telescope/telescope.nvim'
use 'hrsh7th/nvim-cmp'
use 'hrsh7th/cmp-nvim-lsp'
use 'windwp/nvim-autopairs'
use 'simrat39/rust-tools.nvim'
use({
"L3MON4D3/LuaSnip",
tag = "v2.*",
run = "make install_jsregexp"
})
end)
-- Themes
vim.cmd('colorscheme hiccup')
-- Key mappings
vim.g.mapleader = ' '
vim.api.nvim_set_keymap('i', 'jk', '<Esc>', { noremap = true })
vim.api.nvim_set_keymap('n', '<Leader>e', ':QuickRun<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<Leader>pf', '<cmd>Telescope find_files theme=get_dropdown previewer=false<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>f', "<cmd>lua require('telescope.builtin').find_files({ cwd = vim.fn.expand('%:p:h'), theme=get_dropdown, previewer=false, path_display= { 'absolute' } })<CR>", {noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>pr', '<cmd>Telescope oldfiles theme=get_dropdown previewer=false<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '\\', '<cmd>Telescope live_grep theme=get_dropdown<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>s', '<cmd>Telescope lsp_document_symbols theme=get_dropdown<CR>', {noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>l', ':vsplit<CR>', { noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>k', ':split<CR>', { noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>c', ':close<CR>', { noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>wl', ':wincmd l<CR>', { noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>wh', ':wincmd h<CR>', { noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>wk', ':wincmd k<CR>', { noremap = true})
vim.api.nvim_set_keymap('n', '<Leader>wj', ':wincmd j<CR>', { noremap = true})
-- Quickrun
vim.api.nvim_exec([[
let g:quickrun_config = {}
let g:quickrun_config.cpp = {
\ 'command' : 'g++',
\ 'cmdopt' : '-std=c++17',
\ }
]], false)
-- Autopairs
require('nvim-autopairs').setup{}
-- LSP Config
require('mason').setup()
require('mason-lspconfig').setup {
ensure_installed = { "gopls", "clangd", "rust_analyzer", "denols" }
}
local lspconfig = require('lspconfig')
local lsp_defaults = lspconfig.util.default_config
local lsp_capabilities = vim.tbl_deep_extend(
'force',
lsp_defaults.capabilities,
require('cmp_nvim_lsp').default_capabilities()
)
lsp_defaults.capabilities = lsp_capabilities
vim.api.nvim_create_autocmd('LspAttach', {
desc = 'LSP actions',
callback = function()
local bufmap = function(mode, lhs, rhs)
local opts = {buffer = true}
vim.keymap.set(mode, lhs, rhs, opts)
end
-- Displays hover information about the symbol under the cursor
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
-- Jump to the definition
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
-- Jump to declaration
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
-- Lists all the implementations for the symbol under the cursor
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
-- Jumps to the definition of the type symbol
bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
-- Lists all the references
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
-- Displays a function's signature information
bufmap('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
-- Renames all references to the symbol under the cursor
bufmap('n', 'gM', '<cmd>lua vim.lsp.buf.rename()<cr>')
-- Selects a code action available at the current cursor position
bufmap('n', 'ga', '<cmd>lua vim.lsp.buf.code_action()<cr>')
bufmap('x', 'ga', '<cmd>lua vim.lsp.buf.range_code_action()<cr>')
-- Show diagnostics in a floating window
bufmap('n', 'gl', '<cmd>lua vim.diagnostic.open_float()<cr>')
-- Move to the previous diagnostic
bufmap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
-- Move to the next diagnostic
bufmap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<cr>')
end
})
lspconfig.rust_analyzer.setup{}
lspconfig.gopls.setup{}
lspconfig.clangd.setup{}
lspconfig.denols.setup{}
require('rust-tools').setup({
server = {
standalone = true,
capabilities = lsp_capabilities
}
})
-- Completion
local luasnip = require('luasnip')
local cmp = require("cmp")
cmp.setup({
sources = {
{name = 'path'},
{name = 'luasnip'},
{name = 'nvim_lsp', keyword_length = 1},
{name = 'buffer', keyword_length = 3},
},
window = {
documentation = cmp.config.window.bordered()
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end
},
mapping = {
['<Up>'] = cmp.mapping.select_prev_item(select_opts),
['<Down>'] = cmp.mapping.select_next_item(select_opts),
['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
['<C-n>'] = cmp.mapping.select_next_item(select_opts),
['<C-u>'] = cmp.mapping.scroll_docs(-4),
['<C-d>'] = cmp.mapping.scroll_docs(4),
['<C-e>'] = cmp.mapping.abort(),
['<C-y>'] = cmp.mapping.confirm({select = true}),
['<CR>'] = cmp.mapping.confirm({select = false}),
['<C-f>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(1) then
luasnip.jump(1)
else
fallback()
end
end, {'i', 's'}),
['<C-b>'] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {'i', 's'}),
['<Tab>'] = cmp.mapping(function(fallback)
local col = vim.fn.col('.') - 1
if cmp.visible() then
cmp.select_next_item(select_opts)
elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
fallback()
else
cmp.complete()
end
end, {'i', 's'}),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item(select_opts)
else
fallback()
end
end, {'i', 's'}),
},
})
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
vim.lsp.handlers.hover,
{border = 'rounded'}
)
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
vim.lsp.handlers.signature_help,
{border = 'rounded'}
)
local lsp_status = require('lsp-status')
lsp_status.register_progress()
function lsp_status_info()
return lsp_status.status()
end
-- Statusline
vim.opt.statusline = "%<%f %h%m%r %= %{luaeval('lsp_status_info()')} %4l:%4c"
-- Other configs
vim.opt.number = true
vim.opt.clipboard = "unnamedplus"
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.copyindent = true
vim.opt.preserveindent = true
vim.opt.undofile = true
vim.opt.undodir = os.getenv("HOME") .. "/.config/nvim/undo"
vim.opt.undolevels = 1000
vim.opt.undoreload = 10000
vim.opt.updatetime = 300
vim.opt.wildoptions = pum
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
vim.opt.termguicolors = true
vim.api.nvim_command([[autocmd BufWritePre * %s/\s\+$//e]])
vim.api.nvim_command([[autocmd BufWritePre *.go :silent! lua require('go.format').gofmt()]])
@baomatest
Copy link

hello tác giả , xin hỏi thí chủ dùng neovim kết hợp với gì mà dòm thấy giống kiểu editer thế

@baomatest
Copy link

có thể chia sẻ cho tại hạ cách dùng emac được ko , tại hạ sẽ chia sẻ cho thí chủ cách dùng neovim xịn hơn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment