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
8
votes
1answer
540 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: :...
25
votes
1answer
9k 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 ...
62
votes
1answer
21k 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
32
votes
5answers
9k 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.
18
votes
3answers
364 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 ...
15
votes
3answers
11k 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 ...
17
votes
3answers
2k 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 ...
75
votes
2answers
45k 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 ...
26
votes
2answers
3k 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 ...
10
votes
2answers
3k 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 ...
9
votes
2answers
620 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 ...
10
votes
4answers
676 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 ...
7
votes
2answers
921 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 ...
3
votes
1answer
964 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 ...
1
vote
1answer
165 views

Is it possible to have vim run a command every time save `:w` is invoked?

I am editting typescript now, and I'd like to be able to have it so, whenever :w is invoked, the shell runs tsc compiling my new save. This beats having to !tsc every time. Does something like this ...
9
votes
1answer
20k 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,...
15
votes
1answer
851 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 ...
13
votes
2answers
1k 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&...
8
votes
1answer
6k 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 ...
16
votes
1answer
1k 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 ...
7
votes
2answers
470 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,...
7
votes
3answers
7k 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 ...
6
votes
3answers
2k 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 ...
4
votes
1answer
55 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 ...
19
votes
4answers
5k 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/...
9
votes
1answer
441 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? ...
8
votes
1answer
1k 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 ...
5
votes
2answers
238 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 ...
5
votes
2answers
221 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).
5
votes
1answer
403 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: ...
3
votes
3answers
2k 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 ...
3
votes
4answers
1k 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 ...
3
votes
1answer
656 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 ...
3
votes
1answer
262 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; ...
2
votes
1answer
311 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\...
1
vote
0answers
28 views

Why does Gvim treat ansi escape codes differently than Vim in python code?

The following python code uses ansi escape sequences to clear the terminal screen and change the text color to red. It then prints "Hello from Vim." print ('\033c\033[31m Hello from Vim.') In Vim I ...
1
vote
1answer
984 views

How to paste a text block in visual block mode?

I want to paste text which spans across multiple lines and is rectangular. For example, a rectangular box representing a device topology diagram. +-------+ | | | | ...
1
vote
2answers
300 views

User command with modified 'path' completion?

I'm trying to write a wrapper command around :edit or :find specifically to open either my vimrc or a subpath of ~/.vim/ (e.g. ~.vim/autoloads/foo.vim). If I run the command with no arguments, it ...
0
votes
2answers
102 views

Using -c command line option for Vim 7.4 on Windows produces errors

The following commands work fine when I issue them from the command mode in Vim: :%s/\(^\s\+\)\(\S\+.*)\s*\){$/\1\2\r\1{/g :g/^\s*\/\/$/d But when I run the above commands as a script as below: ...
0
votes
1answer
15 views

Changing cpoptions only work in commandline

So i tried to change the setting from cpoptions, so i did: set cpoptions=aABceF on the commandline, where s for the star is missing (on purpose) and it seems to work fine but only if i do it in the ...
0
votes
1answer
815 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 --...
0
votes
0answers
35 views

How to show “/foobar match 1 of ” or “E486: Pattern not found: foobar” in commandline when calling `normal! n` in function [duplicate]

I'm calling normal! n in a vimscript function. If there is a match, I don't get the message /foobar match 1 of 3 in the commandline. If there is no match, my commandline shortly flickers up and down ...
0
votes
1answer
109 views

May I have a Vim session report its “Mode” in its “Window Title”?

Clarification of the moving parts First, let me clarify what I mean by "Window Title", and what I expect to achieve On Windows OS, GUI programs will have three attributes: its Window Title texts, ...
0
votes
1answer
936 views

Changing the vim color scheme only highlights lines of text?

I'm a big noob to vim here. I was trying to change the colorscheme of vim by editing the .vimrc file, but as I was playing around with different color schemes (ayu and gruvbox, for example) I noticed ...
0
votes
1answer
301 views

Sharing vim commands history across different users and computers

I have configured .dotfiles. Eg. see here https://wiki.archlinux.org/index.php/Dotfiles So now I can do dgit push or dgit pull on whichever computer I want, and I have all my config files (including ....