aboutsummaryrefslogtreecommitdiff
path: root/Common/nvim/lua/helper_functions.lua
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2022-06-30 13:31:26 +0200
committerjakobst1n <jakob.stendahl@outlook.com>2022-06-30 13:33:05 +0200
commit64d19effcc7aa1db2f134130484aa68cddd6ecd6 (patch)
tree5ce1fe1484ecc209ad98371162105b8a34092c13 /Common/nvim/lua/helper_functions.lua
parent0447c58e759df165269ffe9182398881e650d923 (diff)
downloaddotfiles-64d19effcc7aa1db2f134130484aa68cddd6ecd6.tar.gz
dotfiles-64d19effcc7aa1db2f134130484aa68cddd6ecd6.zip
neovim
Diffstat (limited to 'Common/nvim/lua/helper_functions.lua')
-rw-r--r--Common/nvim/lua/helper_functions.lua72
1 files changed, 72 insertions, 0 deletions
diff --git a/Common/nvim/lua/helper_functions.lua b/Common/nvim/lua/helper_functions.lua
new file mode 100644
index 0000000..cac6c00
--- /dev/null
+++ b/Common/nvim/lua/helper_functions.lua
@@ -0,0 +1,72 @@
+-- opts that replicate the nore part of noremap
+silentnoremap = { noremap = true, silent = true }
+
+-- Just to make the map function "shorter"
+function map(kind, lhs, rhs, opts)
+ vim.api.nvim_set_keymap(kind, lhs, rhs, opts)
+end
+
+-- True if Paste Mode is enabled
+function HasPaste()
+ return vim.opt.paste:get() and 'PASTE MODE ' or ''
+end
+vim.api.nvim_create_user_command('HasPaste', HasPaste, {bang=true, desc='Returns a string with PASTE MODE if paste is on.'})
+
+-- Toggles wether special characters are visible
+list_chars_enabled = false
+list_chars_when_enabled = "tab:→ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»"
+function ToggleListChars()
+ list_chars_enabled = not list_chars_enabled
+ vim.opt.list = list_chars_enabled
+ vim.opt.listchars = list_chars_enabled and list_chars_when_enabled or 'eol:$'
+end
+
+-- Close buffer without closing window
+--[[
+vim.cmd [[
+ function! <SID>BufcloseCloseIt()
+ let l:currentBufNum = bufnr("%")
+ let l:alternateBufNum = bufnr("#")
+
+ if buflisted(l:alternateBufNum)
+ buffer #
+ else
+ bnext
+ endif
+
+ if bufnr("%") == l:currentBufNum
+ new
+ endif
+
+ if buflisted(l:currentBufNum)
+ execute("bdelete! ".l:currentBufNum)
+ endif
+ endfunction
+]]
+--]]
+
+vim.cmd [[
+ function! CmdLine(str)
+ exe "menu Foo.Bar :" . a:str
+ emenu Foo.Bar
+ unmenu Foo
+ endfunction
+
+
+ function! VisualSelection(direction, extra_filter) range
+ let l:saved_reg = @"
+ execute "normal! vgvy"
+
+ let l:pattern = escape(@", "\\/.*'$^~[]")
+ let l:pattern = substitute(l:pattern, "\n$", "", "")
+
+ if a:direction == 'gv'
+ call CmdLine("Ack '" . l:pattern . "' " )
+ elseif a:direction == 'replace'
+ call CmdLine("%s" . '/'. l:pattern . '/')
+ endif
+
+ let @/ = l:pattern
+ let @" = l:saved_reg
+ endfunction
+]]