New answers tagged

1

Have a look at :help :!. It says: The command runs in a non-interactive shell connected to a pipe (not a terminal). Use :terminal to run an interactive shell connected to a terminal. As top requires a terminal, it can't be run this way. Running :!top in Vim works as expected, so :! seems to be implemented differently in neovim.


2

Is there a better way? In Vim there are always too many ways. I'd do it like this: " get result as List let output = systemlist('myprog') if v:shell_error echoerr 'Command failed! Error message:' output[0] else " add output on top call append(0, output) " delete the rest call deletebufline("%", len(output) + 1, "$") " go to first ...


1

If you're going the Python + ps route, then this should be better and more efficient: :pyx import os, subprocess :let vim_cmdline = pyxeval("subprocess.check_output(['ps', '-p', str(os.getpid()), '-o', 'cmd='])") Note that you're checking for the current PID (os.getpid()), since the Python interpreter is running inside the current Vim process. One (...


0

Sadly, this is what I came up with. Find the current process, the process parent, and use ps ax to obtain the path. Meant to work in mac. in Linux, it is easier with `/proc/XXX/cmdline'. PY import vim PY import os PY pid=os.getpid() PY kk=os.popen('ps -o ppid= -p ' + str(pid)).read() PY kk=kk.replace('\n','') PY tt=("let cmdline=system('ps ax | grep \""+...


1

If what you're looking for is a way to automate the sequence of commands (:silent grep and redraw!), then consider creating a new user-defined command for that operation. (In fact, Vim documentation essentially recommends it for this particular use case with their NewGrep example.) My recommendation would be: command! -nargs=+ -complete=file Grep \ ...


2

I suppose by "open files" you mean active buffers (see :h windows-intro). That could be achieved with the command :ls a (use h-flag to get hidden buffers if needed). To pack it into a function you could use a redirection or a dedicated getbufinfo() interface. For example function! GetActiveBuffers() let l:blist = getbufinfo({'bufloaded': 1, 'buflisted':...


1

Well, you need to do a redraw...per :h :!cmd... This requires a hit-enter prompt, so that you can read any messages. To avoid this use :silent !{cmd}. The screen is not redrawn then.... But if you're simply looking to reduce the number of keys to press perhaps I can interest you in an 89% reduction of the second command. A single key combo... Ctrl+L ....


Top 50 recent answers are included