简体   繁体   中英

Customizing the cursor's position in zsh

I am using this snippet plugin in zsh shell and wanted to customize it. How I can customize the cursor's position to a specific place after expanding the snippet (like the editors usually do with the completion).

I write l and press Ctrl-d to expand it so it becomes $(line ) but the cursor goes after the entire snippet, I want it to be inside the snippet so I can write a number after the line and before the character )

This is the function responsible for the snippet expanding ( I still didn't edit anything from the source code, it is still the same as the repository ):

snippet-expand () {
    emulate -L zsh
    setopt extendedglob
    local MATCH
    LBUFFER=${LBUFFER%%(#m)[.\-+:|_a-zA-Z0-9]#} 
    LBUFFER+=${snippets[$MATCH]:-$MATCH} 
}

Everything you append to $LBUFFER will appear immediately to the left of the cursor. Conversely, everything you prepend to $RBUFFER will appear immediately to the right of the cursor. So, split your snippet into two parts and do

LBUFFER="$LBUFFER<left half of your snippet>"
RBUFFER="<right half of your snippet>$RBUFFER"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM