Search code examples
vimtaskwarrior

How to toggle a split window in Vim


I have the TaskWarrior Plugin installed. In order to show the tasks, you have to enter the :TW command. The problem is, TaskWarrior is displayed in the same buffer that I'm using for editing. In order to avoid that, I have to create a new Split window, switch to the split window and then enter :TW.

I want to have a command that does that in a "switch/toggle" style. The command will not create a new split window if a split window already exists. For example, I have the command to nt keystrokes and it creates/removes the split window each time.

Any suggestions on where to start and how difficult of a task that is?


Solution

  • I have adapted some online code and it is doing the job pretty well for now. This will toggle a TaskWarrior split tab when the combination nt is pressed.

    " Toggle TaskWarrior
    nnoremap nt :call ToggleTaskWarriorMode()<CR>
    vnoremap nt :call ToggleTaskWarriorMode()<CR>gv
    
    let g:TaskWarriorMode = 0
    
    function! ToggleTaskWarriorMode()
        let g:TaskWarriorMode = 1 - g:TaskWarriorMode
        if (g:TaskWarriorMode == 0)
           :close
        else
           :split task
           :TW
        endif
    endfunction