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
0
votes
1
answer
640
views
Delete N lines after cursor that contain a specific pattern
It is possible to delete all lines matching a pattern using :g/pattern/d.
Using the following command, you can replace words matching a pattern, 20 lines after where the cursor currently is: :s/...
0
votes
1
answer
241
views
Tab to view files in directly?
Is it possible to press tab or some other operator to view the available files in a given directory path? For example:
For example, in the unix shell I can do something like [tab] to get:
After ...
0
votes
2
answers
81
views
Define a new ex command active only in specific filetype (C++)
I would like to define a new command for C++ files/buffers (ft=cpp).
I shall explain the requirements through the example below. The newly defined command :stripdbg should strip the surrounding dbg() ...
6
votes
1
answer
737
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 ...
1
vote
0
answers
45
views
Command (e.g. `g++`) does not point to the same binary when run from the terminal or from (neo)vim
I have NVIM v0.4.3 on macOS Mojave version 10.14.6
I have different version of g++ compilers on my machine and made the following alias in my .zshrc file:
alias g++="/usr/local/bin/g++-9"
...
1
vote
1
answer
213
views
Prevent commands from populating command-line history
I would like some commands to not be registered in the cmdline history. Is there a way to do this? I can't seem to find anything about it in the doc.
The story: I accidentally deleted a file with :...
0
votes
1
answer
323
views
How can I set a variable for a single Vim Ex command only?
I often set or modify a shell variable in Bash for the scope of a single command only:
$ FOO=BAR <command>
Is it possible to set or modify a variable in Vim for the scope of a single Ex ...
0
votes
2
answers
1k
views
How can I exit Bash from Vim?
Can Vim kill its parent process?
I know a child could not kill a parent process in Linux, but how can I achieve :!exit in Vim?
I would like to exit directly from Vim out of the terminal without semi-...
0
votes
1
answer
194
views
prevent printing control-character in insert mode and command line
When in insert mode, if no mapping is associated to a sequence, Vim will print the character corresponding to the signal.
For example, typing <c-b> will input ^b as a character.
It is more ...
1
vote
1
answer
489
views
Autocomplete on command-line search pattern returns strange symbols of <09> and ^I
Using Neovim v0.4.3 on a just recently upgraded Linux Mint 19.3.
Problem Description:
After the upgrade, when typing / followed by first characters of any word below the cursor, in the buffer, and ...
2
votes
1
answer
2k
views
How to paste command into vim command line easily
I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1.
To paste onto the vim command line I am using
: ctrl+r "
to paste the " register
Is there an ...
3
votes
3
answers
3k
views
How to run multiple commands in command line, & place 1 comma at the end of each line and join all the lines
I am using latest available version of NeoVim v0.4.3 and latest Arch build with kernel 5.6.4-arch1-1.
I'm having a problem with the following command in the NeoVim command line:
1 ...
2
votes
1
answer
138
views
Having current filename in the command line
Some time ago I completely got rid of the status line. Vertical space is a scarcity in the modern HD world. The only thing I missed from it is an ability to see what file I'm working with. So I'm ...
1
vote
3
answers
765
views
How to go to the beginning of a command
If I am editing a command, for example:
:set paste
And my cursor is between the p and a:
:set pa|ste
I can go to the end of the command text by doing ctrl-e. However it doesn't seem like ctrl-a ...
2
votes
2
answers
2k
views
FZF showing error on preview
I have fuzzy file finder (FZF) set up and working:
And when I do :History it also shows a preview of the file:
I've been able to do a find with passing an "empty" preview to it:
:FZF --preview 'cat'...
2
votes
0
answers
32
views
Chaining user-defined commands [duplicate]
Assuming I have defined 2 commands in .vimrc
MultipleEmptyLinesToOne
RemoveExcessiveSpaces
I can run them in command-line mode:
:exec "'<,'>MultipleEmptyLinesToOne" | exec "'<,'>...
0
votes
1
answer
2k
views
g! vs v in vim command
Is there any difference between doing the following two commands:
:1,19g!/let/d
And:
:1,19v/let/d
Or is v an alias for g! ?
0
votes
1
answer
95
views
How to always show a command
When I enter a search it shows me the input in the command bar, for example:
However, when I enter in a command from the command history, for example clicking enter on line 50:
It doesn't shown ...
4
votes
1
answer
408
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 ...
1
vote
0
answers
110
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 ...
5
votes
1
answer
2k
views
How do I run a shell command using the current selection as arguments?
An example:
A visual selection of:
echo -e "hello
\bworld"
followed by :w !bash prints:
hello
world
How can I get the same result if my starting point is:
hello
\bworld
More details:
I ...
1
vote
1
answer
36
views
Why does `.,.+[count]` appear in command box when typing [count+1] before :
For example if in normal mode 4: is pressed, in the command line there will be :.,.+3. What does this mean and what is it used for?
1
vote
1
answer
2k
views
Commands to write text to a buffer
I'm writing a plugin that often needs to write text to specific buffers.
My current solution is to make the script execute normal commands that open a split with the buffer, write the text and then ...
1
vote
0
answers
40
views
Why is the command line not like a mini buffer in normal mode? [closed]
When typing in the command line, and one wishes to make a correction, I am aware one can press ^f to bring up a cmdline mini buffer where one can use normal and insert mode.
But this make me wonder, ...
1
vote
2
answers
84
views
`a` append to buffer commands
Similar question, yet not duplicate of: How can I reload all buffers at once?
If :wa writes all, would not :ea be expected to reload all?
How could one script :ea to behave this way?
What are the ...
5
votes
3
answers
543
views
How do I use the contents of the buffer to save some typing/autocomplete on the command line?
When editing a buffer and initiating a search-and-replace, I use :s/oldword/newword/g
Now the word 'oldword' will be in the buffer I am editing, and sometimes it is a long word.
It would be helpful ...
2
votes
1
answer
56
views
Difficulty with regular expressions
I'm trying to wrap my head around this line of code:
:execute "normal! gg/for .\\+ in .\\+:\<cr>"
I understand that it's executing in normal mode (ignoring remappings) the command that starts ...
4
votes
1
answer
2k
views
Problem remapping key bindings in command line mode
To make it easier to edit my ~/.vimrc file, I set up the following:
:cnoremap ev :<C-u>vsplit $MYVIMRC<cr>
So, to open ~/.vimrc in a split I just enter command mode and enter ev. However,...
1
vote
1
answer
60
views
Are there comments in command-line mode?
Does VIM support comments in command-line mode?
I have tried the most popular variants including .VIMRC comments but neither worked:
:echo "hello" // echo usage
:echo "hello" /* echo usage */
:echo "...
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' ...
4
votes
1
answer
697
views
Open command-line-mode from VimScript function
How to reproduce this mapping:
nnoremap <Leader>a :DoSomething <C-r>=do_something_arguments()<CR>
..in a function?
The desired effect is to open command-line mode with some text ...
1
vote
1
answer
82
views
Showing external command output only if not empty
Is it possible to silently run an external command, but show the output on the prompt only if there was any?
3
votes
2
answers
3k
views
What is the difference between normal mode and command line mode?
Normal mode is also called command mode, and is different from command line mode.
It seems both can be used for : commands, but what is the difference?
8
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 ...
2
votes
3
answers
221
views
How can I prevent Vim from centering the line under the cursor on `:edit`
Each time I want to save my work while editing a text file, I enter :write to save the file, and :edit to reload the file, with the side effect of resetting the undo/redo buffer.
However, an unwanted ...
0
votes
1
answer
124
views
Wildmenu for command line history
While there is <up> and <down> that tries to complete the line, sometimes one wants to recall all the commands that start with what was typed, on a (wild)menu.
Is this possible somehow?
1
vote
1
answer
2k
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 ...
0
votes
1
answer
462
views
I want to save my typescript file, and immediately run tsc myfile.ts from inside vim. What is the best way to accomplish this?
I am building a daemon, and nodemon currently monitors a file called server.js, which is compiled from the file I am working on, server.ts
In order to compile server.ts, after saving with :w, I need ...
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: :...
3
votes
1
answer
317
views
search for pattern and insert text that precedes the pattern from pattern1 to pattern2 exclusive
basically I have a bunch of lines of code that all match the format .\module.variable (),
.\module.variable2 (),
I want to take everything between the backslash and the space, before the parentheses ...
1
vote
3
answers
12k
views
How to restart vim from within vim?
Here's how I restart vim:
$ vim
:q
$ vim
Is there a way to restart vim so that there is no need to type the second vim in the shell?
6
votes
1
answer
2k
views
How to show completion menu when typing EX-command?
When I use MS Windows version gvim, when typing EX-command, I can press TAB then there will show a completion candidates menu.
For example, if I type :colorscheme then a space then press TAB, gvim ...
7
votes
1
answer
3k
views
How to get the names of all open buffers?
I can use % to get the name of the focused window for commands. How can I get a space-separated list of all buffers for use in a command?
For example, I would like to call
:!cat [all]
where [all] ...
2
votes
2
answers
85
views
How to open one file as "read only" but the others as writable using command line?
Here is what I am doing now:
vim + $1 -c "set titlestring=$title guioptions-=m guioptions-=r lines=66 columns=239" -c ":source .vim_map" -c "sp .help.txt" -c ":wincmd j"
I would like to open the ....
2
votes
3
answers
2k
views
How to repeat the last : command for a visual selection instead of whole buffer?
Say I've done the command:
:g/^.\{1,50\}$/m$
To move all lines with 50 or less characters to the bottom of the file.
Then I realise I actually didn't want to do that for the whole file, but for ...
3
votes
4
answers
3k
views
How to change word under cursor to upper case in command mode with shortcut?
I want to set up a shortcut to make word under the cursor upper case in the command mode. I know that you can get the word under the cursor with expand("<cword>"). But I am not sure how do I ...
0
votes
1
answer
2k
views
Changing PYTHONPATH from inside VIM
Today I was writing code in VIM and wanted to change the PYTHONPATH and so I ran:
:!echo $PYTHONPATH;export PYTHONPATH="/home/oli/git/published_libraries/computer_communication_framework";echo $...
1
vote
1
answer
509
views
Line mode command to delete from column X to end of line?
Using gvim on a file with 30K lines, I want to use ex mode to delete from column 130 to end of line, making each record no longer than 130 characters.
I want to do this for the entire file.
My macro ...
1
vote
1
answer
182
views
Is there a way to enter command line mode for a single command directly from insert mode?
I'd like to go directly into command line mode from insert mode, enter a single command (say :r !date which inserts the date) and then go immediately back into insert mode.
Basically something ...
1
vote
1
answer
154
views
Print Command Without Hitting Enter
Suppose I map a key to enter a command in the command buffer, but without hitting enter:
function! BuildSystemTask()
if inProject() "generic function that checks if I am in a buildable project
...