Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Grammatical and spelling correction + Tag addition
Source Link

This function outputs data, between braces as joined lines, in a quickfix window. The output is sorted based on linenumbersline numbers.

I'm searching for a method to sort the data alphabetically.

TriedI tried to exclude bufnr and lnum, but thats brakesthat breaks the relocation to the actual buffer.

function! Overview() abort
    0
    let bufnr = bufnr('%')
    let items = []
    while 1
        let start = search('^{', 'cW')
        if !start
            break
        endif
        let end = search('^}', 'W')
        let lines = getline(start, end)
        let lines = map(lines, 'trim(v:val)')
        call add(items, {
            \ 'bufnr': bufnr,
            \ 'lnum': start,
            \ 'text': join(lines, ' '),
        \ })
    endwhile
    call setloclist(winnr(), items)
    lopen
endfunction

This function outputs data, between braces as joined lines, in a quickfix window. The output is sorted based on linenumbers.

I'm searching for method to sort the data alphabetically.

Tried to exclude bufnr and lnum, but thats brakes the relocation to the actual buffer.

function! Overview() abort
    0
    let bufnr = bufnr('%')
    let items = []
    while 1
        let start = search('^{', 'cW')
        if !start
            break
        endif
        let end = search('^}', 'W')
        let lines = getline(start, end)
        let lines = map(lines, 'trim(v:val)')
        call add(items, {
            \ 'bufnr': bufnr,
            \ 'lnum': start,
            \ 'text': join(lines, ' '),
        \ })
    endwhile
    call setloclist(winnr(), items)
    lopen
endfunction

This function outputs data between braces as joined lines in a quickfix window. The output is sorted based on line numbers.

I'm searching for a method to sort the data alphabetically.

I tried to exclude bufnr and lnum, but that breaks the relocation to the actual buffer.

function! Overview() abort
    0
    let bufnr = bufnr('%')
    let items = []
    while 1
        let start = search('^{', 'cW')
        if !start
            break
        endif
        let end = search('^}', 'W')
        let lines = getline(start, end)
        let lines = map(lines, 'trim(v:val)')
        call add(items, {
            \ 'bufnr': bufnr,
            \ 'lnum': start,
            \ 'text': join(lines, ' '),
        \ })
    endwhile
    call setloclist(winnr(), items)
    lopen
endfunction
Source Link
Jane
  • 11
  • 1

function: sort output alphabetically

This function outputs data, between braces as joined lines, in a quickfix window. The output is sorted based on linenumbers.

I'm searching for method to sort the data alphabetically.

Tried to exclude bufnr and lnum, but thats brakes the relocation to the actual buffer.

function! Overview() abort
    0
    let bufnr = bufnr('%')
    let items = []
    while 1
        let start = search('^{', 'cW')
        if !start
            break
        endif
        let end = search('^}', 'W')
        let lines = getline(start, end)
        let lines = map(lines, 'trim(v:val)')
        call add(items, {
            \ 'bufnr': bufnr,
            \ 'lnum': start,
            \ 'text': join(lines, ' '),
        \ })
    endwhile
    call setloclist(winnr(), items)
    lopen
endfunction