2

I've looked through the vimwiki documentation and a few questions here on SO, but don't see how I can manage this. In vim-notes, hitting TAB within a list indents the entire list item. In vimwiki, hitting TAB within a list indents within the list item, leaving the list marker unmoved.

For example, I have written one list item and hit ENTER to start a second. Both vimwiki and vim-notes treat this similarly: they both match the indentation and list marker of the preceding line. [Here >--- is a TAB character, * is the list marker, and | is the curser position.]

1 >--- * My list item
2 >--- * |

If I'm using vim-notes, hitting TAB will achieve this:

1 >--- * My list item
2 >--- >--- * |

In vimwiki, hitting TAB will achieve this:

1 >--- * My list item
2 >--- * >---|

Obviously I can exit insert mode, navigate to the start of the line, hit TAB, then hit A to continue typing at the end of the line but that's not a good flow.

There is a setting, g:notes_tab_indents, that controls this behavior in vim-notes, but I haven't found a corresponding control for vimwiki. The closest reference I can find to the behavior vimwiki anticipates supporting is in g:vimwiki_folding where it discusses how vimwiki expects lists to be "nicely indented with shiftwidth":

*g:vimwiki_folding*

Enable/disable Vimwiki's folding (outline) functionality. Folding in
Vimwiki can uses either the 'expr' or the 'syntax' |foldmethod| of Vim.

Value           Description~

''              Disable folding    
'expr'          Folding based on expression (folds sections and code blocks)    
'syntax'        Folding based on syntax (folds sections; slower than 'expr')    
'list'          Folding based on expression (folds list subitems; much slower)    
'custom'        Leave the folding settings as they are (e.g. set by another
                plugin)

Default: ''

Limitations:    
  - Opening very large files may be slow when folding is enabled.    
  - 'list' folding is particularly slow with larger files.    
  - 'list' is intended to work with lists nicely indented with 'shiftwidth'.    
  - 'syntax' is only available for the default syntax so far.

The shiftwidth documentation describes functionality I'd never known about before: << and >>. The former reduces the current line/selection's indent by one tab stop; the latter expands the indentation. This is obviously not available in insert mode, so not optimal, but it'll definitely do in a pinch (especially when I remap it).

I read through the vim-notes code and short of replicating the functions in my own (first) project, I'm not sure if there is some vim functionality, e.g., some keymapping, that can achieve at least the TAB indentation behavior (much of the relevant vim-notes functions use regex patterns to match bullet styles).

Thanks in advance.

6

I'm going to ignore the majority of your question (perhaps someone will be along later to provide more specifically what you're asking for) and instead suggest that you just use insert mode's indent command: Ctrl-T.

:help i_CTRL-T:

Insert one shiftwidth of indent at the start of the current line. The indent is always rounded to a 'shiftwidth' (this is vi compatible). {Vi: only when in indent}

You can also use Ctrl-D for outdent.

EDIT: If you're dead set on indenting with the Tab key, a simple but inelegant method would be to map it:

:inoremap <tab> <c-t>

You'd presumably only want this to apply to vimwiki files, so add the command to a new file:

~/.vim/after/ftplugin/vimwiki.vim

This approach could of course be refined to only perform indent when appropriate, or to perform more intelligent indent. You could of course take a look at vim-notes's indent function for ideas/implementation tips.

  • Holy smokes. This is very close to and perhaps exactly what I'm looking for. How I managed to do all that searching (including /indent while in vim help) and not find it is...something. I'll likely accept this as the answer but will play a little first. Thank you. – Daniel Black Jun 1 '17 at 18:33
  • @DanielBlack See my edit for a quick fix. – Rich Jun 1 '17 at 22:23
  • 1
    Came here looking for the same thing as the OP and learned about <C-T> and <C-D> which I didn't know about before. Thank you very much! – snth Apr 26 '18 at 13:26
2

gll indents item right.

glh indents item left.

  • 1
    I guess this are mappings from vimwiki. You should add a little bit of context and perhaps what help tag to use to get more information. – Ralf Apr 9 at 15:26
  • 2
    Welcome to this site! Linking to the relevant documentation and a bit of context can be useful for future readers :) – statox Apr 9 at 15:26

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.