Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom mappings #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
leave appended parameters to mappings
No need to add specific support to add followed_by strings and enter insert
mode; this can just as easily be done afterwards by normal commands.
  • Loading branch information
shiar committed Jul 1, 2019
commit 2f2de5fb9e02d8b6837ff7507652848a628c525d
25 changes: 8 additions & 17 deletions ftplugin/timesheet.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
" Create a new entry.
" followed_by: string to append after the timestamp
" optional parameter: set to false (e.g. 0) to _not_ go into insert mode
" afterwards
function! s:NewTimesheetEntry(followed_by, ...)
let l:insertmode = get(a:, 1, 1)
" Create a new timestamp entry at the end of the file.
function! s:NewTimesheetEntry()
" Go to the end of the file, because that's the only place where
" inserting a new timestamped item makes sense.
normal G
@@ -14,19 +10,14 @@ function! s:NewTimesheetEntry(followed_by, ...)
execute "normal o\n" . strftime("%Y-%m-%d:")
endif
" Insert the timestamp and start insert mode.
execute "normal o" . strftime("%H%M") . a:followed_by
if l:insertmode
startinsert!
endif
execute "normal o" . strftime("%H%M")
endfunction

nnoremap <Plug>TimesheetStart :call <SID>NewTimesheetEntry(' ')<CR>
nnoremap <Plug>TimesheetStop :call <SID>NewTimesheetEntry('.', 0)<CR>
nnoremap <Plug>TimesheetContinue :call <SID>NewTimesheetEntry('^', 0)<CR>
nnoremap <Plug>(Timesheet) :call <SID>NewTimesheetEntry()<CR>

" Some mappings to insert a timestamped new line.
if !hasmapto('<Plug>TimesheetStart')
nmap <buffer> <LocalLeader>n <Plug>TimesheetStart
nmap <buffer> <LocalLeader>s <Plug>TimesheetStop
nmap <buffer> <LocalLeader>c <Plug>TimesheetContinue
if !hasmapto('<Plug>(Timesheet)')
nmap <buffer> <LocalLeader>n <Plug>(Timesheet)GA<Space><Space>
nmap <buffer> <LocalLeader>s <Plug>(Timesheet)GA.<Esc>
nmap <buffer> <LocalLeader>c <Plug>(Timesheet)GA^<Esc>
endif