changeset 627:a2a5862a3bd3

convert more vimscript to lua
author zegervdv <zegervdv@me.com>
date Thu, 28 Jul 2022 22:25:29 +0200
parents f795168ece65
children 1e6287df57f5
files .chezmoitemplates/config.vim .chezmoitemplates/init.lua
diffstat 2 files changed, 50 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/.chezmoitemplates/config.vim	Tue Jul 26 22:33:25 2022 +0200
+++ b/.chezmoitemplates/config.vim	Thu Jul 28 22:25:29 2022 +0200
@@ -25,38 +25,21 @@
 
 " Mappings
 
-" Highlight VCS conflict markers
-match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
 
 
-" Search for selected text, forwards or backwards.
-vnoremap <silent> * :<C-U>
-  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
-  \gvy/<C-R><C-R>=substitute(
-  \escape(@", '/\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
-  \gV:call setreg('"', old_reg, old_regtype)<CR>
-vnoremap <silent> # :<C-U>
-  \let old_reg=getreg('"')<Bar>let old_regtype=getregtype('"')<CR>
-  \gvy?<C-R><C-R>=substitute(
-  \escape(@", '?\.*$^~['), '\_s\+', '\\_s\\+', 'g')<CR><CR>
-  \gV:call setreg('"', old_reg, old_regtype)<CR>
-
-xnoremap <silent> p p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR>
-
-
-if has('nvim')
-  tnoremap <C-h> <C-\><C-n><C-w>h
-  tnoremap <C-j> <C-\><C-n><C-w>j
-  tnoremap <C-k> <C-\><C-n><C-w>k
-  tnoremap <C-l> <C-\><C-n><C-w>l
-  augroup enter_term
-    au!
-    autocmd TermOpen * startinsert!
-    autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif
-    autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif
-  augroup END
-  let $GIT_EDITOR = 'nvr -cc split --remote-wait'
-endif
+" if has('nvim')
+"   tnoremap <C-h> <C-\><C-n><C-w>h
+"   tnoremap <C-j> <C-\><C-n><C-w>j
+"   tnoremap <C-k> <C-\><C-n><C-w>k
+"   tnoremap <C-l> <C-\><C-n><C-w>l
+"   augroup enter_term
+"     au!
+"     autocmd TermOpen * startinsert!
+"     autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif
+"     autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif
+"   augroup END
+"   let $GIT_EDITOR = 'nvr -cc split --remote-wait'
+" endif
 
 "
 
@@ -129,7 +112,7 @@
         return "\<CR>"
     endif
 endfunction
-cnoremap <expr> <CR> CCR()
+" cnoremap <expr> <CR> CCR()
 "
 
 " Filetype specific settings
--- a/.chezmoitemplates/init.lua	Tue Jul 26 22:33:25 2022 +0200
+++ b/.chezmoitemplates/init.lua	Thu Jul 28 22:25:29 2022 +0200
@@ -906,11 +906,28 @@
   desc = 'Search word under cursor without moving to first results',
 })
 
+map('x', 'p', [[ p:if v:register == '"'<Bar>let @@=@0<Bar>endif<CR> ]], { silent = true })
+
 map('n', '<UP>', ':cprev<CR>', { desc = 'Go to previous error/match' })
 map('n', '<DOWN>', ':cnext<CR>', { desc = 'Go to next error/match' })
 map('n', '<LEFT>', ':cpf<CR>', { desc = 'Go to previous error/match in previous file' })
 map('n', '<RIGHT>', ':cnf<CR>', { desc = 'Go to next error/match in next file' })
 
+map('t', '<C-h>', '<C-\\><C-n><C-w>h')
+map('t', '<C-j>', '<C-\\><C-n><C-w>j')
+map('t', '<C-k>', '<C-\\><C-n><C-w>k')
+map('t', '<C-l>', '<C-\\><C-n><C-w>l')
+
+map('c', '<CR>', function()
+  local cmdline = vim.fn.getcmdline()
+  print(cmdline)
+  if cmdline == 'ls' or cmdline == 'buffers' or cmdline == 'files' then return '<CR>:b' end
+  return '<CR>'
+end, { expr = true })
+
+-- Special highlighting
+vim.cmd.match { 'ErrorMsg', [[ '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' ]] }
+
 local au = require 'au'
 
 -- Highlight yanked text
@@ -946,6 +963,25 @@
   if vim.o.diff then vim.cmd.diffupdate() end
 end
 
+-- Terminal
+au.group('enter_term', {
+  { 'TermOpen', '*', 'startinsert!' },
+  {
+    'BufEnter',
+    '*',
+    function()
+      if vim.bo.buftype == 'terminal' then vim.cmd.startinsert { bang = true } end
+    end,
+  },
+  {
+    'BufLeave',
+    '*',
+    function()
+      if vim.bo.buftype == 'terminal' then vim.cmd.stopinsert { bang = true } end
+    end,
+  },
+})
+
 -- Snippets
 local ls = require 'luasnip'
 -- Expand snippet or jump to next placeholder