Skip to main content

Questions tagged [command-line]

Questions on ex- or colon-commands. For questions about command-line options used to launch the editor, use the [invocation] tag.

Filter by
Sorted by
Tagged with
12 votes
1 answer
3k views

How do I use a variable or return value in option, command, or mapping?

I have a variable foo with let foo='value', and a function F like function F() return 'value' endfunction and I want to use them in an option: :set option=foo, :set option=F(); or in a command: :...
D. Ben Knoble's user avatar
  • 27.2k
29 votes
1 answer
15k views

How to edit files non-interactively (e.g. in pipeline)?

I would like to edit files passed in pipeline input using vim in non-interactive way or edit files in-place (similar to sed). Few examples using sed: $ sed -i'.bak' s/foo/test/g file # Edit file ...
kenorb's user avatar
  • 18.7k
87 votes
1 answer
38k views

How to open multiple files in split mode?

I know how to split windows in vim, but it's possible to open multiple files using vim in split mode (at startup) from the command line? In example: vim file1 file2 file3 or: vim *.cpp
kenorb's user avatar
  • 18.7k
57 votes
5 answers
29k views

Dump the output of internal vim command into buffer

How do I dump an internal vim command (not shell command) into a new buffer? For example, I want to dump a listing of all plugins into :enew from :scriptnames so that I can search it.
Bryce Guinta's user avatar
20 votes
3 answers
467 views

What is the '[Command Line]' that sometimes comes up when I try to quit, and how can I quickly exit it?

Occasionally when I try to quit Vim, I get something that looks like this: I'm not sure how I accidentally invoke this, but my current method for escaping it is to hit random keys and eventually it ...
user avatar
20 votes
3 answers
19k views

vim doesn't show the command that is being typed

I was reading vimtutor and in lesson 2.1 there was this note about typing commands like dw: NOTE: The letter d will appear on the last line of the screen as you type it. Vim is waiting for you ...
Hamon's user avatar
  • 303
20 votes
4 answers
4k views

How can I use Readline shortcuts in the vim command line?

When I'm editing a Vim command, I would like to use the same shortcuts as in Bash and every other REPL: M-b to go back a word, M-Backspace to delete a previous word, M-u to convert the word to ...
Mihai's user avatar
  • 311
10 votes
2 answers
807 views

Is there a way to alias `:w'` to `:w`, to avoid creating files named '?

Occasionally, my pinky will graze the ' key while reaching for enter, resulting in :w'<Enter>. I've tried: cabbrev w' :w cabbrev w\' :w cabbrev "w'" :w None of them work. Is there a way to ...
mwcz's user avatar
  • 245
4 votes
1 answer
358 views

Vimrc tries to execute command defined on leader

I'm trying to have something like this in my .vimrc: nnoremap <leader>has :w | ! reset; runhaskell % <cr> How ever, now it prompts an error when loading .vimrc and tells me: :! reset; ...
Stephane Rolland's user avatar
99 votes
2 answers
72k views

Close and unload a buffer without exiting Vim

Often, I'll load some information into a temporary buffer, and then close it with :clo!. But this hides the buffer rather than unloading it entirely, even though I have nohidden set. I find this ...
Kevin's user avatar
  • 1,093
27 votes
2 answers
5k views

How to save a file for which I have no write permissions?

Sometimes it happens that I open a file and make some modifications as my own user, without noticing or "forgetting" to noticing the [read-only] warning in the status line (ie. some random /etc config ...
guido's user avatar
  • 1,777
11 votes
4 answers
1k views

Bring up the current file name for edition in the command line

How can I bring up the path to the current file in the command line, so as to type a similar file name? I don't want an abbreviation that would be replaced by the current file name, I want to edit the ...
Gilles 'SO- stop being evil''s user avatar
10 votes
2 answers
5k views

How to write whole buffer to standard output from the command line?

I would like to write whole buffer into standard output (/dev/stdout) instead of the file and the following command works as expected while editing the file: :w >> /dev/stdout Hint: Press ...
kenorb's user avatar
  • 18.7k
10 votes
3 answers
13k views

Is there a version of Vim or plugin with a Command Mode auto completion?

I'm wanting to learn Vim, but think it's probably too daunting. I imagine learning enough to become powerful with it, then forgetting 99% after I'm on a computerless project for a while. I know just ...
user12711's user avatar
  • 367
9 votes
2 answers
936 views

Prevent FocusGained autocmd running in command line editing mode

I have the following in my vimrc to automatically reload a buffer: " Triger `autoread` when files changes on disk " https://unix.stackexchange.com/a/383044/143394 autocmd FocusGained,BufEnter,...
Tom Hale's user avatar
  • 2,711
9 votes
2 answers
7k views

Enable incremental search and highlight while typing a search term?

While I enter a regular expression on the vim command line, I would like to see what matches the partial expression I already wrote. For example, while writing the command :%s/regular all words ...
Volker Siegel's user avatar
8 votes
1 answer
904 views

How to make command-line abbreviations that only trigger at begining of line

I have a custom save function, and bound it to :w by using an abbreviation: cabbrev w call SaveBuffer() This works, but I ran into issues when I wanted to reference window local variables because w: ...
Tumbler41's user avatar
  • 7,776
4 votes
1 answer
3k views

How to read the exact command executed by the shell when sent from vim?

Sometimes, when I send a shell command from vim, I receive an error. For example, when I type the following command :!chmod +x shellescape("%"), zsh complains with : zsh:1: unknown sort specifier ...
saginaw's user avatar
  • 6,856
4 votes
4 answers
3k 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 ...
baxbear's user avatar
  • 314
4 votes
1 answer
2k views

Can the command-line be edited/navigated using Vim commands?

How can I edit the text of a Vim command I've started typing out in the Vim command line? Example: If I type out a long search and replace command and realized I made a mistake. Now I want to move ...
I J's user avatar
  • 43
1 vote
1 answer
2k 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 --...
abbood's user avatar
  • 743
35 votes
8 answers
32k views

How to go to previous open buffer from Vim command line?

I am trying to write a Vim function which should make the window go to the previous open buffer. How can I do it from the command line? My first idea was to find out some Ctrl-O command line ...
ephemerr's user avatar
  • 873
34 votes
2 answers
22k views

Execute current buffer as bash script from vim

I use vim for bash scripting, and sometimes I write a one-time script. Usually, I don't want to create a new file, make it executable, execute it and then remove it. For instance I open vim and type ...
St.Antario's user avatar
  • 1,137
27 votes
4 answers
12k views

How to edit content from the standard input?

I would like to edit content in vim which was dynamically generated from the command-line without having the file yet. In example: $ echo This is example. | vim /dev/stdin $ cat /etc/hosts | vim /dev/...
kenorb's user avatar
  • 18.7k
18 votes
1 answer
33k views

Execute normal command over range

For a file looking like this: 2 AD,42.546245,1.601554,Andorra,376 3 AE,23.424076,53.847818,United Arab Emirates,971 4 AF,33.93911,67.709953,Afghanistan,93 5 AG,17.060816,-61.796428,...
FelixJN's user avatar
  • 283
18 votes
1 answer
2k views

Bash-like partial tab-complete for filenames in Vim

In Bash, when there are several files with the same prefix and I type part of the prefix and hit Tab, it completes the common prefix and allows me to continue typing to differentiate among the ...
John O'M.'s user avatar
  • 8,622
16 votes
1 answer
1k views

How is command history resolved between multiple instances of Vim?

Vim keeps a history of ex commands (accessible via :↑ and q:), and that history persists after quitting. If I run multiple instances of Vim (same user, same home directory), how does Vim arbitrate ...
200_success's user avatar
  • 9,629
14 votes
2 answers
2k views

How to escape a whole string in a : command?

Let's see. I have a gvim running and I want open a file, respecting the autocmds (which rules out --remote-tab). Now I know I can do (basically, with some tweak): gvim --remote-send ":tabe my_file&...
Rmano's user avatar
  • 758
11 votes
1 answer
446 views

Why does `<Bar>` behave like `|` in the `:command` command in Vim?

Here is the list of experiments I performed that shows that <Bar> is treated as literal <Bar> in some commands but it is treated as | in the :command command. I am trying to understand why ...
Lone Learner's user avatar
9 votes
3 answers
6k 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 ...
avimehenwal's user avatar
9 votes
1 answer
461 views

Difference between full and short command

Is there a practical difference between using :e and :edit Except for readability, where it make sense in a mapping to use :edit, because it's more explicit. Is there a difference between them? ...
nobe4's user avatar
  • 16.2k
8 votes
1 answer
2k views

Understanding line reference differences through :g/^/norm and through :%norm

Let's say that I have the following very simple file a b c d e and I've decided that I want to add empty lines after each line. Several different methods immediately jump to my mind. We might just ...
davidlowryduda's user avatar
8 votes
4 answers
10k views

How to delete a multi-line match?

For testing purposes I've opened the following file: vim http://example.com/ And I'm using the following command to delete a highlighted multi-line pattern: :/<body\_.\{-}body>/d which ...
kenorb's user avatar
  • 18.7k
6 votes
2 answers
185 views

Position command line under current window?

Sometimes I work with a vertically split window and I was thinking it would be cool if when I enter the command line with :, /, etc., the command I type would appear below the current window instead ...
Andy Schweig's user avatar
6 votes
1 answer
2k views

How to find what is causing the command line height to be changed after opening / closing a tab?

Sometimes (I can't reproduce it reliably), after opening a tab, the height of my command line becomes excessively big. When it begins, the buffer displayed in the first newly created tab has only 10 ...
saginaw's user avatar
  • 6,856
6 votes
1 answer
912 views

How to change the command line status message color and font?

I would like to change the color of part of the command line, the stuff that's echo'd from vim scripts. I know it can be different since when your search hits the bottom it prints a message in red ...
Thomas N's user avatar
6 votes
2 answers
414 views

Setting a default file extension

Can I tell vim to assume a filename ends in .tex if no extension is given? e.g. to open bird.tex if I say :e bird (unless there is a file bird with no extension).
Toothrot's user avatar
  • 3,139
5 votes
1 answer
115 views

Open command window dynamically

I am trying to use the command line window in a vimscript. Unfortunately, the experiment I have with is not good and I am not able to achieve the following: normal! q: This should open the command ...
nobe4's user avatar
  • 16.2k
5 votes
1 answer
363 views

Use shell variable substitution with current filepath

I want to be able to easily change the filename. This works: :! var=%; mv % ${var/.txt/.asc} But this doesn't: :! mv % ${%/.txt/.asc} My questions: Why doesn't this work? Doesn't VIM simply ...
Bart Louwers's user avatar
5 votes
2 answers
302 views

Preventing ex commands from altering the screen

Sometimes ex commands have the useless side effect of jumping, probably to the last place they affected. Can this be prevented? I would prefer it if ex commands left my screen exactly the same as ...
Toothrot's user avatar
  • 3,139
5 votes
4 answers
6k views

Insert blank line above and bellow a certain line

Without being in insert mode, from a certain line, I'd like to create a blank line above and below that line in staying on the same line. Could anyone have an idea how to do it? To clarify what I'm ...
user avatar
5 votes
1 answer
6k views

How to escape pipe character in `:make`, `:grep` and friends

I'm trying to use :grep to search for one of several words. Since grep accepts regular expressions, I figured I could just use the pipe character | to build a single expression for both words: :grep -...
wrtlprnft's user avatar
  • 173
4 votes
2 answers
3k views

Delete all of a file except for certain words that contain certain letters

I have a file that contains words that I want to save, along with other junk that I do not need. I just want to delete everything except the words that contain a certain pattern. Take email addresses ...
Questionmark's user avatar
4 votes
1 answer
2k views

Call vim command from shell, and suppress output while it operates

I'm setting up a vim environment install script. I'm using vim-plug for plugin management. What I'd like to do is, from the install.sh, run vim and call PlugInstall to trigger plugin download and ...
silico-biomancer's user avatar
4 votes
1 answer
471 views

How to check whether a command is run with range or not?

For example, I have the following code command! -range Test call TestFunc() function! TestFunc() abort " if run with range " get selected content " else " get current word under the ...
WW00WW's user avatar
  • 320
4 votes
0 answers
105 views

:tabonly does not close all unmodified tabs if there is a modified tab in the way

Create some test files, touch a b c d and open each in a tab, vim -p a b c d Modify file b. Go to tab c and issue :tabonly. Expected behavior: a and d tabs are closed. b is not closed because it is ...
Quasímodo's user avatar
  • 2,486
3 votes
1 answer
274 views

Use feedkeys then do command

I want to write a mapping that does feedkeys(":cd " . getcwd()), waits for me to edit the directory and then press enter, and then runs a command such as :Rg from the fzf plugin. I tried ...
rlms's user avatar
  • 305
3 votes
1 answer
210 views

multiple shell command execution failed

I want to execute two shell command at the same time in vim. So i use | like below :!ls|!pwd Its Returns the following error E34: No previous command But what happen ls output is forward to ...
SuperKrish's user avatar
2 votes
1 answer
928 views

How to print a multi-line match?

I've a file where I would like to extract a multiline pattern in non-greedy way (similar to this scenario) by using ex editor. This example works fine: $ ex +'/aa/,/cc/p' -scq! <(echo -e "start\...
kenorb's user avatar
  • 18.7k
1 vote
2 answers
206 views

Can I navigate backwards by word (not WORD) in command-line mode?

If I'm in command-line mode in vim, and I have the current command line entered (cursor position shown with |): :somecommand somefilename.txt| I'd like to navigate backwards so that the cursor is ...
Andrew Ferrier's user avatar