tabnew is not working in Gvim - vim

I have opened a file in gvim.
When I want to open another file in gvim , I use following command.
:tabnew `pwd`
and then press tab button.
But tab is not expanding pwd instead it is adding `^I
:tabnew `pwd`^I^I^I
Earlier it was working.
`pwd` is nor expanding in gvim whether I use it with tabnew or sp.

Check the compatible option in your vim session by typing in command line :set compatible?
If the result is:
compatible : you need to type ctrl+e
nocompatible : you need to type tab or ctrl+i
in order to get the expansion in command line.
For more about that: :help cmdline-completion

Related

How to paste the Yanked lines in vim command line after typing other command?

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".

vim autocomplete directory name

When I'm using filename autocompletion in command-line mode, how do I do select the current option to autocomplete?
For example, let's say I want to open the file ~/dev/myproject/foo.c
I start by typing:
:e ~/dtab
And I hit tab a couple of times until I see
:e ~/dev/
What do I press next to get vim to autocomplete the directories within ~/dev/?
If I hit enter, vim will open a buffer with the directory listing, which is not what I want.
I can hit / and then tab, but then I get an innocuous but aesthetically displeasing double-slash in my path:
:e ~/dev//tab
I can also hit "m", and then tab, which will work:
:e ~/dev/mtab
But what if I didn't remember that the next directory started with "m"?
How do I tell vim in the above example that "dev" is the autocomplete option that I want, and then to continue to do autocompletion for the next part of the path?
:h wildmenu
<Down> - in filename/menu name completion: move into a subdirectory or submenu.

Vifm. Edit file in opened gvim

I use Gvim to write code. And use vifm to make file management ( copy, move files, extract tar's ). Sometimes, when navigating in vifm i need to open some file to edit him. Using :e it opened vim in same window. Is there any way to open file to edit in already opened gvim program?
You can use Vim's client-server feature to send the :edit to the existing GVIM instance. In the terminal Vim / vifm, execute:
:!gvim --remote path/to/file
See :help remote.txt for details. You can also open the file in a new tab page with --remote-tab etc.
Partial solution/workaround (I'm using a mac fwiw):
In vfimrc, define
" yank current file path into the clipboard
nnoremap Cf :!echo -n %c:p | pbcopy %i<cr>
To copy filename and dir into system clipboard
Then in vifm, cursor over file and type
Cf
:!gvim "
<cmd-v>
to paste clipboard,
and finish expression with...
"
<enter>
and now that file should open in gvim. It worked for me

Re-execute command by :history option in VIM

How can you execute a command again listed in the
:history
option in vim. There are numbers shown. Is the only way to copy the command by hand, then re-enter it? Or is there something like in shell script.
:history is only there for you to look at it.
To re-execute a previous command, you have two options:
Use <Up> and <Down> at the command prompt:
:m10
(do stuff)
:<Up>
Use the "command-line window":
You can call it with q: and navigate with search and use the beautiful normal mode commands we all love.
Position the cursor on a line and hit <CR> to re-execute the command.
Edit a command and hit <CR> to execute the new command.
You can quit the command-line window with :q.
See :help cmdline-window.
I use q: shortcut in normal mode to open interactive command history window. You just move to the right command and execute it by pressing Enter. You can find more information and other ways of accessing history here.
What I like to do is type the first few characters in the command and press <UP>. For example if you want to repeat an edit command of the file file.txt you could:
:e fil<UP><ENTER>
If the first <UP> does not give you the command you want, keep pressing<UP> until you find the command you were looking for.
If Vim is compiled with +eval you can use histget( {history} [, {index}])
:exe histget('c', 15)
That isn't exactly convenient to type, so you can also create a user-defined command:
:com -nargs=1 HI exe histget('c', <args>)
Thereafter you can use HI {index} to execute the history entry:
:HI 15

vim command line editting

is there a way to use vim/vi in the vim command line? Sometimes I write a long
command in vim such as:
:!./script /home/user/pet --flag=1
and I want to change for instance "user" by "other". What I usually do is to
navigate the command line with right arrow which is time consuming and even more
when I want to go to the beginning of the line. I would like to have something
like "0" to go there or w/b to move by words. Or use j/k to go to the next/previous
command.
Thanks.
:h cedit
in command line, type ctrl-F(default) to enter command window.
or in normal mode type q:
(for search, type q/)
Vim has a feature called the "commandline window". You can enter it with Control-F by default when you're already on the commandline, or q: from normal mode, edit the commandline using vim commands, and press enter to execute. It also contains your command history so that you can yank previous commands if you like. See :help cmdline-window for more information.
I'm not aware how you can use Vim commands to edit a command directly on the command line, but if you enter the command window q: you get can use regular Vim editing to edit commands.
From there you can execute commands by hitting <CR> or use Ctrl-C to copy the command to the regular command line.
If you run set -o vi you will have vim capabilities in your command line. Just put 'set -o vi' in your .bashrc file or equivalent to have it by default.

Resources