Questions tagged [external-command]

Questions about calling external (shell) commands from within Vi or Vim.

Filter by
Sorted by
Tagged with
2
votes
1answer
30 views

Update external file based on VIM mode

Currently I have my vim set up to update the statuslline based on what mode the editor is in. Like if I'm in insert mode then the statusline turns red. Magenta in replace mode. Green in command ...
0
votes
1answer
22 views

Changing PYTHONPATH from inside VIM

Today I was writing code in VIM and wanted to change the PYTHONPATH and so I ran: :!echo $PYTHONPATH;export PYTHONPATH="/home/oli/git/published_libraries/computer_communication_framework";echo $...
2
votes
1answer
40 views

Why does vim call powershell surrounded by two single quotes?

I'm attempting to use powershell from gvim, and when I do...I set: :set shellcmdflag=-NoProfile\ -NoLogo\ -ExecutionPolicy\ RemoteSigned\ -windowStyle\ Normal\ -Command :set shell='C:\\windows\\...
1
vote
1answer
44 views

How to pass a string as stdin to a job?

I have a shell command which reads from stdin, processes the input, and writes to stdout. To call it synchronously from vim I can do system('mycommand', data) where data is some string my vimscript ...
0
votes
2answers
35 views

How to create a function to `hash` buffer content

I want to create a function that I can call to replace a specific string pattern with md5sum of current buffer. I have no experience writing VimL before and can't figure out the way to do it. This ...
0
votes
2answers
37 views

Can I pipe vim spelling suggestions to an external program?

I know I can write a buffer to an external program with :w !<command>, but is there a way to pipe the contents of the spelling correction list I get with z= into an external program (i.e. dmenu)...
3
votes
3answers
91 views

Write buffer to command and append stdout back to same buffer

I've opened an empty buffer with just vim. I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout. In my empty buffer, I ...
2
votes
1answer
115 views

get exit status from system() call

Calling the function system("<command>") or systemlist("<command>") retrieves the stdout output from a shell call to <command>. How can I retrieve the exit status of that command? ...
0
votes
2answers
29 views

Pass character-wise visual selection to an external command

I want to VISUAL select a piece of text character-wise and pass it to an external command. For example I want to select only the URL from the the text below abcde www.google.com abcde and open it ...
0
votes
2answers
287 views

How to execute commands in vim, piping the output back into the editor in real time?

So, to begin, this is similar to Pipe shell command into buffer in real-time. The difference is that the top answer there pipes the output to a new buffer. How do I pipe the output to the editor ...
0
votes
1answer
84 views

How do I control an external program from vim? The final end is to listen to audio and make a transcript in sync

So it seems that vim is great for so many things. And I love it. And yet, it is the configuration that sometimes is a limitation for those of us who don't get a tight grasp on how to tinker into it. I ...
0
votes
0answers
33 views

How does (neo)vim set $PATH for system(['command'])

When I want to call an external program, I have the option of spawning a shell or not. system('my command') will spawn a shell (executing your .bashrc/etc and all it seems). system(['my command']) ...
2
votes
1answer
30 views

Why does colon in shell command read the wrong file?

I write ruby test files in vim, and regularly run tests from the file I'm editing by running :!rspec %:N or something similar (to execute the test at line N). The problem is that when the first ...
1
vote
1answer
24 views

Retrieving results from variations of system('top') returns errors

Directly on the Ubuntu terminal, I can extract the results from top regarding a specific PID with: top -p <pid> -n1 | awk '/<pid>/' Where <pid> should be substituted with a PID ...
0
votes
1answer
110 views

Vim can't search for dot

I'm trying to write a Vim script function to toggle between -> and . but searching for . is seemingly impossible. I've tried to search using ASCII (decimal and hex) and it doesn't work. It all ...
1
vote
1answer
62 views

Function arguments + shell

I'm trying to write a command for adding a Python import line. The problem is that what's added it import a:name and not the module name. Here's the code func! PyImport(name) w silent !isort ...
0
votes
1answer
59 views

Shell coloring handling with :read command

How can I deal with the colored outputs of shell commands when inputing them with :read? As an example, I have a self-defined git log command, and I would like to see it in a split window. That works ...
0
votes
1answer
27 views

How to map a call to a system function using the current filename?

I've been using vim for a little while and I'm doing some LaTeX with it, using Tectonic as the engine. What I was doing to generate the pdf (without leaving the editor) :call system("tectonic main....
1
vote
2answers
44 views

How can I pass a text to an external program without changing the current buffer?

I want to do filter through an external program without actually filtering the lines (but to keep them). For example : %!grep aa > newfile If I do this, all the lines are deleted and I need to do ...
2
votes
1answer
309 views

opening powershell from inside vim

I want to run powershell from vim and I have achieved it using the following mapping: map <leader>cd :cd %:p:h<cr>:silent !powershell<cr> The problem is that I can't do anything ...
1
vote
0answers
63 views

How to make vim shell command wait for keypress?

I have assigned the macro !clear && gcc % && ./a.out to the key 'r'. So when I press '@r', I expect vim to: Clear the shell compile the current C file run the output The problem is ...
0
votes
0answers
24 views

error output when using commands proxied via WSL (asyncrun plugin)

I have wsl - ubuntu installed under Windows 10. Some ubuntu's commands are proxied to use in cmd by create .bat files and add them to PATH environment of windows10, pattern like following: @echo off ...
2
votes
1answer
49 views

:global, how to use matched pattern in the cmd of :g/pat/cmd?

Give a buffer each line contain a filename. how to use r! cmd on the filename, within a :g command? eg, BEFORE PROCESSING: file1.txt file2.txt AFTER PROCESSING (with wc -l): file1.txt 12 ...
1
vote
1answer
40 views

How to run shell commands on file without saving?

For example, if I want to run tidy on a file r! tidy % But I have to save the file beforehand. Is there any way around this?
3
votes
3answers
709 views

How to run zsh aliased command from vim command mode?

I have a bunch of really useful terminal programs which I use often while I am editing or writing. For example, dictionary is a popular one and I have aliased its usage to single character d in .zshrc ...
0
votes
2answers
235 views

How can I import output from linux commands into vim for editing?

Is there a way I can directly import/insert the output of any linux command into vim editor? For example: pwd in currently open vim buffer. Also From terminal how can I directly open command output ...
0
votes
1answer
32 views

e or tabe into path resulting from a ! command

Given a bash function, getMyFilePath(), which results in a directory path, /mydir, how can I open a new tab, passing this function to navigate there?
-1
votes
2answers
164 views

Shortcut for automatic execution

I've found the following command to execute Python or Matlab or any other language as far as I understand to execute code nnoremap <buffer> <F9> :exec '!python' shellescape(@%, 1)<cr&...
3
votes
2answers
172 views

sending variable commands in vim-slime

I am relatively new to vim and have started using the vim-slime plugin. One thing I use it for is to run python scripts, for example :SlimeSend1 python ~/myPythonFile.py I now would like to automate ...
1
vote
0answers
138 views

What encoding does :! use?

I'd like low-level control over exactly what bytes I send and receive from a process spawned from some vimscript. What encoding is used for communications with commands started with :!foo? Can I ...
1
vote
0answers
37 views

Change where a register actually points (in this case, redirect “+” [sys clipboard], to an external program) [duplicate]

Setting up vim on WSL, and I want to be able to redirect the vim internal clipboard to the windows clipboard. This is possible if running an X server like XMing, but I don't want to do that. I have 2 ...
1
vote
1answer
246 views

How to avoid “file has changed” warning when writing buffer?

I am using system() to change a buffer's file. I apply the same change to the buffer itself. I can't just reload the buffer because there are other unsaved changes. When I come to write the buffer, ...
3
votes
1answer
3k views

What is the correct way to escape UNC paths?

Let's say there is a file \\server-42\tmp\dir\test.txt. When my plugin tries to execute this command via system() it triggers an error: cd "\\server-42\tmp\dir" && git ls-files --error-...
1
vote
0answers
56 views

How does one automatically run a function when any error message appears?

I would like to play sounds for accessibility reasons. Do I need to patch and compile (neo)vim to provide some sort of OnError autocmd? edit: more generically I'm looking for a way to hook into ...
0
votes
1answer
69 views

Substring of filename in external command (bang)

Is it possible to execute bash string manipulations to the filename of the current file, represented by % in external commands from within vim? Example: I am editing a file myfile.txt. Using :! ...
0
votes
1answer
557 views

Can I disable running shell commands in Vim?

I am developing a command line application that uses Vim to edit an existing file. Think visudo or crontab -e. Is there any command line option that I can pass to Vim to disable shell commands?
0
votes
1answer
350 views

my ag shortcut chokes on spaces

I got this in my .vimrc: set grepprg=grep\ -nriI\ --exclude=tags\ --exclude-dir=vendor " The Silver Searcher if executable('ag') " Use ag over grep let &grepprg = "ag --nogroup --nocolor --...
2
votes
2answers
128 views

How to execute a bash command from the normal mode and send the output on a different buffer?

I have a bash_file that operates on a latex file to produce a pdf. #!/bin/bash /usr/bin/pandoc/ filein.md -t beamer -o fileout.md ; /usr/bin/pdflatex/ fileother.tex ; /usr/bin/evince fileother.tex ...
1
vote
1answer
101 views

How to disable vim source .cshrc when running external command?

I'm running external command inside vim by :!command. Noticed vim will source .cshrc before run the command, because I've added some echo in the .cshrc. Is there a way to force vim don't source the ....
1
vote
1answer
100 views

Execute selection and redirect output to new buffer/tab

I want to automate something I started using. Short story is I have a file with some lines and I want to execute each line every now and then and see its' output, but I don't want it to override the ...
2
votes
1answer
636 views

Copy output of bash command to system clipboard?

If I run: :w !node It will take my current buffer and send it to stdin and run the code in node. If I run: :redir @+ | echo "bob" | redir END It ends up on the system clipboard. But if I want to ...
1
vote
0answers
53 views

Reading in content from an external command with utf-8

I've got the following vim script to show a perldoc or per man page into a new tab and then rewrap it the text so it's more readable (I have a very wide monitor). nnoremap K :execute "tabnew <bar&...
3
votes
1answer
101 views

Why python autocompletion does not work if path to python binary is taken from variable?

I use YouCompleteMe for python3 code completion, and when I have let g:ycm_python_binary_path = '/usr/bin/python3' in my ~/.vimrc it works great. However, if I change it to let python3path = system(...
2
votes
0answers
65 views

Alter how oldfiles are displayed

Is it possible to "preprocess" the oldfiles list so that it's easier to navigate visually? As far as I can tell, the contents of the oldfiles list are presented as ordinary absolute paths, but with ...
4
votes
3answers
146 views

`Read` seems to bring an extra line - how to prevent this?

I set up this function in my .vimrc file. It duplicates the current window, moves it to a new tab, reads the output of yapf (a code formatter) run on the current file, sets up a diff between the ...
2
votes
2answers
196 views

Diffsplit with output of external command in Vim?

I know I can enter diff mode in vim by calling diffsplit <filename>. I also know I can call an external command and replace the file contents with its output (e.g. in this answer someone uses ...
2
votes
1answer
316 views

How to account for special characters \% in mapping

I am using vim on Windows and have following mappings: imap <f4> <ESC>:w<CR>:!clang -std=c++11 -o output\%.exe %<CR> imap <f5> <ESC>:!output\%.exe<CR> As we ...
0
votes
1answer
92 views

How to setup the default browser to follow hyperlinks [closed]

On a text file with a hyperlink (http://url/) if I hover the mouse over the hyperlink and click on it, it is opened on chrome. How can I change the browser that vim decides to use when following ...
0
votes
2answers
1k views

Executing a shell command in the parent directory

I'm trying to use :! to run my test suite. The file I'm working on is: /foo/bar/baz.py My tests are in: /foo/test I tried running :!../python -m unittest test but I get the following error:/bin/...
1
vote
1answer
185 views

Checking if Makefile exists before executing autocmd

I want Vim to execute build the project automatically after I write the buffer to a *.c or *.cpp file. Here is what I've done: autocmd BufWritePost *.c,*.cpp make This one works as expected (but the ...