Questions tagged [external-command]

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

Filter by
Sorted by
Tagged with
1 vote
0 answers
35 views

How to paste an item selected by external FZF in the cursor position?

I know I can paste output of external shell command with :read! ls. But :read! ls|fzf doesn't work for me. Is there a way for me to go from vim to shell, use fzf to select an item, then go back to vim ...
nabik's user avatar
  • 11
2 votes
2 answers
82 views

See Last Commands Output from the Terminal Buffer

Lets say I run the external very_long_taking_command like this: :!very_long_taking_command and I get the output in this Vim Terminal where it says "Press ENTER or type command to continue". ...
Pixelbog's user avatar
  • 417
0 votes
1 answer
19 views

Convert sequence of external commands to a Vim custom command

To reformat Markdown tables, I use the following sequence of external commands (e.g. after visually selecting my table lines): :<,>! sed 's/[[:space:]]\{1,\}\|/\#\|/g' :<,>! column -t -s '\...
gjherbiet's user avatar
0 votes
1 answer
40 views

Pipe visual region to external command, not whole line

I have a keybinding nmap <leader>c :w ! wc<CR>, I wanted to expand it to work with visual regions (not just the whole file). I did so by creating vmap <leader>c :w ! wc<CR>, ...
Le-Kat's user avatar
  • 3
0 votes
1 answer
61 views

NeoVim - Interact with the thing that pop ups when you type in a command

Questions How can I type something in there? What even is the name of this thing? Problem If you type in for example :!echo 'Hello World' This kinda terminal thing pops up I want to interact with ...
Pixelbog's user avatar
  • 417
0 votes
0 answers
261 views

Neovim - Run an external command in nvterm, reload the current file once completed

What I am trying to do in Neovim is to open an Nvterm window, send a command (sleep in the example below) to it, wait until it finishes and the window is closed. Then reload the current buffer. Where ...
user134068's user avatar
0 votes
0 answers
38 views

Why does Vim search for the word under the cursor when pressing "i" after running an external command?

I stumbled on a behaviour which I don't understand. I'm using Bash and Vim 8.2.2434 in Debian 11. To reproduce it, I created two new files in an empty directory: foo.py class Foo: def __init__(...
mkrieger1's user avatar
  • 135
0 votes
2 answers
75 views

Can you pass specific text within a line to an external command?

Background Vim uses ranges to specify which lines should be passed to a command. For example, :5,10 will use lines 5-10, :'a,'b will use the lines between mark a and mark b, and :'<,'> will use ...
nullromo's user avatar
  • 161
0 votes
1 answer
28 views

read from ls command, create an array to move files

I recently discovered a great way to get a list of all files in a directory, I would like to create an array off of that list to then move the files to a new destination. Currently :read !ls * modify ...
superuser-Miguel's user avatar
1 vote
2 answers
157 views

Passing current line as argument to external command

Say I have a file with contents: abc def https://www.google.com and my cursor is on the 3rd line. How do I: run wget/curl with the contents of that line as argument (in particular, not pass the ...
shyamsfo's user avatar
1 vote
2 answers
207 views

How to create qf or location list from results of shell command

I often open the results of an external project-wide find | xargs grep command into a new tab like this :tabnew|read !find . -iname \*.py | xargs grep -n 'pattern' I then use gf to open the matching ...
textral's user avatar
  • 113
1 vote
2 answers
326 views

Insert Result of an Internal Vim Command into Text/Buffer (e.g. vims echo command)

Question I want to have basically the same as :read ![external command], but instead the external command I want to read the output from an internal command. Example Shells echo / external command: :...
Pixelbog's user avatar
  • 417
0 votes
1 answer
68 views

Put word count of lines into variable

I can get a word count of a range of lines, by doing something like this: :1,20w !wc -w (where that gets lines 1 to 20, writes (w) them to the external shell command (!) wc -w, and outputs the result ...
markling's user avatar
  • 319
1 vote
1 answer
209 views

Small issue when running Python code straight from VIM

I want to be able to set up the hot key \\ to be able to write and run python script from VIM without each time having to type in :w :! python3 file.py What I have done so far is pasted the following ...
alpastor's user avatar
  • 115
0 votes
0 answers
26 views

Scroll to top of previous terminal command

I am using vim to compile my code using the command :w | !make. If this output produces a lot of compiler errors (not uncommon lol), then I'd like to scroll to the top of the output, where the command ...
CrouchEndTiger's user avatar
1 vote
1 answer
27 views

How can I make a command that checks iteratively through parent roots until it finds something or reaches C:/?

I made a command line tool to generate static websites. I want a way to use this command line tool from the vim command line, something like the G command from the Fugitive plugin. The tool can only ...
Katie And's user avatar
2 votes
1 answer
282 views

vim line number does weird things on lines starting with an 8

I have some commands set up that run the test under my current cursor position. using the command rails test <filename>:<linenumber>. I execute this command through exec '!rails test %:'....
Enermis's user avatar
  • 161
-1 votes
1 answer
191 views

Vim is creating a .exe file when I run some C++ code. How do I save it to a specific directory?

I have some C++ source code that I am running. I have F9 and F10 mapped to the following in my vimrc file: autocmd filetype cpp nnoremap <F9> :w <bar> !g++ -std=c++14 % -o %:r -Wl,--stack,...
John Murthy's user avatar
0 votes
1 answer
68 views

How to filter lines only if the filter is successful?

I have the following lines in ~/.vim/ftplugin/python.vim: " yapf integration function FormatFile() :normal mp 0,$!yapf :normal `p endfunction autocmd BufWritePre *.py call FormatFile() ...
Quappas's user avatar
  • 53
0 votes
0 answers
50 views

What does semicolon mean in the imap statement?

For the statement: imap <F5> <Esc>:w<CR>:!python % <CR> When you press F5 key in insert mode,the current python file saved and executed by python. Someone write another ...
showkey's user avatar
  • 1,104
0 votes
0 answers
256 views

Call custom bash function from Vim

I have created a bash function, in its own .sh file, which I want to use from within Vim, and later use if from within the lightline config file. I have tried many ways, but I cannot make it work. ...
Xxxo's user avatar
  • 187
2 votes
3 answers
107 views

how to use shell script (external command) to select a file to open&edit

I've got a shell script: find... | stuff | xargs vi which works fine from the shell. But if I invoke that from inside Vim like :! find... | stuff | xargs vi it's kinda weird... like maybe I'm seeing ...
alec's user avatar
  • 785
0 votes
2 answers
805 views

How to execute a shell command with the current buffer content and open a new split buffer with the command output?

I have an external command which accepts a SQL. I want to execute it within vim while editing SQL. I found two ways but both are not very satisfying. :w !<cmd> This passes the content of the ...
jyshin's user avatar
  • 103
0 votes
2 answers
159 views

Is there a way to run current script in a split window (mimicing VSCode for example)?

When editing a script in vim, I can run it with :! bash % or :! python % for python scripts. When running the script, vim kinda goes back to the terminal, runs there, and then, after "ENTER" ...
CIsForCookies's user avatar
1 vote
1 answer
85 views

`:!sort` unresponsive

I want to randomly sort a file, but it somehow seems to be stuck in a loop or unresponsive. I dinstinctly remember it worked last time, so I must have done something wrong. Here is my code: :!sort --...
jxhyc's user avatar
  • 135
1 vote
1 answer
387 views

`:call append!` -- how vim insert line (append or setline) while respecting indentation

I want to put a string function output in my vim when press xx. My current working example is: nnoremap <silent> xx :call append('.', 'string_output')<CR> However, this put a line without ...
PiTao's user avatar
  • 25
4 votes
2 answers
195 views

Can a vim filter be interactive?

Is there a way to use a read filter that calls an interactive command? My use case is a grep command that returns a long list of tags that I might want to include in a blog post; I was hoping to be ...
n8henrie's user avatar
  • 346
4 votes
1 answer
279 views

How to reference a register in an ex command

I'm trying to write what I thought would be a simple macro to take some values that have been yanked into some registers (a & b) and use bc to do some addition with those values. Here is the ...
cewood's user avatar
  • 143
0 votes
1 answer
162 views

Run another command if first command fails on keypress

Is it possible to combine the two commands map <F5> :w<CR>:exec '!python' shellescape(@%, 1)<CR> map <F6> :w<CR>:exec '!poetry run'<CR> so that when I press F5, it ...
fl_'s user avatar
  • 11
2 votes
2 answers
376 views

Piping buffer through a command, handling failure gracefully

I want to be able to lint my code from within vim, using tools like clang-format and yapf and I'd rather do this without installing a more complex plugin. I can pipe the current buffer through a text ...
moo's user avatar
  • 155
0 votes
0 answers
151 views

Reindent html with xmllint

I'm trying to reindent current HTML file with this command from inside vim : :!xmllint --html --format % 2>/dev/null But, all it does it displays the output to stdout without actually modifying ...
SebMa's user avatar
  • 2,738
0 votes
2 answers
67 views

How to execute a shell script from a line in a file with `%` in it

I have a shell script on a line alone in a file which I would like to be able to easily execute from vim. Normally I could simply use Y:!^R", but this particular script has % in it, which is ...
Iiridayn's user avatar
  • 193
-1 votes
1 answer
116 views

how to filter text containing a vim variable?

In vim, version 8.1, I need to use a shell command, not on a constant text, but containing a vim variable. e.g. in Ex cmdline display by echo the difference in years from current date to a given date (...
Anton Wessel's user avatar
2 votes
2 answers
687 views

How to execute shell command and show result right inside vim similar to when execute command through autocmd?

The main objective of this question is I want to get the shell command's execution result to show in small split window right inside vim while I'm editing the file; the same result I would get when I ...
haxpor's user avatar
  • 121
0 votes
1 answer
103 views

au VimLeave ex mode command not returning output

I've been using the fmt Unix tool to standardise line length, for example :%! fmt -999 (thanks to this answer). I'd like to do this by default in Markdown files, so in ~/.vim/ftplugin/markdown.vim I ...
Josh Friedlander's user avatar
1 vote
2 answers
785 views

Colours in (g)vim output window

I've started learning Rust, and have been setting up my Vim workflow to use it. I'm still relatively new to Vim, and mostly what I've written in it is PHP for a website. Now that I'm working with a ...
murchu27's user avatar
  • 133
0 votes
1 answer
41 views

Paste the first column at the bottom line of the editing file

Here is the file sample.txt i am editing in vim: col11 col12 col21 col22 awk can cut the first column from sample.txt: awk '{print $1}' sample.txt In vim it is :!awk '{print $1}' %,how can i ...
showkey's user avatar
  • 1,104
2 votes
0 answers
191 views

How do I define a custom fixer for ALEFix?

I'm trying to use :ALEFix to run a fixer that is not pre-defined. For example, I might want to run foo -a -b index.html to format index.html with options -a and -b. foo does not read files from stdin, ...
August Janse's user avatar
1 vote
1 answer
259 views

How to pass custom arguments to the shell invoked by :terminal?

I would like to specify the startup command to run on the :terminal shell. E.g. bash -c ls. The shell can be specified with set shell=bash, but how to specify the arguments? In another use case, I ...
tejasvi88's user avatar
  • 440
1 vote
1 answer
4k views

How can I run awk script with in vim?

We know that we can run commands from vim using :!command <args>. For example: :%!awk '{ print $2,$1,$3 }' FS=',' OFS=',' :%!sort I am having trouble running an awk script within vim. I can run ...
Mithun B's user avatar
  • 113
2 votes
1 answer
389 views

How to use the current filename in a shell command?

I would like to run a shell command on the current file - ie, I saved an empty file and would like to delete it. I've found % represents the current filename, but when there are spaces in the filepath ...
Iiridayn's user avatar
  • 193
0 votes
1 answer
181 views

What is :silent !echo doing? Why does it get the cursor to the top?

This question on StackOverflow triggered my curiosity. What does :silent !echo doing? The first time I saw something like :excommand !shellcommand was when I was looking for a way to save a read-only ...
Enlico's user avatar
  • 2,172
-1 votes
1 answer
360 views

How can I display the sloc (source lines of code)?

Is there a way to display the sloc? I have searched every where and all I get is how to display total lines or how to show line numbers.
user419050's user avatar
1 vote
2 answers
495 views

Check if :make fails

I just setup this mapping for my latex development: nnoremap <buffer> <LocalLeader>o :make %:r.pdf <Bar> !open %:r.pdf<CR><CR><CR> But I wondered about checking if ...
D. Ben Knoble's user avatar
  • 25.3k
-1 votes
1 answer
72 views

Why doesn't xdg-open trigger autoread?

When set autoread,if I run :!kate %, do some editing operations and exit, the file in vim will auto reload to my new changes. However, :!xdg-open % doesn't work. My vim version is: VIM - Vi IMproved 8....
Run's user avatar
  • 99
0 votes
1 answer
245 views

Formatting using BufWritePost ends up with WARNING

I am trying to format PHP files using the following function: function! PHPCSFixer() let l:fixer_path = '$HOME/....
Jesus_21's user avatar
  • 111
1 vote
1 answer
102 views

Shortcut to open a particular website

I'm using neovim on mac os, in case that information is of use. In the shell I have some aliases such as alias g='open HTTP://google.com For sites that I access regularly, I would like to be able to ...
baxx's user avatar
  • 985
1 vote
0 answers
33 views

Fix line wrapping in external commands

Sometimes when I have a vim instance open for a long time, I'll notice that newlines no longer reset the column in external commands: :! echo a; echo b [No write since last change] a b Press ENTER ...
rampion's user avatar
  • 201
1 vote
2 answers
541 views

How to run external commands in vim from windows OS?

I learn vim in the Debian distro. In debian I can run commands like 'ls', 'cd', 'curl' etc directly from vim via power of '!' this sign. But now I am in windows because of the driver issue. But I don'...
Bapi's user avatar
  • 133
0 votes
1 answer
130 views

How to import library in my template python script? (not working like in vim like in the repl)

I have a python script for generating templates that's being invoked by this line in my vimrc file: autocmd BufNewFile ~/Documents/wiki/diary/*.mkd :silent 0r !vimwiki-diary-template.py That works. ...
alec's user avatar
  • 785

1
2 3 4 5