lists.vim
lists.vim copied to clipboard
Opening new line from list causes unwanted indent
When in a list, in normal mode, hitting o
causes the new line to be opened, but with the cursor indented irregularly. See image.

I believe this is due to your own configuration or some plugin. Can you provide a minimal example? Something like this:
test.vim
set nocompatible
set runtimepath^=~/.local/plugged/lists.vim
set noswapfile
set nomore
runtime plugin/lists.vim
silent edit list.txt
ListsEnable
list.md
# List
* First entry. Long line
that spans two lines.
* Depth two 1 also a long
line.
* Depth two 2 short line
* Depth three 0
* Depth three 1 with long line here.
spans three
lines.
* Depth three 2 and 2
lines
* Depth two 3
2 lines
* Second entry
also two lines
* Depth two 1 single line
* Depth two 2
three lines
* A
* Aa
* Ab
* Ab1
* Ab1i
Open with nvim --clean -u test.vim
(neovim) or vim -u test.vim
(Vim). Now check if you still have the problem. If you don't, then this is likely to be a problem caused by your configuration or a plugin.
Excuse my ineptitude when it comes to code: I have no idea how to do what you are asking in MacVim (which is how I do Vim).
Hmm, ok. Are you familiar with terminals; can you open a terminal and run commands in them?
In the meantime, another way to do minimal setups is to make a copy of your vimrc file and then create a termporary vimrc file with minimal settings:
-
Copy your current vimrc for safekeeping.
-
Edit your vimrc file and add a minimal setup similar to the one I posted above. If you use vim-plug to install plugins, this should also work:
call plug#begin() Plug 'lervag/lists.vim' call plug#end()
Please adapt this; the point is to apply only the necessary configuration to reproduce the problem described in the issue.
-
Now open MacVim as you normally do, it should open with the minimal settings. Edit some simple lists.txt file or something similar, and enable lists.vim with
ListsEnable
. -
Is the problem still there?
The most relevant option for the behaviour of o
is :help 'formatoptions'
. The behaviour is also affected by other things, such as indentation settings. Notice that these are not really something lists.vim change, so the problem is essentially not a problem with lists.vim. But I'll try to help you figure out what's going on.
Which filetype are you working on when you see this issue (check with :set filetype
). Also, can you show me your current vimrc?
The most relevant option for the behaviour of
o
is:help 'formatoptions'
. The behaviour is also affected by other things, such as indentation settings. Notice that these are not really something lists.vim change, so the problem is essentially not a problem with lists.vim. But I'll try to help you figure out what's going on.Which filetype are you working on when you see this issue (check with
:set filetype
). Also, can you show me your current vimrc?
Thanks for your patience. I'll answer this one first, perhaps the exercise with the minimal settings you outlined earlier won't be needed.
Filetype = markdown
Here's my .vimrc
, with a few abbreviations, hostnames and paths removed for security reasons.
set nocompatible
filetype plugin indent on
augroup textobj_sentence
autocmd!
autocmd FileType markdown call textobj#sentence#init()
autocmd FileType text call textobj#sentence#init()
augroup END
set conceallevel=2
syntax on
colorscheme apprentice
set guicursor=i:block-iCursor
set guicursor+=n-i-v:blinkon0
set guioptions=
set ignorecase
set smartcase
set scrolloff=3
autocmd FileType text setlocal tabstop=16
let g:vim_markdown_folding_disabled = 0
let g:vim_markdown_folding_level = 6
let g:vim_markdown_strikethrough = 1
set backspace=indent,eol,start
set nobackup " do not keep a backup file, use versions instead
set noswapfile
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
set noshowmode
set cmdheight=1
set linespace=4
set clipboard=unnamed
call plug#begin('~/.vim/plugged')
Plug 'romainl/vim-cool'
Plug 'jremmen/vim-ripgrep'
Plug 'kana/vim-textobj-user'
Plug 'preservim/vim-textobj-sentence'
Plug 'ron89/thesaurus_query.vim'
Plug 'preservim/vim-markdown'
Plug 'tpope/vim-commentary'
Plug 'tommcdo/vim-exchange'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-obsession'
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-eunuch'
Plug 'unblevable/quick-scope'
Plug 'svermeulen/vim-subversive'
Plug 'tpope/vim-repeat'
Plug 'svermeulen/vim-yoink'
Plug 'svermeulen/vim-cutlass'
Plug 'lervag/wiki.vim'
Plug 'lervag/lists.vim'
call plug#end()
let g:wiki_root = '~/xxxxxxxx/vimwiki'
let g:wiki_filetypes = ['md']
let g:wiki_link_extension = '.md'
let g:wiki_link_target_type = 'md'
let g:wiki_map_create_page = 'WikiCreatePage'
function WikiCreatePage(text) abort
return substitute(tolower(a:text), '\s\+', '_', 'g')
endfunction
let g:wiki_map_text_to_link = 'MyTextToLink'
function MyTextToLink(text) abort
return [substitute(tolower(a:text), '\s\+', '_', 'g'), a:text]
endfunction
let g:wiki_mappings_local_journal = {
\ '<plug>(wiki-journal-prev)' : '[j',
\ '<plug>(wiki-journal-next)' : ']j',
\}
let g:wiki_fzf_pages_opts = '--preview "cat {1}"'
let g:wiki_write_on_nav = 1
nmap <leader>wi <plug>(wiki-journal-index)
nmap <leader>fw <plug>(wiki-fzf-pages)
let g:wiki_fzf_pages_force_create_key = 'ctrl-v'
nmap <leader>wb <plug>(wiki-graph-find-backlinks)
nmap <leader>wv <plug>(wiki-link-follow-vsplit)
inoremap <C-Space> <C-x><C-o>
let g:lists_filetypes = ['markdown', 'md']
let g:lists_todos = ['_TODO_', '_DONE_']
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-y': {lines -> setreg('*', join(lines, "\n"))}}
set foldmethod=expr
let g:netrw_liststyle = 3
let g:netrw_browse_split = 0
let g:netrw_altv=1
let g:netrw_banner = 0
let g:netrw_winsize = 30
let g:netrw_bufsettings = "noma nomod nu nobl nowrap ro rnu"
nnoremap <leader>th :ThesaurusQueryReplaceCurrentWord<CR>
let g:tq_enabled_backends=["openoffice_en","datamuse_com"]
let g:tq_openoffice_en_file="~/xxxxxxxx/MyThes-1.0/th_en_US_new"
inoremap <silent> <S-TAB> <esc>cas
inoremap <s-left> <esc>lcl
nmap s <plug>(SubversiveSubstitute)
nnoremap gm m
nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
let g:yoinkIncludeDeleteOperations=1
nnoremap m d
xnoremap m d
nnoremap mm dd
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
nnoremap z` zMzv
nnoremap Q vipgq
nnoremap <leader>tr :Texplore<CR>
nnoremap <leader>r :Rg<space>
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
map <Plug> <Plug>Markdown_EditUrlUnderCursor
nnoremap <leader>pda :!pandoc -V lang=nl -V papersize:a4 titel.md -o titel.pdf --template latekiss --top-level-division chapter
nnoremap <leader>pdb :!pandoc -V lang=en-GB -V papersize:a4 titel.md -o titel.pdf --template latekiss --top-level-division chapter -V numbersections
set nu rnu
set ch=1
if hostname() ==# 'xxxxxxxx'
set numberwidth=7
elseif hostname() ==# 'xxxxxxxx'
set numberwidth=7
else
set numberwidth=20
endif
set complete=.,w,b,u,kspell
set autoread
set autoindent
set wildmenu
iabbrev teh the
nmap <leader>s ysiw
nmap <leader>a }kA
nmap <leader>d :colo apprentice<CR>
nmap <leader>l :colo iawriter<CR>
nmap <leader>en :setlocal spelllang=en spell<CR>
nmap <leader>nl :setlocal spelllang=nl spell<CR>
nnoremap <Up> <c-b>
nnoremap <Down> <c-f>
nmap <leader>sw :setlocal tw=0 linebreak<bar>%s/\n\n/§§§/g<bar>%join<bar>:%s/§§§/\r\r/g<CR>
nmap <leader>hw :setlocal tw=60 nolinebreak<bar>norm ggVGgq<CR>
nmap <leader>ws :%s/\s\+$//
:map gf :e <cfile><CR>
inoremap . .<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
inoremap : :<C-g>u
nnoremap <leader>rm :call delete(expand('%')) \| bdelete!
set textwidth=60
set breakindent
set nolist
set display=lastline
set nospell
set undofile
set undodir=~/xxxxxxxx/undodir
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if has('gui_running') && has('gui_macvim')
set fullscreen
endif
autocmd CursorHold * update
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
cd ~/xxxxxxxx
if !exists('g:lasttab')
let g:lasttab = 1
endif
nmap <Leader>tt :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
au BufRead index.md normal zR
Tried outcommenting set breakindent
and set autoindent
, but the fault remains.
First, I took the liberty of removing all comments from the pasted vimrc - they don't matter to me or to this issue.
Next, here is an equivalent version, somewhat cleaned up. I've added comments like "NOTE: ..." where I have a particular comment. I did this mostly to faster understand your vimrc file, and you are of course free to keep your current version.
call plug#begin('~/.vim/plugged')
Plug 'romainl/vim-cool'
Plug 'jremmen/vim-ripgrep'
Plug 'kana/vim-textobj-user'
Plug 'preservim/vim-textobj-sentence'
Plug 'ron89/thesaurus_query.vim'
Plug 'preservim/vim-markdown'
Plug 'tpope/vim-commentary'
Plug 'tommcdo/vim-exchange'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-obsession'
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-eunuch'
Plug 'unblevable/quick-scope'
Plug 'svermeulen/vim-subversive'
Plug 'tpope/vim-repeat'
Plug 'svermeulen/vim-yoink'
Plug 'svermeulen/vim-cutlass'
Plug 'lervag/wiki.vim'
Plug 'lervag/lists.vim'
call plug#end()
" NOTE: plug#end will do the filetype plugin indent on and syntax on!
" Autocommands in vimrc should be kept in an augroup
augroup vimrc
autocmd!
autocmd FileType markdown call textobj#sentence#init()
autocmd FileType text call textobj#sentence#init()
autocmd FileType text setlocal tabstop=16
autocmd CursorHold * update
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
au TabLeave * let g:lasttab = tabpagenr()
au BufRead index.md normal zR
augroup END
" Options
colorscheme apprentice
set conceallevel=2
set guicursor=i:block-iCursor
set guicursor+=n-i-v:blinkon0
set guioptions=
set ignorecase
set smartcase
set scrolloff=3
set backspace=indent,eol,start
set nobackup
set noswapfile
set history=50
set ruler
set showcmd
set incsearch
set noshowmode
set cmdheight=1
set linespace=4
set clipboard=unnamed
" NOTE: This option is not useful in vimrc unless you also specify
" set foldexpr=EXPR. I suggest you remove it.
"set foldmethod=expr
set number
set relativenumber
if hostname() ==# 'xxxxxxxx'
set numberwidth=7
elseif hostname() ==# 'xxxxxxxx'
set numberwidth=7
else
set numberwidth=20
endif
set complete=.,w,b,u,kspell
set autoread
set autoindent
set wildmenu
" NOTE: Minor comment - 60 seems like an unconventional default?
set textwidth=60
set breakindent
set nolist
set display=lastline
set nospell
set undofile
set undodir=~/xxxxxxxx/undodir
if &t_Co > 2 || has("gui_running")
set hlsearch
endif
if has('gui_running') && has('gui_macvim')
set fullscreen
endif
" Mappings and abbreviations
inoremap <C-Space> <C-x><C-o>
iabbrev teh the
nmap <leader>s ysiw
nmap <leader>a }kA
nmap <leader>d :colo apprentice<CR>
nmap <leader>l :colo iawriter<CR>
nmap <leader>en :setlocal spelllang=en spell<CR>
nmap <leader>nl :setlocal spelllang=nl spell<CR>
nnoremap <Up> <c-b>
nnoremap <Down> <c-f>
nnoremap z` zMzv
nnoremap Q vipgq
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <leader>pda :!pandoc -V lang=nl -V papersize:a4 titel.md -o titel.pdf --template latekiss --top-level-division chapter
nnoremap <leader>pdb :!pandoc -V lang=en-GB -V papersize:a4 titel.md -o titel.pdf --template latekiss --top-level-division chapter -V numbersections
nmap <leader>sw :setlocal tw=0 linebreak<bar>%s/\n\n/§§§/g<bar>%join<bar>:%s/§§§/\r\r/g<CR>
nmap <leader>hw :setlocal tw=60 nolinebreak<bar>norm ggVGgq<CR>
nmap <leader>ws :%s/\s\+$//
map gf :e <cfile><CR>
inoremap . .<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
inoremap : :<C-g>u
nnoremap <leader>rm :call delete(expand('%')) \| bdelete!
" Plugin configuration
let g:vim_markdown_folding_disabled = 0
let g:vim_markdown_folding_level = 6
let g:vim_markdown_strikethrough = 1
let g:wiki_root = '~/Dropbox/Schrijven/vimwiki'
let g:wiki_filetypes = ['md']
let g:wiki_link_extension = '.md'
let g:wiki_link_target_type = 'md'
let g:wiki_map_create_page = 'WikiCreatePage'
let g:wiki_map_text_to_link = 'MyTextToLink'
let g:wiki_mappings_local_journal = {
\ '<plug>(wiki-journal-prev)' : '[j',
\ '<plug>(wiki-journal-next)' : ']j',
\}
let g:wiki_fzf_pages_opts = '--preview "cat {1}"'
let g:wiki_fzf_pages_force_create_key = 'ctrl-v'
let g:wiki_write_on_nav = 1
function WikiCreatePage(text) abort
return substitute(tolower(a:text), '\s\+', '_', 'g')
endfunction
function MyTextToLink(text) abort
return [substitute(tolower(a:text), '\s\+', '_', 'g'), a:text]
endfunction
nmap <leader>wi <plug>(wiki-journal-index)
nmap <leader>fw <plug>(wiki-fzf-pages)
nmap <leader>wb <plug>(wiki-graph-find-backlinks)
nmap <leader>wv <plug>(wiki-link-follow-vsplit)
let g:lists_filetypes = ['markdown', 'md']
let g:lists_todos = ['_TODO_', '_DONE_']
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-y': {lines -> setreg('*', join(lines, "\n"))}}
let g:netrw_liststyle = 3
let g:netrw_browse_split = 0
let g:netrw_altv=1
let g:netrw_banner = 0
let g:netrw_winsize = 30
let g:netrw_bufsettings = "noma nomod nu nobl nowrap ro rnu"
let g:tq_enabled_backends=["openoffice_en","datamuse_com"]
let g:tq_openoffice_en_file="~/xxxxxxxx/MyThes-1.0/th_en_US_new"
nnoremap <leader>th :ThesaurusQueryReplaceCurrentWord<CR>
inoremap <silent> <S-TAB> <esc>cas
inoremap <s-left> <esc>lcl
let g:yoinkIncludeDeleteOperations=1
nmap s <plug>(SubversiveSubstitute)
nnoremap gm m
nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
nnoremap m d
xnoremap m d
nnoremap mm dd
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
if !exists('g:lasttab')
let g:lasttab = 1
endif
nmap <Leader>tt :exe "tabn ".g:lasttab<CR>
nnoremap <leader>tr :Texplore<CR>
nnoremap <leader>r :Rg<space>
map <Plug> <Plug>Markdown_EditUrlUnderCursor
" Execute desired commands
cd ~/xxxxxxxx
Now, before we continue, can you be specific about which behaviour you expect after o
in a list line?
Thanks a lot, my .vimrc looks much better :-) However, the 'unwanted indent' remains.
Now, before we continue, can you be specific about which behaviour you expect after
o
in a list line?
I would expect a new line to be opened continuing the list. So
- List item
- List item|
In normal mode, with the cursor somewhere in the second list item line, this should result:
- |
Perhaps this is because I remember bullets.vim did that (but I had lots of other trouble with it).
I also noted that numbered lists are not continued. I'd write
- Test
... and hit return, and expect
... but instead I get just an empty new line.
The plugin is active (cntrl-s toggles a [ ]
checkbox).
Thanks, those are good explanations.
bullets.vim remaps both <cr>
and o
to achieve this behaviour. lists.vim tries to avoid this and instead rely on built-in mechanisms.
I'll look into it, in any case.
I've looked into this. First, and most important: Not everyone wants this behaviour (myself included). I sometimes write text with hard wrapping, where I want both o
and <cr>
to just start a new line properly indented with the current bullet point/number.
The Vim options comments
and formatoptions
can be used to change the behaviour of both <cr>
and o
, and lists.vim currently does rely on comments
to affect how things like gq
work on lists. I'm also adding a minor change to formatoptions
to make it slightly more "as expected", but it does not currently resolve your issue.
Notice that the :ListsToggle
(mapped to <c-s>
by default) is closer to what you want right now. If you hit <cr>
, then <c-s>
, it should add the bullet or number. If we can focus on this first and make it work as expected, then it could be possible to at least create a <plug>
mapping that people can use optionally for o
and <cr>
.
So, first: Can you verify that <c-s>
works as expected for you after <cr>
and o
opens a new line (regardless of indents)?
Both in MacVim and Terminal, control-s
after <cr>
and o
causes the cursor to jump to the command line, adding unexpected hidden characters in MacVim (see screen capture). I can make a screen recording if it helps.
There's no screen capture..? Whats the output of :verbose map <c-s>
(literally, as in four characers: "
n <C-S> @<Plug>(lists-toggle)
Last set from ~/xxxxxxxx/plugged/lists.vim/autoload/lists.vim line 69
https://user-images.githubusercontent.com/34862159/181590337-836887c3-1efb-4fde-b0f9-f7f6440e8d6f.mov
The mapping listed is the normal mode map. I should have asked for :imap <c-s>
- does it give a similar output?
Now we are getting there.
i <C-S> <Plug>Isurround
Precisely; can you (for the context of this issue) disable the plugin that adds that mapping?
And then repeat what I asked for previously.
Disabling tpope's Surround plugin causes <c-s>
after <cr>
to continue the list as intended, both in normal (hitting o
instead of <cr>
)and in insert mode. It would be a pity to lose the Surround plugin functionality, though...
Do you want to investigate this further? The surround plugin is quite popular, I think, so it might be worth the effort. Let me know if I can help.
Do you want to investigate this further? The surround plugin is quite popular, I think, so it might be worth the effort. Let me know if I can help.
Sorry, I've been busy, so I have not had time to follow up yet.
It would be a pity to lose the Surround plugin functionality, though...
Of course, you won't. Don't worry. I just want us to be on the same page about things before I make updates/changes/suggestions.
Disabling tpope's Surround plugin causes
<c-s>
after<cr>
to continue the list as intended, both in normal (hittingo
instead of<cr>
) and in insert mode.
Ok. So, does this mean that you can live with the lists.vim behaviour of <c-s>
as a "resolution" here? This is how I do things personally, and it gives me the option to easily add newlines within lists and then adding new list bullets/numbers with <c-s>
when I want them.
If so, then the last part is to handle the conflict with surround.vim; this is not hard. But before I explain that I want feedback on my previous question.
Thanks for your continued efforts! Yes, I could certainly live with that behaviour.
Great. :)
So, what you want is to have the functionality of <c-s>
from both lists.vim and from surround.vim. But you can't have both of these mapped to <c-s>
. To resolve this, you want to remap for one of the plugins. I don't know how to do it for surround.vim, so this is how to remap for lists.vim:
let g:lists_maps_default_override = {
\ 'i_<plug>(lists-toggle)': '<c-t>',
\}
See :help g:lists_maps_default_override
for more info on this.
PS! This is a new feature, so you must update the plugin first.
Let me know if this works for you as expected and if it is sufficient to resolve the issue.
Thanks. It works, but...
- Lists with dashes auto-continue without the
<c-t>
, which is inconsistent and means they can't be ended (going forward with normal newlines) by just hitting return. Numbered lists don't auto-continue and do need the<c-t>
. -
<c-t>
is normally bound to 'indent list item' in insert mode, so to preserve that, I changed the lists shortcut to<c-l>
. - Lists with items starting
- [ ]
auto-continue with just the dash, and the new shortcut doesn't provide the missing[ ]
.
Thanks for the update!
I believe I need to do some changes and improvements here. I originally had <c-s>
for toggling lists (normal mode), and added <c-s>
in insert mode for the similar thing, except also to add missing number/dash/etc. But I believe it would be better to change.
The current docs say:
*:ListsToggle*
*<plug>(lists-toggle)*
Toggle a list item. The mapping works in both normal and insert mode.
But I think this is better:
*:ListsToggle*
*<plug>(lists-toggle)*
Toggle a list items "status". For checkboxes, this means to toggle the
checkmark on/off. Elsewhere, we toggle between statuses defined in
|g:lists_todos|.
*i_<plug>(lists-new-element)*
An insert mode mapping to add a new element in the current list. This is
useful after creating a new line below a list element to add the
bullet/dash/number in front, possibly with a checkbox if relevant.
What do you think?
Sounds very good!
Ok, I've updated now. Please read the updated docs and test. I think, if nothing else, it is closer to decent now.
Hi. Lists with dashes still auto-continue without the (new) shortcut. And continuing a numbered list using the shortcut triggers the audible alert.
What's your formatoptions and comments settings? I.e., what's the ouptut of :set formatoptions
and :set comments
?
What's your formatoptions and comments settings? I.e., what's the ouptut of
:set formatoptions
and:set comments
?

