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
138 votes
8 answers
202k views

How can I easily move a line?

What is the command (or shortcut) to move a line up or down in vim? My current workflow is to yank (copy) the line and than delete that line and than to put (paste) that line.
Vader's user avatar
  • 1,635
99 votes
2 answers
69k 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
83 votes
1 answer
37k 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.3k
59 votes
2 answers
18k views

Close all split files, except the one currently focused?

Sometimes when I'm working on a file, I'll open up multiple files just to get an idea of the current flow of the code up to a point. However this sometimes leads to multiple files being open at a time ...
Dom's user avatar
  • 3,284
55 votes
5 answers
26k 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
35 votes
3 answers
80k views

How do I stop recording while in command line?

When I am recording a macro with q and I am done, I can type: q to stop recording if I am in normal or visual mode. <c-o>q to stop recording if I am in insert mode. .. How do I stop recording ...
iago-lito's user avatar
  • 1,112
35 votes
4 answers
47k views

When to use :grep and :vimgrep in vim?

In vim :make makes it easy to build and fix errors, and :grep and :vimgrep behaves like :make. But why do you need these two commands? Why not just search for the pattern and just press n? What are ...
Qian's user avatar
  • 453
34 votes
2 answers
21k 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,107
32 votes
8 answers
27k 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
  • 813
30 votes
7 answers
15k views

Easiest way to switch git branches

Right now I'm using fugitive to manage almost everything git related, but I can't find a good workflow to quickly visualize and switch between available branches. I can do :Git checkout <branch-...
Sergio D. Márquez's user avatar
29 votes
1 answer
14k 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.3k
27 votes
4 answers
11k 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.3k
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,757
20 votes
3 answers
5k views

How do I use relative line numbers in command line mode?

Recently I learned from Practical Vim a way to copy or move block of lines without having to move the cursor from the current position. This is done in command line mode. e.g. :123,133m. # moves ...
rpattabi's user avatar
  • 303
20 votes
3 answers
453 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
18k 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
18 votes
1 answer
32k 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,522
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,489
15 votes
4 answers
32k views

How to split a line into multiple lines efficiently?

I've been receiving logged data in a text file that is just one long line with each value separated by a space. Is there a command or set of commands that will split one line into multiple lines?
Dom's user avatar
  • 3,284
15 votes
1 answer
3k views

What is the difference between :quit and :close commands?

In vim docs, the description is very similar: Quit: :q[uit] :{count}q[uit] CTRL-W q *CTRL-W_q* CTRL-W CTRL-Q *CTRL-W_CTRL-Q* Without {count}: Quit ...
Neith's user avatar
  • 253
15 votes
1 answer
2k views

How to use backtick-expansion to populate the arglist?

From help :help backtick-expansion: On Unix and a few other systems you can also use backticks for the file name argument, for example: :next `find . -name ver\\*.c -print` :view `ls -t *....
saginaw's user avatar
  • 6,736
14 votes
2 answers
930 views

Can I search through 'oldfiles' with a specific name or extension?

I use the oldfiles and browse oldfiles commands all the time. I find them extremely useful, because it's easier to hit my leader mapping, scan through the files really quickly, and hit q<number>...
DJMcMayhem's user avatar
  • 17.5k
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
13 votes
7 answers
9k views

How to search for lines matching current line in vim

I usually search for words by :/string, but if I have to search entire current line, how to do that. event: 1 beacon: 0x02 //line 1 event: 19 beacon: 0x02 //line 2 event: 1 ...
manav m-n's user avatar
  • 155
13 votes
2 answers
3k views

How to work with command-line mode the vi way?

Is there a way to interact with the command-line mode while always remaining in the home position? In particular, the following two actions are cumbersome, requiring moving the fingers away to the ...
Shahbaz's user avatar
  • 549
12 votes
2 answers
6k views

How do I insert the output of an external command at the cursor position?

When we execute any system command and get the output, it prints in next line. But I want it in current line, next to the cursor or in place of cursor (not at the start of the current line) Example: ...
SibiCoder's user avatar
  • 3,352
12 votes
3 answers
5k views

Make Command-line mode type <Esc> and Ctrl commands

Imagine you want to quote the word below. If | is the cursor position you can easily quote the word with cw""<Esc>P from Normal mode. |below I want to achieve the same behaviour in Command-...
Gonçalo Ribeiro's user avatar
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
  • 25.8k
12 votes
2 answers
4k views

How to avoid to press ENTER twice, when compiling with :make inside Vim?

I love to use Vim as simple IDE when compiling C/C++ programs (let say with gcc on a Linux terminal), just inside Vim with command: :w | make | cw In that way: the :w vim command save editing the :...
Giorgio Robino's user avatar
12 votes
1 answer
2k views

Switching arrow key mappings for wildmenu tab completion

When wanting to edit another file, I'm a big fan of typing :e then tab (or a few characters before) to see the wildmenu pop up. Problem is that the way it works, arrows keys up and down go 'down' ...
Delhirio's user avatar
  • 123
12 votes
2 answers
2k views

Zsh-like tab completion of partial paths

Related to Bash-like partial tab-complete for filenames in Vim One of the truly fantastic features of zsh is that you can type, for example, ls /u/s/m/m/who.1, press Tab and have it complete to ls /...
muru's user avatar
  • 24.8k
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
11 votes
6 answers
31k views

How do I copy and paste between two Vim instances - shared clipboard?

I use gnu screen and I run vim file1.txt and vim file2.txt in two windows. How can I copy part of the text from file1.txt and paste it to file2.txt without using temporary files or opening two files ...
name's user avatar
  • 965
11 votes
1 answer
3k views

Open file and scroll to bottom command line param?

I'm new to vim. I want to open vim from command line and have it scroll to the bottom of a file automatically. The use case is opening logs. Typically I open vim "vim log" and then scroll down ...
Leo Ufimtsev's user avatar
11 votes
3 answers
200 views

Auto completion for option values on the cmdline

I cannot count the number of times I have tried to do this: :set foldmethod=syn^I It seems that completion doesn't work on option values! In some cases options are complex strings where completion ...
joeytwiddle's user avatar
  • 3,612
11 votes
1 answer
410 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
10 votes
3 answers
12k 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
10 votes
2 answers
7k views

What does :%! mean? [duplicate]

I saw an editor command which started like this: :%! sort What does that mean? Specifically, the :%!.
minseong's user avatar
  • 2,291
10 votes
3 answers
882 views

How to output highlighted source code into a file to use outside vim

At my workplace, I want to do a presentation of a custom language I've developed for solving some problems we had. For easier development, I created my own vim syntax file for this particular language....
DainDwarf's user avatar
  • 203
10 votes
3 answers
5k views

How can I start vim and then execute a particular command that includes a \, from the command line?

In my ~/.vimrc, I have a command defined approximately like this: nnoremap <expr> <Leader>n ':new ~/Notes/' . strftime('%F') . '-' It is designed for creating notes files that contain ...
Andrew Ferrier's user avatar
10 votes
1 answer
2k views

How to substitute in multiple lines?

I'd like to insert a word in multiple lines, is there any command like :[2,3,5,7,11]s/^/word\ /g which would insert word at the beginning of line 2, line 3, line 5, line 7 and line 11? Here, ...
user3813057's user avatar
  • 1,451
10 votes
2 answers
4k 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.3k
10 votes
4 answers
1k views

Can I use "gf" (or similar) to open a file and jump to a search term?

Is there a way to get vim's gf command (or something similar) to recognize a +{cmd} argument for file-paths? One can start vim and go directly to a search term by doing: $ vim +/coding_effort ~/...
Oliver Taylor's user avatar
10 votes
2 answers
2k views

:silent makes my vim go blank

When I used :silent to run a terminal command in the background, my vim screen goes blank, until I navigate through my code, at which point each line I move to reappears. What gives?
Costa Michailidis's user avatar
10 votes
1 answer
4k views

selecting a range of lines from command line

I need to (visual) select a range of lines from command line. For example the following command :?^\s*for?+,/^\s*end/- p prints all lines contained between a for and end (exclusive way). Instead of ...
nicmus's user avatar
  • 365
10 votes
2 answers
788 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
9 votes
2 answers
6k 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
9 votes
1 answer
456 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
  • 16k

1
2 3 4 5
10