Public Spots to Spend Time by Myself Over the Weekend

Visiting Ahmedabad for a few days; primarily looking to spend a few hours on weekends (Fri-Sun) reading - especially at public libraries. I've lived in Ahmedabad in the past, so, navigation won't be an issue. What I need to know is what good options I have, and, when/where/how do I register to have a hassle free experience getting in once I'm at a venue. I'm not looking for travel/touristy advice, just, good reading places (for long hours); preferably public libraries - with access to a variety of reading materials.

Any insight in this direction will be highly appreciated.

reddit.com
u/CRTejaswi — 1 day ago

Re-Enable Extensions to Work With Local Files

My Firefox recently updated to v153.0.4 (Windows10/22H2), and now, NONE of the extensions work with local files (had to re-install all, as most of my original configs were reset automatically). Files open up by default, but none of the extensions are allowed to act on them. (getting the usual - Your browser does not run web extensions like Vimium on certain pages, usually for security reasons).

I'm unable to use staple extensions like Markdown Viewer.

I've modified these (to false) for now, to no avail. Any guidance will be appreciated.

privacy.file_unique_origin
security.fileuri.origin_policy
security.fileuri.strict_origin_policy 
security.mixed_content.block_active_content
extensions.webextensions.allow_file_access_from_files
u/CRTejaswi — 4 days ago
▲ 3 r/vim

Persist ECHO (from function) on Visual Selection

How to persist echo from this function call (without using timers)

function! VisualStats()
    let wc      = wordcount()
    let [l1,l2] = sort([line('v'), line('.')])
    let txt     = join(getline(l1,l2), "\n")
    let sp      = len(substitute(txt, '[^ ]', '', 'g'))
    let st      = len(substitute(txt, '[^.!?]', '', 'g'))
    let pa      = empty(txt) ? 0 : len(split(txt, '\n\s*\n'))
    echo "CHARs " . wc.visual_chars . " WORDs " . wc.visual_words
    \. " SENTs " . (st > 0 ?st :1) . " PARAs " . pa . " SPACEs " . sp
endfunction
xnoremap <silent> C <Cmd>call VisualStats()<CR>

just like when directly keymapped?

xnoremap <silent> c <Cmd>let g:wc=wordcount()<CR><Esc>:
    \let t=join(getline("'<","'>"),"\n")<Bar>
    \let sp=len(substitute(t,'[^ ]','','g'))<Bar>
    \let st=len(substitute(t,'[^.!?]','','g'))<Bar>
    \let pa=empty(t)?0:len(split(t,'\n\s*\n'))<Bar>
    \echo "CHARs ".g:wc.visual_chars." WORDs ".g:wc.visual_words.
    \" SENTs ".(st>0?st:1)." PARAs ".pa." SPACEs ".sp<Bar>
    \unlet g:wc t sp st pa<CR>
reddit.com
u/CRTejaswi — 13 days ago
▲ 20 r/vim

What All Can I Do With A Visual Selection?

I'm looking for creative things one could do with selected blocks to make life easier - and associate them to keys. Some common keybindings I use are:

xnoremap _ :g/^\s*$/d<CR> # delete all empty lines
xnoremap # :g/^\s*#/d<CR> # delete all comments (assuming #)
xnoremap s :sort<CR>
reddit.com
u/CRTejaswi — 14 days ago
▲ 7 r/vim

StdLib Projects/Ideas?

Are there any projects (or even inbuilt stuff) that aid in bringing about a standard library of optimized utilities in VimScript? It doesn't even have to be VimScript stuff - could be a collection of binary utilities that work cohesively with VimScript constructs.

Context: I often use json files as lookup tables (eg. emojis), and over time, have made a collection of functions that enable using jsons in an API-esque manner (obviously using utilities such as jq/curl). I was wondering if there are existing projects out there that structurally enable tooling in Vim using utilities - imitating a standard library like behaviour.

Any insight in this direction is highly appreciated.

reddit.com
u/CRTejaswi — 18 days ago
▲ 24 r/vim+1 crossposts

Vim/Emacs: skills you've carried over from the latter to the former

Fellow Vimmers who've used Emacs in the past (or have coworkers who do), what are some skills you've carried over into your Vim configuration (or even a concept to simplify your workflow)?

I've been tooling recently (writing utility Vim code to fit my needs), and am looking for both inspiration (addressing meaningful issues), and, optimization (removing redundancies, ie, snappier implementations).

Hence, Emacs is an obvious avenue imo to learn from - without wanting to dabble into all its craziness (I have some experience in it, but don't use it routinely).

Any advice/insight in this direction is highly appreciated.

EDIT:

As a Vimmer myself, I miss not having features like MultipleCursors (tried using an extension long ago, but it slowed down usage so removed it). I stumbled upon this video from Tsoding that highlights the usefulness of Dired (Emacs builtin), and how MultipleCursors is an intuitive addon to it - to say, modify several filenames/extensions at once.

While I use ViFM, so, I can pretty much achieve the same thing, but was inspired, and sought to learn of other creative ways in which Emacs is used - so I may implement something similar for myself in Vim, if it's of use to me.

reddit.com
u/CRTejaswi — 22 days ago
▲ 15 r/vim

Translucent Text Label At Buffer's Corner

Is is possible to display a customizable text label at one of the corners (it mustn't block text written in the buffer itself) of an open buffer? I have several terminal panels open at once, so, having a visual marker like this would be great. Any advice in this direction is appreciated.

⚠ RESOLVED

popup works just fine for this task. I'd tried it earlier but couldn't make it persist, owing to a faulty highlighting logic of mine. Anyway, I'm listing a simple function that achieves set objective. You can modify it to add custom text, toggling & highlights.

Also, see this for how my solution worked out.

function! LabelOverlay(text)
    let l:options = {
    \   'line': 1,
    \   'col': &columns - strlen(a:text),
    \   'pos': 'topright',
    \   'wrap': 0,
    \   'zindex': 1,
    \   'highlight': 'Normal'
    \ }
    let g:popup_id = popup_create(a:text, l:options)
endfunction
call LabelOverlay("TEXT HERE")
u/CRTejaswi — 27 days ago

Display ONLY Output, NOT the Tab Completed Text

Setting a KeyHandler, so I can ?alias<ENTER> to get a cmdlet's source/definition.

My example tab-completes (using <ENTER>, so <TAB> isn't overloaded), so, obviously there's completion text. I want it to not be displayed (either erased, or, capture/print $output only).

Set-PSReadLineKeyHandler -Key Enter -ScriptBlock {
    $line = $null
    $cursor = $null
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line,[ref]$cursor)
    if($line -match '^\?([^\s]+)$'){
        $n = $matches[1]
        [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
        [Microsoft.PowerShell.PSConsoleReadLine]::Insert(@"
`$c = gcm '$n'
if(`$c.CommandType -eq 'Alias'){ (gcm (gal '$n').Definition).Definition
} else { `$c.Definition }
"@)
        [Microsoft.PowerShell.PSConsoleReadLine]::TabCompleteNext()
        [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
        return
    }
} # ?gcm

PS: I'm aware this blocks <ENTER> - it can be associated to something else, eg. -Key ' ,?', so, please ignore this for now.

⚠️ RESOLVED, thanks to surfingoldelephant, and monkeynin. Kudos for their meticulous implementations!

Set-PSReadLineKeyHandler -Key Enter -ScriptBlock {
    $line,$cursor = $null,$null
    [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line,[ref]$cursor)
    if($line -match '^\?([^\s]+)$'){
        $n = $matches[1]
        [Microsoft.PowerShell.PSConsoleReadLine]::DeleteLine()
        $c = gcm "$n"
        if($c.CommandType -eq 'Alias'){ $out = (gcm (gal "$n").Definition).Definition
        } else                        { $out = $c.Definition }
        Write-Host $out
    }
    else {}
    [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
} # ?gcm
reddit.com
u/CRTejaswi — 1 month ago

Issue When Piping Raw Bytes

Why does parsing STDOUT (-) work correctly in the first case, but fail in the second?

magick  _.png -negate png:- | chafa --size=70x -f sixel -  # PS7.6 ✔

function img     { chafa.exe --size=70x -f sixel @args}
magick  _.png -negate png:- | img -                        # PS7.6 ❌
reddit.com
u/CRTejaswi — 2 months ago
▲ 7 r/vim

put: String Parsing Issue

Here, echo works fine, but put raises an error. Why?

AIM:

let s:key_handlers = #{
  \ a: {-&gt; execute('echo "a"')},
  \ b: {-&gt; execute('echo "b"')},
  \ c: {-&gt; execute('echo "c"')},
  " ... fill d-z
  \ }

APPROACH:

:echo join(map(split('defghijklmnopqrstuvwxyz', '\zs'), '"\\ ".v:val.": {-&gt; execute(''echo \"" . v:val . "\"'')},"'), "\n")
:put =join(map(split('defghijklmnopqrstuvwxyz', '\zs'), '"\\ ".v:val.": {-&gt; execute(''echo \"" . v:val . "\"'')},"'), "\n")

ISSUE:

E115: Missing single quote: '

⚠ SOLVED, courtesy u/LostAd6514

reddit.com
u/CRTejaswi — 2 months ago
▲ 41 r/vim

Vim: Snippet to Quickly Display RGBA Images

Following the previous post on the topic, here's a snippet to play a sequence of frames (chess game in my example). Enjoy!

Tested on WSL. Vim v9.2.0612.

To generate frames, try this in powershell:

ls *.png | %{ magick $_.FullName -alpha on -depth 8 "RGBA:$($_.BaseName).rgba" }
u/CRTejaswi — 2 months ago
▲ 4 r/vim

Vim9.0: Commenting Inside A Dictionary

How do I safely insert comments inside a dictionary definition?

let s:groups = {
\ '0': {                         " group 0
\   '':  ['#000000', '#ffffff'], " black/white
\   '0': ['#000000', '#f5f5f5'], " ...
\   '1': ['#000000', '#dcdcdc'], " ...
\   '2': ['#000000', '#d3d3d3'], " ...
\ },
...
\}
reddit.com
u/CRTejaswi — 3 months ago

Unexpected Behaviour with `args[$_]`

This snippet:

function lf {
    if ($args){
        (0..($args.Count-1) | %{ "$args[$_]" }) -join ','
        (0..($args.Count-1) | %{ "$($args[$_])" }) -join ','
    } else{
        ...
    }
}
lf pdf png txt

prints:

[0],[1],[2]
,,

instead of the expected pdf,png,txt. Why?


I'm concerned with 0..N | args[$_] failing (but args[N] works) even though the syntax pipes well to most objects/cmdlets.

⚠️ RESOLVED, thanks to surfingoldelephant.

reddit.com
u/CRTejaswi — 3 months ago