Skip to content

Commit

Permalink
move stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed Dec 10, 2023
1 parent 65b4bfd commit dae4489
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 51 deletions.
48 changes: 47 additions & 1 deletion .config/nvim/lua/user/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ inoremap(';', ';<c-g>u')
inoremap(';;', '<C-O>A;')

-- Search for string within the visual selection
vim.keymap.set('x', '/', '<Esc>/\\%V')
xnoremap('/', '<Esc>/\\%V')

-- Copy number of lines and paste below
function _G.__duplicate_lines(motion)
Expand Down Expand Up @@ -205,6 +205,12 @@ vnoremap('#', ":call StarSearch('?')<CR>?<C-R>=@/<CR><CR>", true)
nnoremap('-', [["ldd$"lp]])
nnoremap('_', [["ldd2k"lp]])

-- Allow clipboard copy paste in neovim
vim.keymap.set('', '<D-v>', '+p<CR>', opts.no_remap_silent)
vim.keymap.set('!', '<D-v>', '<C-R>+', opts.no_remap_silent)
tnoremap('<D-v>', '<C-R>+', true)
vnoremap('<D-v>', '<C-R>+', true)

-- Copy entire file to clipboard
nnoremap('Y', ':%y+<cr>', true)

Expand Down Expand Up @@ -283,6 +289,13 @@ nnoremap('<leader>bd', '<cmd>BDelete this<cr>', true)
-- Close current buffer
nnoremap('<leader>bc', ':close<cr>', true)

-- Abbreviations
vim.keymap.set('!a', 'dont', [[don't]], opts.no_remap)
vim.keymap.set('!a', 'seperate', [[separate]], opts.no_remap)
vim.keymap.set('!a', 'rbm', [[# TODO: remove before merging]], opts.no_remap)
vim.keymap.set('!a', 'cbm', [[# TODO: change before merging]], opts.no_remap)
vim.keymap.set('!a', 'ubm', [[# TODO: uncomment before merging]], opts.no_remap)

-----------------
-- Yaml / Json --
-----------------
Expand Down Expand Up @@ -433,6 +446,39 @@ vim.keymap.set({ 'n', 'v' }, '<C-f>', function()
return vim.fn.mode() == 'v' and ':RipGrepCWORDVisual!<cr>' or ':RipGrepCWORD!<Space>'
end, opts.no_remap_expr)

------------------------
-- Run current buffer --
------------------------
vim.cmd [[
" Will attempt to execute the current file based on the `&filetype`
" You need to manually map the filetypes you use most commonly to the
" correct shell command.
function! ExecuteFile()
let l:filetype_to_command = {
\ 'javascript': 'node',
\ 'python': 'python3',
\ 'html': 'open',
\ 'sh': 'bash'
\ }
call inputsave()
let sure = input('Are you sure you want to run the current file? (y/n): ')
call inputrestore()
if sure !=# 'y'
return ''
endif
echo ''
let l:cmd = get(l:filetype_to_command, &filetype, 'bash')
:%y
new | 0put
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
exe '%!'.l:cmd
normal! ggO
call setline(1, 'Output of ' . l:cmd . ' command:')
normal! yypVr=o
endfunction
]]
nnoremap('<F3>', ':call ExecuteFile()<CR>', true)

----------------------------
-- Sort Json Array by key --
----------------------------
Expand Down
50 changes: 0 additions & 50 deletions .config/nvim/lua/user/options.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
local utils = require 'user.utils'
local opts = utils.map_opts
local keymap = utils.keymap
local tnoremap = utils.tnoremap
local vnoremap = utils.vnoremap
vim.o.compatible = false
vim.g.python3_host_prog = 'python3'

Expand Down Expand Up @@ -147,51 +142,6 @@ vim.o.expandtab = true -- Tab changes to spaces. Format with :retab
vim.opt.indentkeys:remove '0#'
vim.opt.indentkeys:remove '<:>'

-- Allow clipboard copy paste in neovim
keymap('', '<D-v>', '+p<CR>', opts.no_remap_silent)
keymap('!', '<D-v>', '<C-R>+', opts.no_remap_silent)
tnoremap('<D-v>', '<C-R>+', true)
vnoremap('<D-v>', '<C-R>+', true)

-- Abbreviations
vim.keymap.set('!a', 'dont', [[don't]], opts.no_remap)
vim.keymap.set('!a', 'seperate', [[separate]], opts.no_remap)
vim.keymap.set('!a', 'rbm', [[# TODO: remove before merging]], opts.no_remap)
vim.keymap.set('!a', 'cbm', [[# TODO: change before merging]], opts.no_remap)
vim.keymap.set('!a', 'ubm', [[# TODO: uncomment before merging]], opts.no_remap)

-- Run current buffer
vim.cmd [[
" Will attempt to execute the current file based on the `&filetype`
" You need to manually map the filetypes you use most commonly to the
" correct shell command.
function! ExecuteFile()
let l:filetype_to_command = {
\ 'javascript': 'node',
\ 'python': 'python3',
\ 'html': 'open',
\ 'sh': 'bash'
\ }
call inputsave()
let sure = input('Are you sure you want to run the current file? (y/n): ')
call inputrestore()
if sure !=# 'y'
return ''
endif
echo ''
let l:cmd = get(l:filetype_to_command, &filetype, 'bash')
:%y
new | 0put
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
exe '%!'.l:cmd
normal! ggO
call setline(1, 'Output of ' . l:cmd . ' command:')
normal! yypVr=o
endfunction
nnoremap <silent> <F3> :call ExecuteFile()<CR>
]]

-- disable some builtin vim plugins
local default_plugins = {
'2html_plugin',
Expand Down

0 comments on commit dae4489

Please sign in to comment.