Files
neovim/init.vim

464 lines
12 KiB
VimL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
" required for nvim-tree plugin
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
" https://vimhelp.org/map.txt.html#modifyOtherKeys
" I'm not sure that this really helps anything
let &t_TI = "\<Esc>[>4;2m"
let &t_TE = "\<Esc>[>4;m"
" Automatically install vim-plug plugin manager
" https://github.com/junegunn/vim-plug/wiki/tips#automatic-installation
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
Plug 'nvim-tree/nvim-web-devicons' " optional
Plug 'nvim-tree/nvim-tree.lua'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
"Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'Mofiqul/dracula.nvim'
Plug 'nvim-lualine/lualine.nvim'
Plug 'akinsho/bufferline.nvim', { 'tag': '*' }
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' }
" Installation manager for 'ripgrep' search tool
Plug 'iruzo/ripgrep.nvim'
" Not sure if this is useful?
" Plug 'rafcamlet/nvim-luapad'
" For managing lsps
Plug 'williamboman/mason.nvim'
Plug 'neovim/nvim-lspconfig'
" Delete, change and add surrounding pairs
Plug 'kylechui/nvim-surround'
" Indent line
Plug 'lukas-reineke/indent-blankline.nvim'
Plug 'airblade/vim-gitgutter'
" Highlight syntax and support indent for MoonScript
Plug 'leafo/moonscript-vim'
call plug#end()
colorscheme dracula
set termguicolors
" Open a terminal in the current file's directory
command Cdot normal! :lcd%:h<CR>:terminal<CR>A<CR>
" Very basic "autocompletion". See `h compl-autocomplete`
lua <<
local triggers = {"."}
vim.api.nvim_create_autocmd("InsertCharPre", {
-- buffer = vim.api.nvim_get_current_buf(),
pattern = {'*'},
callback = function()
if vim.fn.pumvisible() == 1 or vim.fn.state("m") == "m" then
return
end
local char = vim.v.char
if vim.list_contains(triggers, char) then
local key = vim.keycode("<C-x><C-n><C-p>")
vim.api.nvim_feedkeys(key, "m", false)
end
end
})
-- vim.api.nvim_create_autocmd("WinEnter", {
-- pattern = {'*'},
-- callback = function()
-- vim.print(vim.api.nvim_win_get_config(0))
-- -- vim.print("HELLO")
-- end
-- })
.
lua <<
local function nvim_tree_custom_mappings(bufnr)
local api = require('nvim-tree.api')
local function opts(desc)
return {
desc = "nvim-tree: " .. desc,
buffer = bufnr,
noremap = true,
silent = true,
nowait = true
}
end
local function change_directory()
local node = api.tree.get_node_under_cursor()
if node.name == '..' then
vim.cmd("cd " .. vim.fn.getcwd())
elseif node.nodes ~= nil then
vim.cmd("cd " .. node.absolute_path)
end
end
api.config.mappings.default_on_attach(bufnr)
vim.keymap.set('n', '<C-S-]>', change_directory, opts('Global CD'))
if vim.env.TERM == 'alacritty' then
-- Arabic 'aleph', unicode: "\u0627"
-- vim.keymap.set('n', 'ا', change_directory, opts('Global CD'))
end
end
require('nvim-tree').setup({
on_attach = nvim_tree_custom_mappings,
tab = {sync = {open = true}},
sync_root_with_cwd = true,
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_root = false
},
live_filter = {
always_show_folders = false
}
})
.
lua <<
vim.g.VM_set_statusline = 0
vim.g.VM_silent_exit = 1
local function vm_mode()
return vim.iter(string.gmatch(vim.fn['vm#themes#statusline'](), "%S+")):nth(2)
end
local function vm_status()
return vim.fn['VMInfos']().status or ''
end
require('lualine').setup({
options = {
theme = 'dracula-nvim',
},
-- sections = {
-- lualine_a = {{'mode', fmt = function(mode) return vm_mode() or mode end}},
-- lualine_b = {vm_status, 'branch', 'diff', 'diagnostics'},
-- },
extensions = {
'nvim-tree'
},
})
vim.api.nvim_create_autocmd({'CmdlineEnter'}, {
pattern = {'@'},
callback = function(ev)
if vim.b.visual_multi then
local delay = 0
vim.defer_fn(function() vim.cmd('execute "redrawstatus"') end, delay)
end
end
})
.
lua require('bufferline').setup({options = {numbers = function(opts) return string.format('%s', opts.raise(opts.id)) end}})
lua <<
require('telescope').setup({
defaults = {
mappings = {
i = {
['<C-x>'] = false,
['<C-s>'] = 'select_horizontal'
},
n = {
['<C-x>'] = false,
['<C-s>'] = 'select_horizontal'
}
}
},
pickers = {
buffers = {
mappings = {
i = {
['<C-d>'] = require('telescope.actions').delete_buffer
},
n = {
['<C-d>'] = require('telescope.actions').delete_buffer
}
}
}
}
})
.
lua <<
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
if not configs.lua_ls then
configs.lua_ls = {
default_config = {
cmd = {vim.fn.expand('~/.local/bin/lua-language-server')},
filetypes = {'lua'},
single_file_support = true,
autostart = true,
}
}
end
lspconfig.lua_ls.setup({
settings = {
Lua = {
diagnostics = {
globals = { "love" },
}
}
}
})
lspconfig.cssls.setup({})
.
lua <<
-- require('lspconfig').lua_ls.setup({
-- settings = {
-- Lua = {
-- runtime = {
-- version = "LuaJIT"
-- }
-- }
-- }
-- })
.
lua require("mason").setup()
lua require('nvim-surround').setup()
lua <<
local hooks = require('ibl.hooks')
hooks.register(hooks.type.HIGHLIGHT_SETUP, function()
vim.api.nvim_set_hl(0, "IblScope", {fg = '#454545'})
end)
require('ibl').setup({scope = {char = "▎"}, indent = {char ="▏"}}) -- ▏▎┊▍▎┋┃⦚
.
" lua require("helpers")
"https://github.com/editorconfig/editorconfig-vim/blob/8b7da79e9daee7a3f3a8d4fe29886b9756305aff/plugin/editorconfig.vim#L594-L605
function! s:TrimTrailingWhitespace()
" Called from within a buffer-specific autocmd, so we can use '%'
if getbufvar('%', '&modifiable') && &ft != 'markdown'
" don't lose user position when trimming trailing whitespace
let s:view = winsaveview()
try
silent! keeppatterns keepjumps %s/\s\+$//e
finally
call winrestview(s:view)
endtry
endif
endfunction
autocmd BufWritePre * call s:TrimTrailingWhitespace()
function! LineHome()
let x = col('.')
execute "normal ^"
if x == col('.')
execute "normal 0"
endif
return ""
endfunction
" Use :emenu <Tab> to see menu list from command prompt
source $VIMRUNTIME/menu.vim
"set guifont=IosevkaTerm\ Nerd\ Font\ Mono:h12
set guifont=NotoSansM\ Nerd\ Font\ Mono:h12
set number
set title
set expandtab
set shiftwidth=2
set softtabstop=2
set noautoindent
set nosmartindent
set nocindent
set foldmethod=expr
"set foldexpr=nvim_treesitter#foldexpr()
set foldexpr=v:lua.vim.treesitter.foldexpr()
set foldlevelstart=99
" yank, delete, and change operations copy into both + and *, put operations paste from +
"set clipboard=unnamed,unnamedplus
" Highlights item mouse hovers over in popup menu
set mousemoveevent
" Number of screen lines to use for the command-line
set cmdheight=2
" Highlight column after 'textwidth'
set colorcolumn=+1
autocmd WinEnter * set colorcolumn=+1
autocmd BufEnter * if &textwidth == 0 | set textwidth=79 | endif
set selectmode=key
set keymodel=startsel
set conceallevel=0
let g:neovide_text_gamma = 0.8
let g:neovide_text_contrast = 0.1
" F1 to close help window if current buffer is a help window
lua <<
vim.keymap.set('n', '<F1>', function()
return vim.bo.ft == 'help' and '<Cmd>bw<CR>' or '<Help>'
end, {expr = true, remap = false})
.
"NvimTreeOpen
" Move cursor to previous window after opening NvimTree
wincmd p
" Move cursor from NvimTree to empty buffer on start
autocmd VimEnter * wincmd 2w
" Save
nmap <C-s> :w<CR>
imap <expr> <C-s> '<ESC>:w<CR>' . (col('.') == 1 ? '' : 'l')
" Copy
vmap <C-S-C> "+y
" Copy from visual-multi selection and return to normal mode
nmap <C-S-C> "+y<ESC>
" call nvim_set_keymap('', '<C-v>', '+p<CR>', {'noremap': v:true, 'silent': v:true})
" call nvim_set_keymap('!', '<C-v>', '<C-R>+', {'noremap': v:true, 'silent': v:true})
" call nvim_set_keymap('t', '<C-v>', '<C-R>+', {'noremap': v:true, 'silent': v:true})
" call nvim_set_keymap('v', '<C-v>', '<C-R>+', {'noremap': v:true, 'silent': v:true})
" Edit/source init.vim
nnoremap <Leader>ev :edit $MYVIMRC<CR>
nnoremap <Leader>sv :source $MYVIMRC<CR>
nnoremap <Leader>q :q<CR>
nnoremap <Leader>t :tabnew<CR>
" Delete current buffer and view another open buffer in current window
nnoremap <silent> <Leader>bd :bn<Bar>:bd #<CR>
nnoremap <silent> <Leader>w :set wrap!<CR>:set wrap?<CR>
" Find files using Telescope command-line sugar.
nnoremap <Leader>ff <Cmd>Telescope find_files<CR>
nnoremap <Leader>fg <Cmd>Telescope live_grep<CR>
nnoremap <Leader>fb <Cmd>Telescope buffers<CR>
nnoremap <Leader>fh <Cmd>Telescope help_tags<CR>
" Stop highlighting
noremap <Leader><ESC> :noh<CR>
" Print current date
map <leader>D :put =strftime('%A, %B %d, %Y %I:%M %p %Z')<CR>
" Toggle file explorer
noremap <silent> <C-S-E> :lua require('nvim-tree.api').tree.toggle({focus = false})<CR>
inoremap <silent> <C-S-E> <C-o>:lua require('nvim-tree.api').tree.toggle({focus = false})<CR>
autocmd WinEnter * set nowrap
autocmd WinEnter * set linebreak
" Cycle buffers
nnoremap <silent> <S-PageUp> :BufferLineCyclePrev<CR>
nnoremap <silent> <S-PageDown> :BufferLineCycleNext<CR>
inoremap <silent> <S-PageUp> <ESC>:BufferLineCyclePrev<CR>i
inoremap <silent> <S-PageDown> <ESC>:BufferLineCycleNext<CR>i
" Move buffers
nnoremap <C-S-PageUp> :BufferLineMovePrev<CR>
nnoremap <C-S-PageDown> :BufferLineMoveNext<CR>
" Insert comment
lua vim.keymap.set('i', '<C-/>', '<ESC>gcc', { remap = true })
lua vim.keymap.set('n', '<C-/>', 'gcc', { remap = true })
lua vim.keymap.set('v', '<C-/>', 'gc', { remap = true })
" For Alacritty
"lua vim.keymap.set('i', '<C-_>', '<ESC>gcc', { remap = true })
"lua vim.keymap.set('n', '<C-_>', 'gcc', { remap = true })
"lua vim.keymap.set('v', '<C-_>', 'gc', { remap = true })
" Jump to first non-whitespace on line, or jump to begining of line if already at first non-whitespace
" https://superuser.com/questions/301109/move-cursor-to-beginning-of-non-whitespace-characters-in-a-line-in-vim/426147#426147
"map <silent><Home> :call LineHome()<CR>:echo<CR>
imap <silent><Home> <C-R>=LineHome()<CR>
" This next line is my own solution. Doesn't clear selection when used in visual mode.
" Reference: https://vi.stackexchange.com/questions/3296/count-the-number-of-whitespace-in-the-beginning-of-a-line
map <expr> <Home> col('.') == indent(line('.')) + 1 ? "0" : "^"
" Map <Esc> to exit terminal-mode
tnoremap <Esc> <C-\><C-n>
" Simulate i_CTRL-R in terminal-mode
tnoremap <expr> <C-R> '<C-\><C-N>"'.nr2char(getchar()).'pi'
" Use `ALT+{Left,Down,Right,Up}` to navigate windows from any mode
tnoremap <A-Left> <C-\><C-N><C-w>h
tnoremap <A-Down> <C-\><C-N><C-w>j
tnoremap <A-Up> <C-\><C-N><C-w>k
tnoremap <A-Right> <C-\><C-N><C-w>l
inoremap <A-Left> <C-\><C-N><C-w>h
inoremap <A-Down> <C-\><C-N><C-w>j
inoremap <A-Up> <C-\><C-N><C-w>k
inoremap <A-Right> <C-\><C-N><C-w>l
nnoremap <A-Left> <C-w>h
nnoremap <A-Down> <C-w>j
nnoremap <A-Up> <C-w>k
nnoremap <A-Right> <C-w>l
" Use `ALT+{h,j,k,l}` to navigate windows from any mode
tnoremap <A-h> <C-\><C-N><C-w>h
tnoremap <A-j> <C-\><C-N><C-w>j
tnoremap <A-k> <C-\><C-N><C-w>k
tnoremap <A-l> <C-\><C-N><C-w>l
inoremap <A-h> <C-\><C-N><C-w>h
inoremap <A-j> <C-\><C-N><C-w>j
inoremap <A-k> <C-\><C-N><C-w>k
inoremap <A-l> <C-\><C-N><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
if $TERM == 'alacritty'
" Undo
map <C-z> <Cmd>undo<CR>
inoremap <C-z> <Cmd>undo<CR>
" Redo
"map ز <Cmd>redo<CR>
"inoremap ز <Cmd>redo<CR>
map <C-S-Z> <Cmd>redo<CR>
inoremap <C-S-Z> <Cmd>redo<CR>
endif
cnoremap <expr> <Right> wildmenumode() ? "\<Down>" : "\<Right>"
cnoremap <expr> <Left> wildmenumode() ? "\<Up>" : "\<Left>"
cnoremap <expr> <Up> wildmenumode() ? "\<Left>" : "\<Up>"
cnoremap <expr> <Down> wildmenumode() ? "\<Right>" : "\<Down>"
:tnoremap <Esc> <C-\><C-n>