From f371d214c1e07373ef27a46793f6dcc0da704671 Mon Sep 17 00:00:00 2001 From: z3rOR0ne Date: Sat, 23 Apr 2022 06:03:55 -0700 Subject: [PATCH] preparing to convert over to lua for nvim --- nvim/init.lua | 3 + nvim/lua/config.lua | 153 ++++++++++++++++++ nvim/lua/keybindings.lua | 26 +++ nvim/lua/packages.lua | 23 +++ ...it.lua => vim_to_lua_conversion_notes.lua} | 13 +- 5 files changed, 215 insertions(+), 3 deletions(-) create mode 100644 nvim/init.lua create mode 100644 nvim/lua/config.lua create mode 100644 nvim/lua/keybindings.lua create mode 100644 nvim/lua/packages.lua rename nvim/{test_init.lua => vim_to_lua_conversion_notes.lua} (93%) diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 00000000..b35a6db9 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,3 @@ +require('packages') +require('config') +require('keybindings') diff --git a/nvim/lua/config.lua b/nvim/lua/config.lua new file mode 100644 index 00000000..4d0c6d2d --- /dev/null +++ b/nvim/lua/config.lua @@ -0,0 +1,153 @@ +-- main init.lua configurations + +keymap = vim.api.nvim_set_keymap + +-- Nvim_Tree configuration: +-- -- setup with all defaults +-- each of these are documented in `:help nvim-tree.OPTION_NAME` +require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS + auto_reload_on_write = true, + disable_netrw = false, + hide_root_folder = false, + hijack_cursor = false, + hijack_netrw = true, + hijack_unnamed_buffer_when_opening = false, + ignore_buffer_on_setup = false, + open_on_setup = true, + open_on_setup_file = true, + open_on_tab = false, + sort_by = "name", + update_cwd = false, + view = { + width = 25, + height = 30, + side = "right", + preserve_window_proportions = true, + number = false, + relativenumber = false, + signcolumn = "yes", + mappings = { + custom_only = false, + list = { + -- user mappings go here + }, + }, + }, + renderer = { + indent_markers = { + enable = false, + icons = { + corner = "└ ", + edge = "│ ", + none = " ", + }, + }, + icons = { + webdev_colors = true, + }, + }, + hijack_directories = { + enable = true, + auto_open = true, + }, + update_focused_file = { + enable = false, + update_cwd = false, + ignore_list = {}, + }, + ignore_ft_on_setup = {}, + system_open = { + cmd = nil, + args = {}, + }, + diagnostics = { + enable = false, + show_on_dirs = false, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + filters = { + dotfiles = false, + custom = {}, + exclude = {}, + }, + git = { + enable = true, + ignore = true, + timeout = 400, + }, + actions = { + use_system_clipboard = true, + change_dir = { + enable = true, + global = false, + restrict_above_cwd = false, + }, + open_file = { + quit_on_open = false, + resize_window = false, + window_picker = { + enable = true, + chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", + exclude = { + filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" }, + buftype = { "nofile", "terminal", "help" }, + }, + }, + }, + }, + trash = { + cmd = "trash", + require_confirm = true, + }, + log = { + enable = false, + truncate = false, + types = { + all = false, + config = false, + copy_paste = false, + diagnostics = false, + git = false, + profile = false, + }, + }, +} -- END_DEFAULT_OPTS for Nvim_Tree + + -- Automatically closes Nvim tree if last window open +vim.cmd[[autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif]] + +-- vim-smoothie configuration +-- Use experimental features of vim-smoothie (gg and G) +vim.g.smoothie_experimental_mappings = 1 + +-- set colored brackets via rainbow +vim.g.rainbow_active = 1 + +-- Marks end of line, space, and trailing space characters +vim.opt.listchars:append({ eol = '↵', trail = '·', space = '·' }) +vim.opt.list = true + +-- enable AutoSave on start +vim.g.auto_save = 1 + +-- silence AutoSave messages +vim.g.auto_save_silent = 1 + +-- Create Default Mappings for NerdCommenter +vim.g.NERDCreateDefaultMappings= 1 + +-- Add spaces after NerdCommenter delimiters by default +vim.g.NERDSpaceDelims= 1 + +-- this variable must be enabled for colors to be applied properly +vim.g.termguicolors = true +vim.g.nosplitright = true + +-- do not close the markdown preview tab when switching to other buffers +vim.g.mkdp_auto_close = 0 + diff --git a/nvim/lua/keybindings.lua b/nvim/lua/keybindings.lua new file mode 100644 index 00000000..457da397 --- /dev/null +++ b/nvim/lua/keybindings.lua @@ -0,0 +1,26 @@ +-- remap Nvim_Tree toggle to CTRL+B +keymap('n', '', ':NvimTreeToggle', {}) + +-- Tab Shortcuts +keymap('n', '', ':tabnew', {}) +keymap('n', '', ':tabprevious', {}) +keymap('n', '', ':tabnext', {}) + +-- Use ctrl- [hl] to select the active split! +keymap('n', '', ':wincmd h', {}) +keymap('n', '', ':wincmd l', {}) + +-- Toggle NERDCommenter with Ctrl + c +vim.cmd[[:map NERDCommenterToggle]] + +-- redraws the screen and removes any search highlighting +keymap('n', '', ':nohl', {silent = true}) + +-- Can't quite get working yet +-- keybind map Ctrl + m to :MarkdownPreview +-- vim.cmd[[nnoremap M MarkdownPreviewToggle]] +-- keymap('n', '', ':MarkdownPreviewToggle', {noremap = true}) +-- +-- Toggle Multi-Cursor with j or k +vim.cmd[[nmap ]] +vim.cmd[[nmap ]] diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua new file mode 100644 index 00000000..4ebd5eec --- /dev/null +++ b/nvim/lua/packages.lua @@ -0,0 +1,23 @@ +-- Packages installed using 'packer', install using :PackerSync + +require('packer').startup(function() + use 'wbthomason/packer.nvim' + use 'kyazdani42/nvim-web-devicons' -- for file icons + use 'kyazdani42/nvim-tree.lua' + use 'psliwka/vim-smoothie' + -- use 'mattn/emmet-vim' + -- use 'ap/vim-css-color' + -- use 'airblade/vim-gitgutter' + -- use 'ctrlpvim/ctrlp.vim' -- fuzzy find files + -- use 'junegunn/fzf'--{ 'do': { -> fzf#install() } } + use 'preservim/nerdcommenter' + -- use 'Yggdroot/indentLine' + -- use 'sheerun/vim-polyglot' + use 'mg979/vim-visual-multi'-- {'branch': 'master'} + use {'iamcco/markdown-preview.nvim', run = ':call mkdp#util#install'} -- {'do': { -> mkdp#util#install() }} + use 'luochen1990/rainbow' + -- use 'simeji/winresizer' + use '907th/vim-auto-save' + -- use 'itchyny/lightline.vim' + -- use 'jremmen/vim-ripgrep' +end) diff --git a/nvim/test_init.lua b/nvim/vim_to_lua_conversion_notes.lua similarity index 93% rename from nvim/test_init.lua rename to nvim/vim_to_lua_conversion_notes.lua index 2aa162fb..f58839e0 100644 --- a/nvim/test_init.lua +++ b/nvim/vim_to_lua_conversion_notes.lua @@ -14,7 +14,9 @@ -- vim.bo.expandtab = true -- vim.bo.shiftwidth = 2 -- vim.bo.softtabstop = 2 - +-- +-- vim.g.something is equivalent to let g:something= +-- -- keybindings .vim style: -- Ctrl-s to save @@ -33,8 +35,8 @@ -- Now Converted to keybindings .lua style: -- -- local keymap = vim.api.nvim_set_keymap --- kemap('n', '', ':w', {}) --- kemap('i', '', ':wa', {}) +-- keymap('n', '', ':w', {}) +-- keymap('i', '', ':wa', {}) -- local opts = { noremap = true } -- keymap('n', '', 'j', opts)' -- keymap('n', '', 'h', opts)' @@ -144,3 +146,8 @@ -- Note that at the require('lspconfig')[] is a placeholder where YOUR_LSP_SERVER is meant to be replaced with the server of your choice, the example in the video is: -- -- 'sumneko_lua' +-- +-- Other resources: +-- +-- https://vonheikemen.github.io/devlog/tools/configuring-neovim-using-lua/ +-- https://dev.to/arunanshub/making-a-proper-initlua-for-real-this-time-4k44