Created
September 13, 2022 18:53
-
-
Save YukiNagat0/f3c4acb249c290b8c7d5c2a7f68ccd37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set mouse=v " middle-click paste with | |
set mouse=a " enable mouse | |
set encoding=utf-8 " set encoding | |
set number " set line ordering | |
set nocompatible | |
set showmatch | |
set ignorecase | |
set hlsearch | |
set incsearch | |
set noswapfile " disable creating swapfile | |
syntax on | |
set clipboard=unnamedplus " using system clipboard | |
filetype plugin on | |
set ttyfast " Speed up scrolling in Vim | |
set scrolloff=7 " scroll off | |
" features for tab | |
set tabstop=4 | |
set softtabstop=4 | |
set shiftwidth=4 | |
set expandtab | |
set autoindent | |
set fileformat=unix | |
set wildmode=longest,list " get bash-like tab completions | |
filetype plugin indent on | |
inoremap jk <esc> | |
call plug#begin('~/.vim/plugged') | |
Plug 'neovim/nvim-lspconfig' | |
Plug 'hrsh7th/nvim-cmp' | |
Plug 'hrsh7th/cmp-nvim-lsp' | |
Plug 'saadparwaiz1/cmp_luasnip' | |
Plug 'L3MON4D3/LuaSnip' | |
Plug 'preservim/nerdcommenter' | |
Plug 'SirVer/ultisnips' | |
Plug 'honza/vim-snippets' | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
" Color theme | |
Plug 'folke/tokyonight.nvim', { 'branch': 'main' } | |
Plug 'xiyaowong/nvim-transparent' | |
Plug 'pocco81/auto-save.nvim' | |
Plug 'justinmk/vim-sneak' | |
Plug 'jose-elias-alvarez/null-ls.nvim' | |
Plug 'nvim-lua/plenary.nvim' | |
Plug 'prettier/vim-prettier', { | |
\ 'do': 'npm install --frozen-lockfile --production', | |
\ 'for': ['css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'svelte', 'yaml', 'html'] } | |
Plug 'bmatcuk/stylelint-lsp' | |
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' } | |
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' } | |
" Convenient floating terminal window | |
"Plug 'voldikss/vim-floaterm' | |
call plug#end() | |
" move line or visually selected block - alt+j/k | |
inoremap <A-j> <Esc>:m .+1<CR>==gi | |
inoremap <A-k> <Esc>:m .-2<CR>==gi | |
vnoremap <A-j> :m '>+1<CR>gv=gv | |
vnoremap <A-k> :m '<-2<CR>gv=gv | |
" move split panes to left/bottom/top/right | |
nnoremap <A-h> <C-W>H | |
nnoremap <A-j> <C-W>J | |
nnoremap <A-k> <C-W>K | |
nnoremap <A-l> <C-W>L | |
" move between panes to left/bottom/top/right | |
nnoremap <C-h> <C-w>h | |
nnoremap <C-j> <C-w>j | |
nnoremap <C-k> <C-w>k | |
nnoremap <C-l> <C-w>l | |
" Press i to enter insert mode, and ii to exit insert mode. | |
:inoremap ii <Esc> | |
:inoremap jk <Esc> | |
:inoremap kj <Esc> | |
:vnoremap jk <Esc> | |
:vnoremap kj <Esc> | |
" open file in a text by placing text and gf | |
nnoremap gf :vert winc f<cr> | |
" copies filepath to clipboard by pressing yf | |
:nnoremap <silent> yf :let @+=expand('%:p')<CR> | |
" copies pwd to clipboard: command yd | |
:nnoremap <silent> yd :let @+=expand('%:p:h')<CR> | |
" Vim jump to the last position when reopening a file | |
if has("autocmd") | |
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | |
\| exe "normal! g'\"" | endif | |
endif | |
" Leader bind to space | |
let mapleader = "," | |
" Netrw file explorer settings | |
let g:netrw_banner = 0 " hide banner above files | |
let g:netrw_liststyle = 3 " tree instead of plain view | |
let g:netrw_browse_split = 3 " vertical split window when Enter pressed on file | |
" Automatically format frontend files with prettier after file save | |
let g:prettier#autoformat = 1 | |
let g:prettier#autoformat_require_pragma = 0 | |
" Disable quickfix window for prettier | |
let g:prettier#quickfix_enabled = 0 | |
" Turn on vim-sneak | |
let g:sneak#label = 1 | |
if (has('termguicolors')) | |
set termguicolors | |
endif | |
" turn off search highlight | |
nnoremap ,<space> :nohlsearch<CR> | |
lua << EOF | |
require("tokyonight").setup({ | |
-- your configuration comes here | |
-- or leave it empty to use the default settings | |
style = "storm", -- The theme comes in three styles, `storm`, a darker variant `night` and `day` | |
transparent = true, -- Enable this to disable setting the background color | |
terminal_colors = true, -- Configure the colors used when opening a `:terminal` in Neovim | |
styles = { | |
-- Style to be applied to different syntax groups | |
-- Value is any valid attr-list value for `:help nvim_set_hl` | |
comments = { italic = true }, | |
keywords = { italic = true }, | |
functions = {}, | |
variables = {}, | |
-- Background styles. Can be "dark", "transparent" or "normal" | |
sidebars = "dark", -- style for sidebars, see below | |
floats = "dark", -- style for floating windows | |
}, | |
sidebars = { "qf", "help" }, -- Set a darker background on sidebar-like windows. For example: `["qf", "vista_kind", "terminal", "packer"]` | |
day_brightness = 0.3, -- Adjusts the brightness of the colors of the **Day** style. Number between 0 and 1, from dull to vibrant colors | |
hide_inactive_statusline = false, -- Enabling this option, will hide inactive statuslines and replace them with a thin border instead. Should work with the standard **StatusLine** and **LuaLine**. | |
dim_inactive = false, -- dims inactive windows | |
lualine_bold = false, -- When `true`, section headers in the lualine theme will be bold | |
--- You can override specific color groups to use other groups or a hex color | |
--- function will be called with a ColorScheme table | |
---@param colors ColorScheme | |
on_colors = function(colors) end, | |
--- You can override specific highlights to use other groups or a hex color | |
--- function will be called with a Highlights and ColorScheme table | |
---@param highlights Highlights | |
---@param colors ColorScheme | |
on_highlights = function(highlights, colors) end, | |
}) | |
EOF | |
" Vim Script | |
colorscheme tokyonight | |
" There are also colorschemes for the different styles | |
colorscheme tokyonight-storm | |
lua << EOF | |
-- Set completeopt to have a better completion experience | |
vim.o.completeopt = 'menuone,noselect' | |
-- luasnip setup | |
local luasnip = require 'luasnip' | |
local async = require "plenary.async" | |
-- nvim-cmp setup | |
local cmp = require 'cmp' | |
cmp.setup { | |
completion = { | |
autocomplete = false | |
}, | |
snippet = { | |
expand = function(args) | |
require('luasnip').lsp_expand(args.body) | |
end, | |
}, | |
mapping = { | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-n>'] = cmp.mapping.select_next_item(), | |
['<C-d>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping.complete(), | |
['<C-e>'] = cmp.mapping.close(), | |
['<CR>'] = cmp.mapping.confirm { | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}, | |
['<Tab>'] = function(fallback) | |
if vim.fn.pumvisible() == 1 then | |
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-n>', true, true, true), 'n') | |
elseif luasnip.expand_or_jumpable() then | |
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-expand-or-jump', true, true, true), '') | |
else | |
fallback() | |
end | |
end, | |
['<S-Tab>'] = function(fallback) | |
if vim.fn.pumvisible() == 1 then | |
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<C-p>', true, true, true), 'n') | |
elseif luasnip.jumpable(-1) then | |
vim.fn.feedkeys(vim.api.nvim_replace_termcodes('<Plug>luasnip-jump-prev', true, true, true), '') | |
else | |
fallback() | |
end | |
end, | |
}, | |
sources = { | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
}, | |
} | |
local nvim_lsp = require('lspconfig') | |
-- Use an on_attach function to only map the following keys | |
-- after the language server attaches to the current buffer | |
local on_attach = function(client, bufnr) | |
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | |
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | |
-- Enable completion triggered by <c-x><c-o> | |
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | |
-- Mappings. | |
local opts = { noremap=true, silent=true } | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | |
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | |
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | |
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | |
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | |
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | |
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | |
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | |
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | |
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | |
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
end | |
-- Use a loop to conveniently call 'setup' on multiple servers and | |
-- map buffer local keybindings when the language server attaches | |
local servers = { 'pyright' } | |
for _, lsp in ipairs(servers) do | |
nvim_lsp[lsp].setup { | |
on_attach = on_attach, | |
flags = { | |
debounce_text_changes = 150, | |
} | |
} | |
end | |
EOF | |
" Delete buffer while keeping window layout (don't close buffer's windows). | |
" Version 2008-11-18 from http://vim.wikia.com/wiki/VimTip165 | |
if v:version < 700 || exists('loaded_bclose') || &cp | |
finish | |
endif | |
let loaded_bclose = 1 | |
if !exists('bclose_multiple') | |
let bclose_multiple = 1 | |
endif | |
" Display an error message. | |
function! s:Warn(msg) | |
echohl ErrorMsg | |
echomsg a:msg | |
echohl NONE | |
endfunction | |
" Command ':Bclose' executes ':bd' to delete buffer in current window. | |
" The window will show the alternate buffer (Ctrl-^) if it exists, | |
" or the previous buffer (:bp), or a blank buffer if no previous. | |
" Command ':Bclose!' is the same, but executes ':bd!' (discard changes). | |
" An optional argument can specify which buffer to close (name or number). | |
function! s:Bclose(bang, buffer) | |
if empty(a:buffer) | |
let btarget = bufnr('%') | |
elseif a:buffer =~ '^\d\+$' | |
let btarget = bufnr(str2nr(a:buffer)) | |
else | |
let btarget = bufnr(a:buffer) | |
endif | |
if btarget < 0 | |
call s:Warn('No matching buffer for '.a:buffer) | |
return | |
endif | |
if empty(a:bang) && getbufvar(btarget, '&modified') | |
call s:Warn('No write since last change for buffer '.btarget.' (use :Bclose!)') | |
return | |
endif | |
" Numbers of windows that view target buffer which we will delete. | |
let wnums = filter(range(1, winnr('$')), 'winbufnr(v:val) == btarget') | |
if !g:bclose_multiple && len(wnums) > 1 | |
call s:Warn('Buffer is in multiple windows (use ":let bclose_multiple=1")') | |
return | |
endif | |
let wcurrent = winnr() | |
for w in wnums | |
execute w.'wincmd w' | |
let prevbuf = bufnr('#') | |
if prevbuf > 0 && buflisted(prevbuf) && prevbuf != btarget | |
buffer # | |
else | |
bprevious | |
endif | |
if btarget == bufnr('%') | |
" Numbers of listed buffers which are not the target to be deleted. | |
let blisted = filter(range(1, bufnr('$')), 'buflisted(v:val) && v:val != btarget') | |
" Listed, not target, and not displayed. | |
let bhidden = filter(copy(blisted), 'bufwinnr(v:val) < 0') | |
" Take the first buffer, if any (could be more intelligent). | |
let bjump = (bhidden + blisted + [-1])[0] | |
if bjump > 0 | |
execute 'buffer '.bjump | |
else | |
execute 'enew'.a:bang | |
endif | |
endif | |
endfor | |
execute 'bdelete'.a:bang.' '.btarget | |
execute wcurrent.'wincmd w' | |
endfunction | |
command! -bang -complete=buffer -nargs=? Bclose call <SID>Bclose(<q-bang>, <q-args>) | |
nnoremap <silent> <Leader>bd :Bclose<CR> | |
map gn :bn<cr> | |
map gp :bp<cr> | |
map gw :Bclose<cr> | |
set relativenumber | |
set rnu | |
let g:transparent_enabled = v:true | |
tnoremap <Esc> <C-\><C-n> | |
" Telescope bindings | |
nnoremap ,f <cmd>Telescope find_files<cr> | |
nnoremap ,g <cmd>Telescope live_grep<cr> | |
lua << EOF | |
require("auto-save").setup { | |
enabled = true, -- start auto-save when the plugin is loaded (i.e. when your package manager loads it) | |
execution_message = { | |
message = function() -- message to print on save | |
return ("AutoSave: saved at " .. vim.fn.strftime("%H:%M:%S")) | |
end, | |
dim = 0.18, -- dim the color of `message` | |
cleaning_interval = 1250, -- (milliseconds) automatically clean MsgArea after displaying `message`. See :h MsgArea | |
}, | |
trigger_events = {"InsertLeave", "TextChanged"}, -- vim events that trigger auto-save. See :h events | |
-- function that determines whether to save the current buffer or not | |
-- return true: if buffer is ok to be saved | |
-- return false: if it's not ok to be saved | |
condition = function(buf) | |
local fn = vim.fn | |
local utils = require("auto-save.utils.data") | |
if | |
fn.getbufvar(buf, "&modifiable") == 1 and | |
utils.not_in(fn.getbufvar(buf, "&filetype"), {}) then | |
return true -- met condition(s), can save | |
end | |
return false -- can't save | |
end, | |
write_all_buffers = false, -- write all buffers when the current one meets `condition` | |
debounce_delay = 135, -- saves the file at most every `debounce_delay` milliseconds | |
callbacks = { -- functions to be executed at different intervals | |
enabling = nil, -- ran when enabling auto-save | |
disabling = nil, -- ran when disabling auto-save | |
before_asserting_save = nil, -- ran before checking `condition` | |
before_saving = nil, -- ran before doing the actual save | |
after_saving = nil -- ran after doing the actual save | |
} | |
} | |
EOF | |
" Telescope fzf plugin | |
lua << EOF | |
require('telescope').load_extension('fzf') | |
EOF | |
" White colors for LSP messages in code | |
hi DiagnosticError guifg=White | |
hi DiagnosticWarn guifg=White | |
hi DiagnosticInfo guifg=White | |
hi DiagnosticHint guifg=White | |
set colorcolumn=120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment