" 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 = "\[>4;2m" let &t_TE = "\[>4;m" lua << vim.pack.add({ 'https://github.com/nvim-tree/nvim-web-devicons', -- optional 'https://github.com/nvim-tree/nvim-tree.lua', 'https://github.com/nvim-treesitter/nvim-treesitter', 'https://github.com/Mofiqul/dracula.nvim', 'https://github.com/nvim-lualine/lualine.nvim', 'https://github.com/akinsho/bufferline.nvim', 'https://github.com/nvim-lua/plenary.nvim', 'https://github.com/nvim-telescope/telescope.nvim', -- For managing lsps 'https://github.com/williamboman/mason.nvim', -- Delete, change and add surrounding pairs 'https://github.com/kylechui/nvim-surround', -- Indent line 'https://github.com/lukas-reineke/indent-blankline.nvim', 'https://github.com/airblade/vim-gitgutter', -- Highlight syntax and support indent for MoonScript 'https://github.com/leafo/moonscript-vim', }, { confirm = false }) . colorscheme dracula set termguicolors " Open a terminal in the current file's directory command Cdot normal! :lcd%:h:terminalA " 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("") 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', '', change_directory, opts('Global CD')) 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 = { [''] = false, [''] = 'select_horizontal' }, n = { [''] = false, [''] = 'select_horizontal' } } }, pickers = { buffers = { mappings = { i = { [''] = require('telescope.actions').delete_buffer }, n = { [''] = require('telescope.actions').delete_buffer } } } } }) . lua << vim.lsp.config['lua_ls'] = { cmd = { 'lua-language-server' }, filetypes = { 'lua' }, root_markers = { '.luarc.json', '.git' }, settings = { Lua = { diagnostics = { globals = { "vim" } } } } } vim.lsp.enable('lua_ls') . 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 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', '', function() return vim.bo.ft == 'help' and 'bw' or '' 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 :w imap ':w' . (col('.') == 1 ? '' : 'l') " Copy vmap "+y " Copy from visual-multi selection and return to normal mode nmap "+y " call nvim_set_keymap('', '', '+p', {'noremap': v:true, 'silent': v:true}) " call nvim_set_keymap('!', '', '+', {'noremap': v:true, 'silent': v:true}) " call nvim_set_keymap('t', '', '+', {'noremap': v:true, 'silent': v:true}) " call nvim_set_keymap('v', '', '+', {'noremap': v:true, 'silent': v:true}) " Edit/source init.vim nnoremap ev :edit $MYVIMRC nnoremap sv :source $MYVIMRC nnoremap q :q nnoremap t :tabnew " Delete current buffer and view another open buffer in current window nnoremap bd :bn:bd # nnoremap w :set wrap!:set wrap? " Find files using Telescope command-line sugar. nnoremap ff Telescope find_files nnoremap fg Telescope live_grep nnoremap fb Telescope buffers nnoremap fh Telescope help_tags " Stop highlighting noremap :noh " Print current date map D :put =strftime('%A, %B %d, %Y %I:%M %p %Z') " Toggle file explorer noremap :lua require('nvim-tree.api').tree.toggle({focus = false}) inoremap :lua require('nvim-tree.api').tree.toggle({focus = false}) autocmd WinEnter * set nowrap autocmd WinEnter * set linebreak " Cycle buffers nnoremap :BufferLineCyclePrev nnoremap :BufferLineCycleNext inoremap :BufferLineCyclePrevi inoremap :BufferLineCycleNexti " Move buffers nnoremap :BufferLineMovePrev nnoremap :BufferLineMoveNext " Insert comment lua vim.keymap.set('i', '', 'gcc', { remap = true }) lua vim.keymap.set('n', '', 'gcc', { remap = true }) lua vim.keymap.set('v', '', 'gc', { remap = true }) " For Alacritty "lua vim.keymap.set('i', '', 'gcc', { remap = true }) "lua vim.keymap.set('n', '', 'gcc', { remap = true }) "lua vim.keymap.set('v', '', '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 :call LineHome():echo imap =LineHome() " 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 col('.') == indent(line('.')) + 1 ? "0" : "^" " Map to exit terminal-mode tnoremap " Simulate i_CTRL-R in terminal-mode tnoremap '"'.nr2char(getchar()).'pi' " Use `ALT+{Left,Down,Right,Up}` to navigate windows from any mode tnoremap h tnoremap j tnoremap k tnoremap l inoremap h inoremap j inoremap k inoremap l nnoremap h nnoremap j nnoremap k nnoremap l " Use `ALT+{h,j,k,l}` to navigate windows from any mode tnoremap h tnoremap j tnoremap k tnoremap l inoremap h inoremap j inoremap k inoremap l nnoremap h nnoremap j nnoremap k nnoremap l if $TERM == 'alacritty' " Undo map undo inoremap undo " Redo "map ز redo "inoremap ز redo map redo inoremap redo endif cnoremap wildmenumode() ? "\" : "\" cnoremap wildmenumode() ? "\" : "\" cnoremap wildmenumode() ? "\" : "\" cnoremap wildmenumode() ? "\" : "\" :tnoremap