Is there a way to remove the last empty line in vim? I mean the line at the bottom of the window, below the line in which I type the command with the colon symbol (see the image Line2Remove).
Type the following command, and check what it returns:
:set cmdheight
If it's greater than 1, set it to 1:
:set cmdheight=1
Related
I wanted to paste the yanked line in the vim command prompt after typing certain command.
I saw a solution where they asked to enter <Ctrl-R><Shift-"> to paste the yanked lines in the vim command prompt, however I am having the following problems:
When I try like, :tabnew and then type <Ctrl-R><Shift-">, whatever yanked line gets pasted after :tabnew line.
Eg: :tabnew /disk/bin/hello.log
The above solution doesn't work if I map the same above command in the vimrc. I tried adding the following map in my .vimrc:
:map <S-P> :<C-R><S-">
When I try :tabnew and type <S-P>, it is not pasting the yanked line, i.e. the mapped command is not working.
Can anyone help me on the above scenario?
FOLLOW-UP QUERY:
Is it possible to mix normal mode and command line mode operations?
For Eg:
a. I have a line in text file which is a directory path and wanted to open that directory in vim.
b. Instead of doing Yanking [S-Y] the line and then doing mapped command [map <C-T><C-O> :tabnew <C-R><S-"><bs><CR>] to open the directory for vim, is it possible to do something as given below ?
nnoremap <F7> <S-Y>cnoremap:tabnew <C-R><S-"><bs><CR>
Please drop you comments/suggestions?
The : command line prompt is "Command-line-mode" (see :h Command-line-mode, :h cmdline, or :h : [all show the same help]). You can map keys in that mode using :cnoremap. So you seem to be looking for this:
:cnoremap <s-p> <c-r>"<bs>
The backspace at the end removes the trailing end-of-line character that is (probably) at the end of the buffer.
I very strongly suggest you use a different mapping than <s-p>, because that will be triggered every time you try to type a capital "P".
I have gVim 8.0.69 installed on my Windows 10 system along with Cygwin. I'm using the same .vimrc for both to keep them in sync. Some settings don't apply to both, so I'm using some conditional expressions in my .vimrc to selectively apply settings:
if !(has("gui_running"))
if version >= 747
" line 199 is the next line
set listchars=eol:-|,tab:>_,trail:~,extends:>,precedes:<,space:_
else
set listchars=eol:-|,tab:>_,trail:~,extends:>,precedes:<,
endif
endif
gVim is reporting the following error when I start it:
Error detected while processing C:\Users\<user name>\.vimrc:
line 199:
E488: Trailing characters: ,tab:>_,trail:~,extends:>,precedes:<,space:_
The line number refers to the first set listchars command.
Executing :echo !(has("gui_running")) in the gVim window reports 0, and :echo has("gui_running") returns 1, so I know the conditional is evaluating correctly after the program has started
Why is this line even being executed?
The problem doesn't come only from the | character but it comes mainly from the number of characters entered to the string setting eol.
From :help listchars it says:
*lcs-eol*
eol:c Character to show at the end of each line. When
omitted, there is no extra character at the end
It means that eol at most needs 1 single character but you gave it two : - and |.
If you still want to list eol by | you need to escape it so it will not be interpreted as a pipe.
The exact set cmd would be in that case:
set listchars=eol:\|,tab:>_,trail:~,extends:>,precedes:<,space:_
I don't know for sure, but vim still has to scan the commands to find the corresponding else or endif.
You have a | in there; | is a command separator. You could have written
if ...
set foo=bar|endif
so vim has to look at the part after the pipe to see what command it is.
I think you need to escape the pipe with set listchars=eol:-\|,tab:>_,....
I have a file edited in Vim with many lines. There is a specific line that contains a shell command, which I want to run.
How can I do this through Vim?
You can use this map:
:nmap ^ GI:!^V^[yy#"Xx
(Pick your favorite key command you don't use in place of ^ for the mapping;I like ^ because I always use 0 for its default function. Enter the ^V^[ with control-V control-V control-V Esc)
Then you can type 4^ to execute line 4, or just ^ to execute the last line in the file.
try Use
:exec '!'.getline('.')
This is like to copy the current line and run it.
You can also map this command to
map <F12> :exec '!'.getline('.')
getline receives the number of the line. if you will write 4 it will the line 4. The "." it run the current line.
so for run the command in line 4 you can write.
:exec '!'.getline(4)
When I try to execute my script I got ^M is an invalid character but in Vim, I see $ upon entering :set list
I tried :%s/^V^M//g but it says ^M pattern is not found
I guessed this occurred because I used some .vimrc I found here which converts the end of line characters to $
Without figuring this out, my only option would be retyping my script.
It looks like your script consistently has ^M line endings, and therefore got detected as fileformat=dos. :setlocal fileformat? will tell you.
To convert this file to Unix (LF) line endings, just :setlocal fileformat=unix and :write, or combine this in :w ++ff=unix.
If you never want Vim to detect such files (and show the ^M instead), put :set fileformats-=dos into your ~/.vimrc (or edit an existing config).
se nolist and the dollar signs will disappear.
No matter the OS, you always have line endings in your text.
Line endings are whitespace and always present, but usually just not shown.
Are you using Windows or *nix?
in windows, you can replace ^M as ctlr-q ctrl-m to input the ^M. In *nix, you can just use dos2unix to translate your script file to unix format.
If after opening your file you don’t see ^M at the end of line, but when you try sourcing it vim does show complains about ^M in various places the only thing you need to do is w ++ff=unix and reopen this file.
When you open a file vim detects line ending format. Thus trying to substitute ^M will not work: all detected line endings are converted into internal string end. E.g. when file format is dos like in your case it looks like
set nocompatible\r\nset ignorecase\r\n...
(where \r is carriage return, sometimes represented as ^M, and \n is line feed character, and \r\n sequence is dos line ending). When file format is unix it looks like
set nocompatible\nset ignorecase\n...
. For mac it looks like
set nocompatible\rset ignorecase\r...
. But if vim correctly detected line ending all these files transform into
"set nocompatible"
"set ignorecase"
"..."
C strings in internal structure representing buffer, each string represents one line. No \r and no \n are there.
When you do :w files are converted back into a sequence of bytes. :w ++ff=unix forces line endings. Reopening is needed because fileformat setting is not changed in this case thus next w without ++ff will save with dos line endings again. When you reopen line endings are redetected and fileformat setting is reassigned. You can do :set fileformat=unix manually after :w ++ff=unix, but :e is much faster to type.
In VIM in command line mode a "%" denotes the current file, "cword" denotes the current word under the cursor. I want to create a shortcut where I need the current line number. What is the symbol which denotes this?
. (dot) stands for the current line.
To clarify:
This is meant for stuff like :1,.s/foo/bar/g which will transform every foo to bar from the beginning of the file up to the current line.
I don't know know of a way to get the current line number expanded for a shell command, which is what you are trying to do by doing :!echo .
You can find out about the expansions that are done (like % and # for example) in :he cmdline-special.
If you want to pass the current line number to a shell command, you could do
:exe "!echo " . line(".")
To return the line number of current line at bottom of screen, use:
:.=
Commands in vim works on the current line so:
:s/foo/bar/g
will transform every foo in bar on the line you are currently on.