Questions tagged [external-command]

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

Filter by
Sorted by
Tagged with
5
votes
2answers
567 views

Why does gx call curl when the cursor is on a URL with trailing slash?

When my cursor is on a URL that ends with a trailing slash, for example : http://www.google.com/ ... if I type gx to open the link in my browser, curl is also called to download the webpage and the ...
4
votes
2answers
695 views

How to get line numbers of selected text

Is it possible to get the line numbers of selected text to pass to an external command? Context: I'd like to integrate pyfmt into vim. Ideally, I'd like to be able to select some text and type some ...
4
votes
2answers
212 views

Use search matches as parameters in external command

I want to define a Vim command that will install all LaTeX packages used in a .tex file. To install packages I can do sudo tlmgr install package1 package2 package3 etc. in the command line. So now I ...
4
votes
3answers
579 views

How to pass generic shebang line to shell

As far as I know, all "good" scripts/programs start off with a shebang line as the first line: #!/bin/bash #!/usr/bin/env python #!/usr/bin/perl etc. Is it possible to pass that line to Vim in ...
4
votes
2answers
490 views

Why do exclamation ! shell commands in GVIM show error: “syntax error near unexpected token (” for “ls() (”?

E.g., it I do: !echo a or any other !, it first prints: syntax error near unexpected token ( ls() ( /* my alias */ ) and then the actual command. The problem only happens in GVIM, not in Vim. ...
4
votes
2answers
1k views

Error when sourcing my .vimrc

I've just added this line to my .vimrc to be able to open chrome without leaving vim. command GoogleChromeA execute "!google-chrome > /dev/null 2>&1 &" It works fine however, when I ...
4
votes
1answer
343 views

Don't expand `%` in external grep call

I try to search for {% amount in all files under the current directory. Using ag, this works fine: ag -Q '{% amount' (-Q specify to not use any regex, try to match text literally) I have this in ...
4
votes
1answer
435 views

Autoreturn after external command [duplicate]

When I run the following command ex: :! some_command It's somewhat annoying the message: Press ENTER or type command to continue Is there a way to automatically return to current buffer without ...
4
votes
1answer
394 views

Why doesn't vim recognize bash self-made functions

Say, I defined a command in my ~/.bash_profile, (MacOS Sierra, Macbook Air, if it's relevant) function sayHello(){ echo Hello world! } and while using vim, intend to call :! sayHello It does ...
4
votes
3answers
111 views

How to filter discontinuous line sets through an external program (Is it possible to combine :g global command with :range! external program filter)?

Say you have some text like this: ## countries, primary United States,Washington,North America Canada,Ottawa,North America Australia,Canberra,Oceania ## countries, secondary France,Paris,Europe Japan,...
4
votes
2answers
373 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 ...
4
votes
3answers
703 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 ...
4
votes
0answers
180 views

How to utilize the Cygwin ack tool from Vim 7.4?

I used Cygwin perl and cpan to download, compile and test a working ack, struggling with a clean working model. Primarily using win32 Vim, it seems like I can only utilize the Cygwin ack if I change ...
3
votes
2answers
478 views

Passing a # character to the shell in vimscript?

In my previous question, I passed an argument into a Vimscript function and concatenated it into the command line. This works great, but when you pass a string that contains the # character, it balks ...
3
votes
2answers
130 views

Creating a list of files contained in a buffer

Let's say I have the following buffer: foo.txt bar buzz.txt fizz/foo.txt fizz/fuzz/fozz.txt Representing an arborescence that I need to create. How can I easily create it from Vim? I.e. How can I ...
3
votes
2answers
223 views

How can I use a range as input for an external command without deleting it?

I'm executing an external command that takes as input a range of lines within my file. :'<,'>!copy_stuff Running this runs copy_stuff correctly with the currently selected visual range (and it ...
3
votes
2answers
310 views

Call PDF viewer on the compiled tex file

Suppose I am editing a file.tex. How would I open file.pdf in zathura (or any pdf viewer) from vim? I understand how to reference file.tex using '%' but I'm not sure how to reference file.pdf.
3
votes
2answers
2k views

How to export information from vim to bash

When you execute the shell in vim via the :sh command, the shell that is set in the shell option is executed. However, is it possible to pass some information from the vim instance that you are ...
3
votes
4answers
620 views

Filter specific lines matching a pattern through external command

I'm trying to filter specific lines through external command. I think knowing how to do this would be extremely beneficial to me, so I'm trying to find a way to do this. As an example, I wanted to ...
3
votes
2answers
198 views

ex mode choice of shell for external commands

When I'm shelling out some external command using ! :r !pbpaste or :!./path/to_my_script What environment will be used and how to manually configure it? I'm a big fan of ZSH. Can I have some ...
3
votes
1answer
8k 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-...
3
votes
1answer
898 views

Why does vim use temporary file or pipe for shell commands?

One can configure Vim to use temporary files(stored in /tmp directory by default) when shell commands(for example :%!ls) are executed. Those temporary files contain the output of an external command. ...
3
votes
1answer
753 views

How to get the names of all open buffers?

I can use % to get the name of the focused window for commands. How can I get a space-separated list of all buffers for use in a command? For example, I would like to call :!cat [all] where [all] ...
3
votes
1answer
782 views

Insert filename in external-command

I'm using Latex a lot lately and I find myself having to leave vim so I can execute the command pdflatex *filename* too often (compile the code and create a pdf file). I'd like to make a command ...
3
votes
2answers
396 views

Vimfiler (a plugin): how to open .doc file using MS Word

I have a question regarding a plugin called Vimfiler. What I want is to open a .doc/.docx file using MS Word from Vimfiler. For this, I added the following call vimfiler#set_execute_file('doc,docx', '...
3
votes
1answer
1k views

How to define a custom user defined command to filter a range?

I want to select some lines in visual mode, and enter a custom command :Ex<CR> so that: '<,'>!expand -t4 is run to expand all tabs in selected range. How to define the Ex command? I ...
3
votes
2answers
474 views

Is there a simple way to require clean syntax before saving?

I currently use Ricardo Signes's plugin to allow me to use a single command to both check my Perl syntax and save my code only if it is syntactically correct. However, isn't there a simpler way to do ...
3
votes
2answers
1k views

How can I run :! commands inline instead of in a new cmd.exe window?

When using Gvim on Linux I can use :!ls to list files and directories 'in-line' in Gvim to navigate around the file structure and open files. However, on Windows when using :!dir, a cmd window opens ...
3
votes
1answer
91 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 ...
3
votes
1answer
218 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(...
3
votes
3answers
2k views

Execute external command in split window

Is there a way to get the following in Vim: If I execute a command in Vim like !make c, I would like to have a frame/split that pops up like in syntastic instead of switching to terminal view. That ...
3
votes
1answer
471 views

How can I make a slow-ish `system` call in a statusline without corrupting the display?

I wrote a quick snippet of VimL to display, in my statusline, the type of the currently focused Haskell expression It looks like this (click for better quality (as gfy)): I've included the code below,...
3
votes
1answer
1k views

How to setup AG (the silver searcher) in vim?

I am using AG to simplifying and improve the search in my vim. I remapped K to search for the current selected word as follows: if executable('ag') set grepprg=ag\ --nogroup\ --nocolor command -...
3
votes
1answer
58 views

How to open internal MediaWiki links with their full URL from within Vim?

I have a file in Mediawiki format, containing internal links (in a Mediawiki installation) * [[Topic A]] * [[Topic B]] * [[Vim]] (The asterisks are how MediaWiki lists are formatted, they are not ...
3
votes
1answer
69 views

How can I write a range to a command, and then read the resulting output?

I have an SQL file that I have to work on from the command line. -- Query 1 select 1; -- Query 2 select * from metadata; I've marked line 4 as a (4Gma) and line 5 as b (5Gmb), then execute :'a,'b w !...
3
votes
1answer
1k views

Run a python script without closing buffer [duplicate]

I have a script that writes output to a text file which I have open in a split side-by-side my code. If I use :! python % it will close the window to display the terminal, show the script's terminal ...
3
votes
1answer
89 views

Why using external “tr” command on lines with Farsi numbers does not work correctly?

I want to use external tr command on a line in Vim. When the source or replace pattern includes Farsi numbers the result is unpredictable. Executing :.!tr 1 ۱ on 1 results: Û Executing :.!tr ۱ 1 on ...
2
votes
2answers
2k 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 ...
2
votes
2answers
319 views

make external command completion case insensitive when called from within Vim

I've been learning Vi/Vim for some month and, at the moment, I'm editing many files at once splitting the window, jumping from one buffer to the others. I find it very useful. One thing I don't like ...
2
votes
3answers
229 views

How to find non duplicate <type:keywords> of a file?

I need a vim shortcut to display all non-duplicate struct names in the file being edited. I have made this C program which does this, however I have to leave the editor and execute the program in bash ...
2
votes
2answers
62 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
846 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 ...
2
votes
2answers
768 views

How to execute xdg-open from NERDTree in Linux?

Netrw able to execute file with xdg-open by pressing x, how about NERDTree ? [Response to downvote] If xdg-open can so easy/direct to work (which is the reason of downvote), then what's the point ...
2
votes
1answer
164 views

inspect filter output in minibuffer or a new buffer

Would like to send a line to an external programme and inspect output in the minibuffer or a new buffer. Don't want the output to replace original text. How to do this? In gnu emacs there's M-| (...
2
votes
1answer
53 views

# turning to exe when running terminal command

First of, I am sure there are plugins that will do what I am trying to achieve but I am using this as an exercise to learn vim as I am still quite new so I am not really interested in plugin ...
2
votes
2answers
2k views

How do you pass user input to a system command?

I'm trying to write an autocmd to make a commit to a git repository. Here is some non-functional code that should illustrate what I'm trying to do: let g: CommMsg = '' augroup misc autocmd! ...
2
votes
1answer
123 views

Insert mode completion of executables in `$PATH` (like `compgen -c`)

When writing shell scripts, it is frequently necessary to call external commands in $PATH. Some of these have long names (e.g. system-config-printer-applet or xfwm4-workspace-settings), and it would ...
2
votes
1answer
90 views

How do I combine system() and “start” in a Windows environment

I am currently using gvim in an MS-Windows environment. As part of a vim script function, I need to open a pdf file. So I call system like so: call system(l:pdf_file) This opens and displays the ...
2
votes
1answer
332 views

separate stdout and stderr of system() command

I can catch the output of running a system command via system() or systemlist(), but that actually gives me the result of stdout and stderr combined. As I am only interested in stdout (and may use ...
2
votes
2answers
85 views

Filter text and insert text after cursor or in register?

I want to filter some text through an external command without replacing the text, but rather have some way of inserting it afterwards or wherever I want. Say I want to calculate: 2^8 = I mark 2^8 ...