Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:09:01+00:00 2026-06-09T17:09:01+00:00

I found some Vim list functions can not work as I thought. For example:

  • 0

I found some Vim list functions can not work as I thought.
For example:

let list0 = [1, [1, 2]]
echo count(list0, 1)

It returns 1, but I want it returns 2. So I think those functions can not deep into nested lists, only work on first level.

I think here I should expand nested list into a normal list like this:

list0 = [1, 1, 2]

How to flatten a nested list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:09:02+00:00Added an answer on June 9, 2026 at 5:09 pm
    " Code from bairui@#vim.freenode
    " https://gist.github.com/3322468
    function! Flatten(list)
      let val = []
      for elem in a:list
        if type(elem) == type([])
          call extend(val, Flatten(elem))
        else
          call add(val, elem)
        endif
        unlet elem
      endfor
      return val
    endfunction
    

    Here unlet elem is necessary. Because the elem variable is changing, it is a list item, or a list, and VimL does not support assign a list item to a list, and vice versa.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found some in the Cappuccino website (vim, textmate and SubEthaEdit), but not
I found some old code which I'm not sure I understand completely. The folowing
I found some result here, but can't figure out with my solution! and please,
I found some lovely websites - http://www.mini.jp/event_campaign/big-point/ , http://www.twenty8twelve.com/ and http://www.scozzese.com - all vertical
I found some problems when implementing Jake Wharton 's ViewPagerIndicator . These are what
I found some things I want to submit a pull request for in the
I found some classes designed for debugging in package com.sun.jdi like VirtualMachine , but
I found some old Python code that was doing something like: if type(var) is
I found some really great code from Matt Gallagher for use with making Undo
I found some mapkit code on the internet that looks like this: - (void)recenterMap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.