Vim command to go past a closing ) } ] " ' without pressing right arrow? - vim

I have this problem every time I use a ( or any of " ' { [. I have plugin that automatically closes it by corresponding ) " ' } ] but I am stuck inside the parenthesis or inside double quotes
String s="I completed typing the string but my cursor is stuck right here |";
I want exit the enclosure by pressing something for all. In VScode I can press the same symbol if my cursor is right behind it and it gets past the enclosure or by pressing tab
I can exit the enclosure without reaching for right arrow

If your plugin is 'jiangmiao/auto-pairs' it has a variable called g:AutoPairsShortcutJump you can set as you want or use the default tha is Altn.
" Jump outside '"({
" -> default Alt-n
if !exists('g:AutoPairsShortcutJump')
let g:AutoPairsShortcutJump = '<A-l>'
endif
Note: If your cursor it close to the end atom you can just repeat that one to jump outside. For example:
Let's supose the character `|' represents your cursor
(|)
Just press closing parenthesis will jump outside

Related

Expand Command Line Arguments Autohotkey

TLDR; I am trying to find an equivalent to bash $# in autohotkey
I am developing an autohotkey script which will run a specific program when triggered.
<^#i::Run D:\Scripts\myprog.exe "arg_1" "arg_2"
; Runs with whatever arguments I provide on pressing Ctrl + Win + I
I want the program to be started with specific command line arguments; that I provide during starting the script.
> ahk_prog.exe arg_1 arg_2
I basically want to be able to convert my command line arguments provided during starting the program to be able to run the Run Command every time I trigger it.
I tried this:
<^#i::Run D:\Scripts\myprog.exe %A_Args% ; A_Args is the array of CLI arguments
; Runs with whatever arguments I provide on pressing Ctrl + Win + I
I also tried this(this one does not compile at all)
<^#i::Run D:\Scripts\myprog.exe "%*%" ; Trying Batch Like syntax since %1% and %2% are valid
; Runs with whatever arguments I provide on pressing Ctrl + Win + I
Both of them do not work. Is there a way to do this?
A_Args(docs) is an array, so you'll have join it into a string.
For example:
for each, arg in A_Args
arg_list .= """" arg """ "
arg_list := RTrim(arg_list) ;trim trailing space (might be unnecessary)
MsgBox, % arg_list
Added quotes around the argument, since they will of course be needed if your argument has spaces in it.
Then you can add it to your Run command like so:
for each, arg in A_Args
arg_list .= """" arg """ "
arg_list := RTrim(arg_list) ;trim trailing space (might be unnecesary)
<^#i::Run, % "D:\Scripts\myprog.exe " arg_list
Could also be done as a one-liner like so:
<^#i::Run, % "D:\Scripts\myprog.exe " RTrim(Format(StrReplace(Format("{:0" A_Args.length() "}", ""), 0, """{}"" "), A_Args*))

backspace not working in bash restricted mode

I am facing a problem with backspace in bash when used in restricted mode. I have already googled through lots of things, nothing worked or matching scenario am facing.
On pressing backspace, cursor is moving forward by one white space, but internally actually it's deleting the previous letter, i.e. on pressing "enter" it actually works but not visible on screen.
Example: command "ls backspace backspace", don't list anything (as expected) but on screen ls is visible after 2 backspaces and extra 2 white spaces are appended.
Looking forward for helpful suggestions. :)
Thanks in advance !! :)
Below is the piece of patch i used to chroot my bash.
Please have look and notify me if something is wrong here.
file: shell.c: ## -384,6 +387,30 ##
+ if (getcwd(pwd,sizeof(pwd)) != pwd )
+ {
+ return -1;
+ }
+ /* chroot to mount point path */
+ if( !(chroot(chroot_dir)))
+ {
+ seteuid(getuid());
+ setegid(getgid());
+ /* On successful to chroot env invoke bash prompt */
+ if(! chdir(pwd))
+ {
+ if(execlp("/rbin/bash","/rbin/bash","--restricted",NULL))
+ {
+ }
+ }
+ else
+ {
+ chdir("/");
+ if(execlp("/rbin/bash","/rbin/bash","--restricted",NULL))
+ {
+ }
+ }
+ }
Try using Backspace with Shift key, It should work.
If pressing backspace is printing a character, then you can use stty to change terminal settings like this: stty erase backspace_character where backspace_character is the character you get while pressing backspace.
you can use emacs command
for shell terminal you can hit command as below
set -o emacs
for vi editor you can hit command as below
set -o vi

Change and restore pastetoggle

Suppose that my pastetoggle is set to <F10>, if I run echo &pastetoggle it prints out <80>k; (Question number 1) how can I reach its value as string "<F10>" instead of this <80>k; code. I mean is it possible to set a variable to "<F10>" based on the value of pastetoggle?
Now if I run let #a=&pastetoggle and then run echo #a it prints out the same <80>k; string, but if I run let &pastetoggle=#a afterwards and run echo &pastetogggle it prints out <80><fe>Xk; (Question number 2) why? (Question number 3) how can I set pastetoggle based on value in #a?
The <80>k; is the internal keycode representation of <F10>; unfortunately, as you've found out, it cannot be saved and then reassigned to &pastetoggle.
You can get the "actual" value via
:set pastetoggle?
To capture that, you'd have to use :redir and string extraction:
redir => setOutput
silent! set pastetoggle?
redir END
let pasteToggleKey = matchstr(setOutput, 'pastetoggle=\zs.*')
echo pasteToggleKey

VIM: Check if a file is open in current tab? window? (and activate it)

In vim, you can check if a file is open in the current buffer with bufexists. For a short filename (not full path), you can check if it's open using bufexists(bufname('filename')).
Is there any way to check if a file is open in a tab?
My closest workaround is to do something like:
:tabdo if bufnr(bufname('filename')) in tabpagebuflist(): echo "Yes"
However, that's sort of pythonic pseudocode... I'm not sure how to get that to work in vim. My goal is for an external applescript to check if a file is already open and if so go to a line in that file.
Ideally, I'd like to be able to search through different GUI windows too, but I've gathered (e.g. Open vim tab in new (GUI) window?) that working with different GUI windows is very challenging / impossible in VIM.
My impatience and good documentation got the better of me... here's the solution (greatly aided by Check if current tab is empty in vim and Open vim tab in new (GUI) window?). The source is at https://github.com/keflavich/macvim-skim
function! WhichTab(filename)
" Try to determine whether file is open in any tab.
" Return number of tab it's open in
let buffername = bufname(a:filename)
if buffername == ""
return 0
endif
let buffernumber = bufnr(buffername)
" tabdo will loop through pages and leave you on the last one;
" this is to make sure we don't leave the current page
let currenttab = tabpagenr()
let tab_arr = []
tabdo let tab_arr += tabpagebuflist()
" return to current page
exec "tabnext ".currenttab
" Start checking tab numbers for matches
let i = 0
for tnum in tab_arr
let i += 1
echo "tnum: ".tnum." buff: ".buffernumber." i: ".i
if tnum == buffernumber
return i
endif
endfor
endfunction
function! WhichWindow(filename)
" Try to determine whether the file is open in any GVIM *window*
let serverlist = split(serverlist(),"\n")
"let currentserver = ????
for server in serverlist
let remotetabnum = remote_expr(server,
\"WhichTab('".a:filename."')")
if remotetabnum != 0
return server
endif
endfor
endfunction
then use like so:
exec "tabnext ".WhichTab('my_filename')
echo remote_foreground( WhichWindow('my_filename') )
or, from the command line, here's a script to go to a particular line of a file using WhichTab:
#!/bin/bash
file="$1"
line="$2"
for server in `mvim --serverlist`
do
foundfile=`mvim --servername $server --remote-expr "WhichTab('$file')"`
if [[ $foundfile > 0 ]]
then
mvim --servername $server --remote-expr "foreground()"
mvim --servername $server --remote-send ":exec \"tabnext $foundfile\" <CR>"
mvim --servername $server --remote-send ":$line <CR>"
fi
done
I'd reply to keflavich, but I can't yet...
I was working on a similar problem where I wanted to mimic the behavior of gvim --remote-tab-silent when opening files inside of gvim. I found this WhichTab script of yours, but ran into problems when there is more than one window open in any given tab. If you split windows inside of tabs, then you will have more than one buffer returned by tabpagebuflist(), so your method of using the buffer number's position in the List doesn't work. Here's my solution that accounts for that possibility.
" Note: returns a list of tabnos where the buf is found or 0 for none.
" tabnos start at 1, so 0 is always invalid
function! WhichTabNo(bufNo)
let tabNos = []
for tabNo in range(1, tabpagenr("$"))
for bufInTab in tabpagebuflist(tabNo)
if (bufInTab == a:bufNo)
call add(tabNos, tabNo)
endif
endfor
endfor
let numBufsFound = len(tabNos)
return (numBufsFound == 0) ? 0 : tabNos
endfunction
I think I can just return tabNos which will be an empty list that gets evaluated as a scalar 0, but I just learned vimscript and am not that comfortable with the particulars of its dynamic typing behavior yet, so I'm leaving it like that for now.

more syntax-aware navigation in vim

I have a good amount of code which looks like this:
rule requestIntHoleTemplate {
constr:HoleCall;
y:PrimitiveIntRange;
:IntRangeHole(constr, y);
modify {
emit("Request template IntRangeHole\n");
}
}
I'd like to skip over the entire block in vim, not just to the next empty line as } does. I can accomplish it with $%, but that wouldn't work if I'm on an empty line preceding the block. I suppose I could alias }{j$%j. Are there other navigation commands I'm missing?
Thanks in advance.
You can use ]] and friends, but they only work if the opening brace is on its own line.
]] next beginning of block
[[ previous beginning of block
][ next end of block
[] previous end of block

Resources