From 9a17fc3c26a351cd5bdd20351b9ab3ff0ca2e4cb Mon Sep 17 00:00:00 2001 From: Cody Hiar Date: Tue, 7 Sep 2021 19:41:44 -0600 Subject: minor tweaks --- init.lua | 73 +++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/init.lua b/init.lua index b8992af..f068e9d 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,20 @@ --[[ -How to install +To install everything run `:PackerSync` -1. Run `PackerSync` -2. Run TSInstall for treesitter grammar -3. LspInfo to check if the language servers are working +LspInfo to check if the language servers are working +]]-- -Todo -https://dev.to/voyeg3r/writing-useful-lua-functions-to-my-neovim-14ki -function to remove whitespace and preserve spot on save -]]-- +-- https://dev.to/voyeg3r/writing-useful-lua-functions-to-my-neovim-14ki +-- function to remove whitespace and preserve spot on save +function _G.preserve(cmd) + cmd = string.format('keepjumps keeppatterns execute %q', cmd) + local original_cursor = vim.fn.winsaveview() + vim.api.nvim_command(cmd) + vim.fn.winrestview(original_cursor) +end +vim.cmd([[autocmd BufWritePre,FileWritePre,FileAppendPre,FilterWritePre * :lua preserve('%s/\\s\\+$//ge')]]) + -- Bootstrap packer if not installed local fn = vim.fn @@ -21,16 +26,12 @@ end -local o = vim.o -local g = vim.g -local cmd = vim.cmd -local map = vim.api.nvim_set_keymap - - --- https://old.reddit.com/r/neovim/comments/lrz18i/how_to_change_colorscheme_in_lua_without_any/ -g.colors_name = "nord" -g.SuperTabDefaultCompletionType = "" +-- https://old.reddit.com/r/neovim/comments/lrz18i/how_to_change_colorscheme_in_lua_without_any/ +vim.g.colors_name = "nord" +vim.g.SuperTabDefaultCompletionType = "" +-- Shortcut the map function +local map = vim.api.nvim_set_keymap -- Set up spacebar as leader -- https://icyphox.sh/blog/nvim-lua/ @@ -38,18 +39,18 @@ map('n', '', '', {}) vim.g.mapleader = ' ' -- Set spaces > tabs, 4 as default -o.expandtab = true -o.tabstop = 4 -o.shiftwidth = 0 -o.relativenumber = true +vim.o.expandtab = true +vim.o.tabstop = 4 +vim.o.shiftwidth = 0 +vim.o.relativenumber = true -o.wrap = false -o.history = 1000 +vim.o.wrap = false +vim.o.history = 1000 -- Wildmode show list, complete to first result -o.wildignore = "*/app/cache,*/vendor,*/env,*.pyc,*/venv,*/__pycache__,*/venv" -o.splitright = true -o.splitbelow = true -o.spelllang = "en_ca" +vim.o.wildignore = "*/app/cache,*/vendor,*/env,*.pyc,*/venv,*/__pycache__,*/venv" +vim.o.splitright = true +vim.o.splitbelow = true +vim.o.spelllang = "en_ca" local highlights = { @@ -68,12 +69,12 @@ local highlights = { "IndentBlanklineIndent2 ctermbg=235 ctermfg=NONE", } for i, highlight in ipairs(highlights) do - cmd('au VimEnter * hi ' .. highlight) + vim.cmd('au VimEnter * hi ' .. highlight) end -- Along with the highlight definition for ColorColumn above, these options -- will set colored marks at certain line lengths -cmd [[ +vim.cmd [[ au BufEnter *.py let w:m1=matchadd('ColorColumn', '\%81v', 100) au BufEnter *.py let w:m2=matchadd('Error', '\%121v', 100) au BufLeave *.py call clearmatches() @@ -81,13 +82,15 @@ au BufLeave *.py call clearmatches() -- Custom commands -cmd [[ +vim.cmd [[ command! MakeTagsPython !ctags --exclude=venv --languages=python --python-kinds=-i -R . ]] options = { noremap = true } + + map('n', '', ':noh', options) map('i', 'jj', '', options) @@ -95,8 +98,8 @@ map('i', 'jj', '', options) map('n', 'gp', "`[v`]", options) map('n', 'ps', 'PackerSync', options) map('n', 'ff', 'Telescope find_files', options) -map('n', 'fb', 'Telescope buffers', options) -map('n', 'fj', 'Telescope jumplist', options) +map('n', 'fb', 'Telescope buffers', options) +map('n', 'fj', 'Telescope jumplist', options) map('n', 'f/', 'Telescope live_grep', options) map('n', 'fa', 'Telescope grep_string', options) map('n', 'fg', "lua require('telescope.builtin').git_status()", options) @@ -192,7 +195,7 @@ local stl = { '%{&filetype}', } -o.statusline = table.concat(stl) +vim.o.statusline = table.concat(stl) return require('packer').startup(function() @@ -216,7 +219,7 @@ return require('packer').startup(function() enable = true, }, indent = { - enable = true, + enable = true, }, rainbow = { enable = true, @@ -296,7 +299,7 @@ return require('packer').startup(function() 'nvim-telescope/telescope.nvim', requires = { {'nvim-lua/plenary.nvim'}, - {'glepnir/lspsaga.nvim'}, + {'glepnir/lspsaga.nvim'}, {'nvim-telescope/telescope-fzf-native.nvim', run = 'make' }, }, config = function() -- cgit v1.2.3