diff --git a/Dockerfile b/Dockerfile index 59defe2..592d11d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,28 +6,9 @@ RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen ENV LANG=en_US.UTF-8 ENV LANGUAGE=en_US:en ENV LC_ALL=en_US.UTF-8 +WORKDIR /opt/app +COPY init.vim . +RUN mkdir -p ~/.config/nvim && mv ./init.vim ~/.config/nvim RUN sh -c 'curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' -RUN mkdir -p ~/.config/nvim \ - && echo "call plug#begin()" >>~/.config/nvim/vimrc.vim \ - && echo "Plug 'nvim-treesitter/nvim-treesitter'" >>~/.config/nvim/vimrc.vim \ - && echo "Plug 'nvim-tree/nvim-web-devicons'" >>~/.config/nvim/vimrc.vim \ - && echo "Plug 'nvim-tree/nvim-tree.lua'" >>~/.config/nvim/vimrc.vim \ - && echo "Plug 'Mofiqul/dracula.nvim'" >>~/.config/nvim/vimrc.vim \ - && echo "Plug 'nvim-lualine/lualine.nvim'" >>~/.config/nvim/vimrc.vim \ - && echo "Plug 'akinsho/bufferline.nvim', { 'tag': '*' }" >>~/.config/nvim/vimrc.vim \ - && echo "call plug#end()" >>~/.config/nvim/vimrc.vim \ - && echo "vim.cmd.source(vim.fn.stdpath('config') .. '/vimrc.vim')" >>~/.config/nvim/init.lua \ - && : RUN nvim -c "PlugInstall" -c "qall" \ && nvim -c "TSUpdate" -c "qall" -RUN echo "vim.g.loaded_netrwPlugin = 1" >>~/.config/nvim/init.lua \ - && echo "vim.g.loaded_netrw = 1" >>~/.config/nvim/init.lua \ - && echo "require('nvim-tree').setup()" >>~/.config/nvim/init.lua \ - && echo "require('lualine').setup({options = {theme = 'dracula-nvim'}, extensions = {'nvim-tree'}})" >>~/.config/nvim/init.lua \ - && echo "require('bufferline').setup({options = {numbers = function(opts) return string.format('%s', opts.raise(opts.id)) end}})" >>~/.config/nvim/init.lua \ - && echo "require('nvim-treesitter').setup {" >>~/.config/nvim/init.lua \ - && echo " install_dir = vim.fn.stdpath('data') .. '/site'" >>~/.config/nvim/init.lua \ - && echo "}" >>~/.config/nvim/init.lua \ - && echo "vim.cmd([[colorscheme dracula]])" >>~/.config/nvim/init.lua \ - && echo "vim.cmd([[set termguicolors]])" >>~/.config/nvim/init.lua -WORKDIR /opt/app diff --git a/README.md b/README.md index 9d6c809..d2d0268 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## build docker image - docker build -t nvim . + docker build -t nvim . ## start a docker container - docker run --rm -it -v $PWD:/opt/app nvim:latest + docker run --rm -it -v $PWD:/opt/app nvim:latest nvim diff --git a/init.vim b/init.vim new file mode 100644 index 0000000..9590938 --- /dev/null +++ b/init.vim @@ -0,0 +1,463 @@ +" 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" + +" 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', 'branch': 'master'} + +"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: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')) + + 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 = { + [''] = false, + [''] = 'select_horizontal' + }, + n = { + [''] = false, + [''] = 'select_horizontal' + } + } + }, + pickers = { + buffers = { + mappings = { + i = { + [''] = require('telescope.actions').delete_buffer + }, + n = { + [''] = 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 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