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.
464
questions
137
votes
8
answers
194k
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.
98
votes
2
answers
68k
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 ...
83
votes
1
answer
36k
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
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 ...
54
votes
5
answers
25k
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.
36
votes
3
answers
79k
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 ...
35
votes
4
answers
44k
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 ...
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 ...
32
votes
7
answers
25k
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 ...
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-...
28
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 ...
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/...
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 ...
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 ...
20
votes
3
answers
447
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 ...
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 ...
20
votes
4
answers
3k
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 ...
18
votes
1
answer
31k
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,...
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 ...
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 ...
15
votes
4
answers
31k
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?
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 ...
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 *....
14
votes
2
answers
904
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>...
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&...
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 ...
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 ...
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-...
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: :...
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' ...
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 /...
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 ...
11
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 :...
11
votes
6
answers
30k
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 ...
11
votes
3
answers
191
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 ...
11
votes
1
answer
396
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 ...
10
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:
...
10
votes
3
answers
865
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....
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 ...
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, ...
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 ...
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 ~/...
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?
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 ...
10
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 ...
10
votes
2
answers
764
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 ...
9
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 ...
9
votes
1
answer
452
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?
...
9
votes
1
answer
472
views
Is there a way to write out the results of ":ls" to a file?
I have a bunch of splits up right now, and it took me a while to find these files (basically I'm chasing down a bug through 50 interconnected files).
Is there a command like :ls > /tmp/filelist ...
9
votes
2
answers
894
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,...