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
2
votes
2answers
467 views

Any recommendations to enforce use of keybindings rather than equivalent command mode commands?

Context: I learned about the :[v]split command long before I learned the shortcuts Ctrl-w+[s|v] and as a result I find myself typing these commands often. Is there a way to break this habit ? (as a ...
1
vote
2answers
225 views

Contextual text processing

I would classify my mathematics pdf collection in folders named by the MSC 2010 Classification (just the 2 top-level). My approach is creating a file which will contain all path and uses mkdir in a ...
7
votes
2answers
660 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,...
3
votes
1answer
470 views

I've just installed (g)Vim, how do I get arrow keys to access command history?

So the problem is that I've installed (g)Vim and the arrow keys are moving around rather than going through command history. It's a little complicated by the fact that there was an old version of vim ...
3
votes
2answers
616 views

The meaning of "= in Vim

I was solving a problem on Vimgolf (you can take a look at this) where I stumbled upon this solution. djgJ.V"=[<C-R><C-A>]<CR>pZZ Could you please walk me through the meaning of ...
1
vote
1answer
427 views

Checking if Makefile exists before executing autocmd

I want Vim to execute build the project automatically after I write the buffer to a *.c or *.cpp file. Here is what I've done: autocmd BufWritePost *.c,*.cpp make This one works as expected (but the ...
2
votes
2answers
854 views

cnoreabbrev do not expand abbreviations in command history

Is it possible to configure vim to store commands in your command history without abbreviations expanded? For instance I have the following command (to make it easy to switch back and forth between ...
0
votes
0answers
90 views

Is it possible to copy block (given by range) multiple times in a single command?

Is there a way to copy a few times a given block from command-line mode, e.g. with the :t command? For example, how to copy the two lines (block) above the cursor -2,-1 to the current position ., 3 ...
1
vote
2answers
404 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 ...
7
votes
1answer
567 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

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 ...
1
vote
2answers
731 views

How to add inline comment for the echo command?

I've tried the following syntax: :echo 123 " comment but it failed with E15 and E114 errors. Is there any way to put the inline comment right after the command, so it can be ignored?
3
votes
1answer
541 views

How to delete blocks of text which contain a specific string?

I have a file which has the following structure From: foo@example.org Subject: Bar Date: 2017-06-27 Mailbox: /some/dire/ctory <CR> Such a block always contains of four lines followed by an ...
2
votes
1answer
2k views

source the current file

I know that to source my current file I need to do this: :so ~/.vimrc But is it possible to source the current file without mentioning its name?
2
votes
1answer
439 views

Issue with using ex commands

I asked a question a few days ago in the Linux/Unix SE about how to copy a block of text from one file to another in a way that I could use for a script of many similar files. I thought I came up with ...
1
vote
0answers
418 views

How do I get vim to autocomplete correctly for :! on Windows?

On Vim 7.3 on Windows, if I use Tab to autocomplete paths with nonstandard characters in many cases, it works fine. For example: :n 2016\ Posts\\feb\something.txt If I press Tab after '2' and 'f' ...
4
votes
1answer
5k 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 -...
3
votes
0answers
609 views

Set maximum cmdheight

Is there a way to limit the command area in vim? When typing a long command, cmdheight is "temporarily increased", but I like to limit it to one line. What I currently have is illustrated on the ...
2
votes
1answer
148 views

Using the current file name (%) in command line mode when the file name contains spaces (or other special characters)

I cannot figure out the general rules for using % to substitute the current file name/path into a command line mode command. Here are examples. I create a file te st.txt, open it in vim and try to ...
2
votes
1answer
55 views

# turning to exe when running terminal command

First of, I am sure there are plugins that will do what I am trying to achieve but I am using this as an exercise to learn vim as I am still quite new so I am not really interested in plugin ...
0
votes
1answer
219 views

What does :[range]t <line-number> do?

I just started playing vimgolf and saw a solution that used this command to select a line and copy it to the line specified. I searched google and vim's documentation and couldn't find anything about ...
3
votes
3answers
116 views

remap ':' to maintain last command, and erase all char if any key other than <CR> was pressed

As the title stated, remap ':' to maintain last command, and erase all char if any key other than <CR> was pressed. possible use cases: I have typed a long command, and I may or may not ...
12
votes
2answers
691 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>...
2
votes
0answers
185 views

How can I view all of the vimscript run by a command? (neovim)

I want something similar to what I get when I enter debug mode and type "step", then enter and up, enter and up, ten thousand times... But without having to do all that work, allows it to be done ...
6
votes
1answer
2k views

Searching for text when launching Vim

I am writing a shell script to view a text file and search for a pattern. I want to specify this pattern in the command line when launching Vim. This command is what I am currently using do ...
1
vote
1answer
303 views

Pass word one-by-one and replace (Search and replace with confirmation) [duplicate]

I'd like to pass through a text an replace word1 by word2. However, I don't want to execute this task in one pass, but rather word by word. I know I could put the cursor on the word I want, execute *, ...
8
votes
1answer
8k 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 ...
3
votes
2answers
234 views

Undesired command line completion history

Starting vim (8.0) with an empty .vimrc, or as vim -u /dev/null. Executing: :set nocompatible :set wildmode=list On the screen: :e .config/█ I always thought that what happens when you press Tab ...
3
votes
1answer
283 views

What is the name of the line you enter commands on after hitting escape?

What is the name of the line you enter commands on after hitting escape? E.g. When you hit escape and start typing a colon command you are typing in/on the _____ .
1
vote
1answer
586 views

Get list of files using glob in command mode

With the following command, I'd like to glob for all .cpp files so that I can compile and run simple programs: autocmd FileType cpp nnoremap <buffer><silent><localleader>cr :execute ...
10
votes
1answer
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 ...
6
votes
3answers
573 views

Is it possible to execute a Normal mode command only on the first/last line of a range?

I want to comment out a piece of code. For instance this snippet: foo bar foo Should become this: <!--foo bar foo--> So I type the following sequence: vap:norm '<i<!--<C-v><...
2
votes
1answer
151 views

Make colon appear even though you execute a silent command

I have this remap in my vimrc which makes the cooperation between vim and bash a lot easier: function! LoadRegisters() let $y = @0 let $r = @" endfunction nnoremap <silent> : :call ...
8
votes
3answers
10k views

How do I run Homebrew vi on macOS instead of the older version Apple provided?

I have recently upgraded to Vim 8 using Homebrew, but my vi commands still load the OS-provided version 7.4 of Vim. I could add an alias to vi, but is there another way?
5
votes
1answer
249 views

Change command-line prompt leading character?

Reason: I've swapped my semi-colon and colon commands so that entering the command-line takes one less key-stroke: nnoremap ; : nnoremap : ; vnoremap ; : vnoremap : ; nnoremap q; q: But in the ...
1
vote
1answer
67 views

Vimception: Why does reading the output of executing the current file cause recursion?

Preface: I first encountered this with a Node.js script I was trying to simulate a REPL with. I cooked up this demo to prove that is also happens with bash. Please explain: Why is it that on ...
5
votes
4answers
2k 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 ...
5
votes
1answer
2k views

Search and replace, special pattern for indent (ex: newline = '\r')

I am cleaning up some minified css. I found this article helpful for adding a newline before/after a search match. This SO thread has a pretty exhaustive list of ways to indent with VIM, but it DOES ...
1
vote
1answer
316 views

How to read/get the number of lines of code in the buffer or a directory?

We can read some information about the current buffer, by hitting g C-g; for example: Col 3 of 2; Line 28 of 106; Word 144 of 474; Byte 916 of 3396 And we can capture the same information in a ...
1
vote
2answers
116 views

Current line after :3,7call XYZ()

Executing:3,7y does not change the line which contains the cursor (line('.')). This is what I expected. However, when I execute :3,7call XYZ(), the current line goes to the third line. I didn't ...
3
votes
1answer
74 views

How can I write a range to a command, and then read the resulting output?

I have an SQL file that I have to work on from the command line. -- Query 1 select 1; -- Query 2 select * from metadata; I've marked line 4 as a (4Gma) and line 5 as b (5Gmb), then execute :'a,'b w !...
1
vote
1answer
47 views

Is there a default binding to go into command-line mode and append a '!'?

Of course, I could make a mapping, but I was wondering if there's a default binding.
2
votes
2answers
1k views

How to customize % symbol in makeprg command

When I set makeprg using: set makeprg=gcc\ -Wall\ -g\ %\ -o\ % and then invoke :make Vim does not pass proper filenames, because this command is translated as: gcc -Wall -g file.c -o file.c and ...
4
votes
1answer
277 views

Strange behavior with "map(range ...)"

I'm trying to get into more advanced features of vimscript, so I'm trying to figure out how to use the map function, so I thought I'd write a function that returns every character with ASCII values ...
31
votes
2answers
18k 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 ...
0
votes
1answer
91 views

Tcsh-like history scrolling for commands?

In the command minibuffer (Pardon my emacs, I don't know what it's actually called), C-p and C-n go to the previous and next command in my history. Is there a way to make them behave like M-n and M-p ...
3
votes
1answer
123 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 ...
0
votes
0answers
41 views

Color line numbers part pitch black regardless of color scheme? [duplicate]

I have tried this: :highlight LineNr ctermbg=black but the problem is that apparently the color scheme I am using has changed the definition of "black", so instead of being black the gutter is now ...
5
votes
2answers
5k views

What does :%! mean? [duplicate]

I saw an editor command which started like this: :%! sort What does that mean? Specifically, the :%!.
0
votes
1answer
693 views

Copy a file from an archive

I recently discovered that vim can open archives like .zip or tar.gz and list all files in them. We can even open the files in vim by pressing enter on a filename we want. But I want to extract some ...

1
4
5
6 7 8