2

I'm creating a plugin and I'm writing its documentation according to :helptags. However I cannot link my tags if they have an hyphen in them. The strange thing is that help-writing itself has a hyphen and I can jump to it using CTRL-] depending on the vim instance I'm running.

For reproducibility:

1   ===============================================================================
2   CONTENTS                                                *vim-dictionary-contents*
3   
4   1. Intro ................................................. |vim-dictionary-intro|
5   2. Variables ......................................... |vim-dictionary-variables|
6   3. Details ............................................. |vim-dictionary-details|
7   4. Next steps ....................................... |vim-dictionary-next-steps|
8   5. Development ..................................... |vim-dictionary-development|
9   6. License ............................................. |vim-dictionary-license|
10  
11  ===============================================================================
12  1. Intro ~
13                                                             *vim-dictionary-intro*
14  
15  This plugin adds a dictionary functionality to your vim. It aims to be the
16  simplest. Only one command defined:
17  
18      Dictionary 'term'
19  
20  This command should open a new scratch window with the 'term' definition.
21  
22  All of this plugin's customization are two variables related to the window size
23  of the dictionary window.

I execute :helptags /path/to/dir.

Then putting my cursor on line 4 on the |vim-dictionary-intro| tag and pressing CTRL-] I get: E426: tag not found: intro which is pretty obvious.

By issuing set ft? I get filetype=help. So my conclusion is that the filetype is correct and I hoped that vim would understand that a word between | but that does not happen.

If I change vim-dictionary-intro to vimdictionaryintro I can jump around.

The question is then how to have the proper behavior as I have with help-writing ?

Helptags inexpected behavior if tag has hyphen

PS: no helptags tag for adequate keywording the question.

  • 3
    Did you modify the iskeyword setting by chance? What does :verbose set iskeyword? output? – Martin Tournoij Dec 14 '17 at 14:33
  • @carpetsmoker, you nailed it! It was being modified somewhere. I cleaned the temporary files/info files for my help and now works as a charm. What should I do? Remove the question? – fmv1992 Dec 14 '17 at 16:10
  • Best is to provide an answer which details what the problem is, how it was caused, and how you fixed it. That way is will be helpful for people searching for the same problem :-) – Martin Tournoij Dec 14 '17 at 16:31
2

TL;DR: not vim's fault: persistence in vim files was the problem.

So for the record the problem was not with vim. The plugin hierarchy and the customization level that we employ in our files make vim unpredictable sometimes.

The solution was to remove persistence related to the aforementioned help file. So after deleting the:

  • file from viewdir
  • file from undodir
  • file from backupdir

Things worked as expected. I find this function and command definition very helpful to avoid those things:

command! CleanViewFile :call s:CleanViewFile()
" s:CleanViewFile() " {{{
function! s:CleanViewFile()
    function! DeleteFromViewdir()
        " # Function to permanently delete views created by 'mkview'
        " https://stackoverflow.com/questions/28384159/vim-how-to-remove-clear-views-created-by-mkview-from-inside-of-vim
        let path = fnamemodify(bufname('%'),':p')
        " vim's odd =~ escaping for /
        let path = substitute(path, '=', '==', 'g')
        if empty($HOME)
        else
            let path = substitute(path, '^'.$HOME, '\~', '')
        endif
        let path = substitute(path, '/', '=+', 'g') . '='
        " view directory
        let path = &viewdir.'/'.path
        call delete(path)
        echom "Deleted: ".path
    endfunction
    function! DeleteFromUndodir()
        " # Function to permanently delete views created by 'mkview'
        " https://stackoverflow.com/questions/28384159/vim-how-to-remove-clear-views-created-by-mkview-from-inside-of-vim
        let path = fnamemodify(bufname('%'),':p')
        let path = substitute(path, '/', '%', 'g')
        let path = &undodir.'/'.path
        call delete(path)
        " echom path
        echom "Deleted: ".path
    endfunction
    function! DeleteFromBackupdir()
        " # Function to permanently delete views created by 'mkview'
        " https://stackoverflow.com/questions/28384159/vim-how-to-remove-clear-views-created-by-mkview-from-inside-of-vim
        let path = fnamemodify(bufname('%'),':t')
        let path = &backupdir.'/'.path.'~'
        call delete(path)
        echom "Deleted: ".path
    endfunction
    " Clean the view file and parse the modeline for current buffer.
    " Clean the view file and parse the modeline for current buffer.

    " Saves the file vithout creating the view file.
    " TODO: winsaveview may be a better option.
    let save_cursor = getcurpos()
    silent! noautocmd w!
    " set filetype=&filetype

    " Buffer name without extension.
    let buffer_name=expand("%:t")
    " Create variable to remove view file for this file.
    let shell_command="rm " . shellescape(&viewdir . "/*" . buffer_name . "*")
    " Clean the view file.
    silent! call system(shell_command)

    " Buffer name without extension.
    let full_buffer_name=expand("%:p")
    " Use sed to remove viminfo options from this file.
    " echom s:cachedir
    " TODO: Use sed to remove viminfo options from this file.
    " let shell_command="sed -i /" . full_buffer_name . "/^\s*$/d " . shellescape(s:cachedir . "/viminfo")
    " echom shell_command
    " silent! call system(shell_command)
    "
    " Full path to buffer.
    silent! execute "normal! :edit! " . full_buffer_name . "\r"
    silent! execute ":e!"
    " Improves by  the modeline reading the modeline.
    doautocmd BufEnter
    let &filetype=&filetype
    call setpos('.', save_cursor)
    call DeleteFromViewdir()
    call DeleteFromUndodir()
    call DeleteFromBackupdir()
endfunction
" }}}

And run :execute 'tabdo CleanViewFile' | silent! noautocmd xa! | silent noautocmd qa! from time to time.

Thanks @Carpetsmoker for the help.

| improve this answer | |
  • 1
    I doubt that backup or undofiles were the problem. you might want to set 'sessionopts' to not include option values. – Christian Brabandt Dec 14 '17 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.