views:

592

answers:

3

In the past, I have used Vim as a note taking platform by creating an index.txt file with a list of tags using the Vim help file format and then creating a bunch of text files that have the normal *Help_Tag* link syntax so that using CTRL-] on a tag in the index.txt file will jump to the respective tag in an arbitrary notes text file. You need to do :helptags dir to generate the tags for the directory (where dir is the path to the notes directory).

alt text

What I am looking for is a simple way to be on the left split window and open the tag under the cursor in the right split window. Something like CTRL-W v but for tag jumping and using the already open vertical split window.

The problem is if you do CTRL-] it will open the tag in the left pane and if you do CTRL-W CTRL-] it creates a horizontally split window in the left pane.

There must be a way to do this that I'm overlooking.

+1  A: 

Probably the easiset would be an autocommand local mapping

au FileType index.txt nnoremap <buffer> <cr> 
    \ :vert belowright split 
    \ |tag <c-r><c-w>
    \ |vert resize 130<cr>

Note I use return

michael
Using the help command requires having the notes files in my .vim/doc folder. Plus it would open a new pane to the left. This can be avoided with `:rightb vert help test` but the width of the split is 50/50. Is there a way to specify the width of the vertically split pane?
Pierre-Antoine LaFayette
resizing is :vert belowright help resize|vert resize 130
michael
I'd like to use the 'tag' command instead of 'help' but this does get the job done. Do you know how I can make the tag command open in the right window? When I try it now it will open to the left.
Pierre-Antoine LaFayette
you just need to split|tag instead. I've updated the map. note I've used <c-r><c-w> instead of <cword> to mimick actual key motions. not sure if this makes a difference
michael
+1  A: 

map <A-]> :vsp<CR>:exec("tag ".expand("<cword>")) " Open the definition in a new vsplit

jinxed_coder
Now how do I get the split to open to the right of my current buffer?
Pierre-Antoine LaFayette
A: 

Try this mapping:

nmap <buffer> <C-]> :let word=expand("<cword>")<CR><C-W>l:exe "tag" word<CR>

It stores the word under the cursor in the variable word, then swaps the window and goes to the tag with that name. The <buffer> bit makes this mapping only apply to the current buffer.

Al