dotfiles/nvim.configlink/settings/custom.vim

105 lines
2.4 KiB
VimL
Raw Normal View History

2021-04-12 00:49:42 +00:00
" Custom Commands
"----------------
command! Vimrc edit $MYVIMRC " Edit .vimrc (this file)
command! Refresh source $MYVIMRC " Refresh from .vimrc (this file)
2021-04-20 21:24:35 +00:00
command! Today exe 'edit ~/notes/journal/'.strftime("%Y-%m-%d_%a").'.md'
2021-04-12 00:49:42 +00:00
" Custom Keybinds
"----------------
" Map the leader key
map <Space> <Leader>
2021-05-10 01:58:06 +00:00
" Unsets the search pattern register by hitting return
2021-04-12 00:49:42 +00:00
nnoremap <silent> <CR> :noh<CR><CR>
2021-04-20 21:24:35 +00:00
" Shuffle lines around
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv
2021-04-12 00:49:42 +00:00
" Jump to text in this directory
nnoremap <Leader>/ :Rg<CR>
" Quit vim
nnoremap <Leader>q :quit<cr>
nnoremap <Leader>Q :quitall<cr>
" Save file
nnoremap <Leader>fs :write<cr>
" Make file executable
nnoremap <silent> <Leader>fe :!chmod 755 %<cr><cr>
" Make file normal permissions
nnoremap <silent> <Leader>fn :!chmod 644 %<cr><cr>
" Open file in this directory
nnoremap <Leader>ff :Files<cr>
" Change directory to this file
nnoremap <silent> <Leader>fd :lcd %:p:h<cr>
" Back up directory
nnoremap <silent> <Leader>fu :lcd ..<cr>
" Open a recent file
nnoremap <Leader>fr :History<cr>
" Switch between multiple open files
nnoremap <Leader>b :Buffers<cr>
" Switch between two open files
nnoremap <Leader><Tab> :b#<cr>
" Jump to text in this file
nnoremap <Leader>s :BLines<cr>
" Toggle Git gutter (by line numbers)
nnoremap <Leader>` :GitGutterToggle<cr>
2021-04-20 21:24:35 +00:00
" Git repo
nnoremap <silent> <Leader>gr :!gh repo view -w<cr><cr>
2021-04-12 00:49:42 +00:00
" Split window
2021-04-22 13:34:57 +00:00
nnoremap <Leader>wv :vsplit<cr>
nnoremap <Leader>wh :split<cr>
2021-04-12 00:49:42 +00:00
" Close all other splits
nnoremap <Leader>wm :only<cr>
2021-04-22 13:34:57 +00:00
" Zoom / Restore window.
" https://stackoverflow.com/a/26551079
function! s:ZoomToggle() abort
if exists('t:zoomed') && t:zoomed
execute t:zoom_winrestcmd
let t:zoomed = 0
else
let t:zoom_winrestcmd = winrestcmd()
resize
vertical resize
let t:zoomed = 1
endif
endfunction
command! ZoomToggle call s:ZoomToggle()
nnoremap <silent> <leader>z :ZoomToggle<CR>
2021-05-02 22:33:02 +00:00
" Exit terminal mode
tnoremap <A-CR> <C-\><C-n>
2021-04-12 00:49:42 +00:00
" Reload Vimrc settings
nnoremap <Leader>rr :Refresh<cr>
nnoremap <Leader>rp :Refresh<cr> :PlugInstall<cr>
" Tabularize
2021-04-22 13:34:57 +00:00
noremap <Leader>ta :Tabularize /
noremap <Leader>t# :Tabularize /#<CR>
noremap <Leader>t" :Tabularize /"<CR>
2021-04-17 22:04:53 +00:00
" Read todo comments
nnoremap <Leader>td /# \?TODO:\?<CR>