Tab complete from :open in Macvim? - text-editor

If I open MacVim (specifically janus) and try :open ~/<TAB> I get :open ~/^I. How can I get it to tab complete the way one would expect bash completion to work?

You can use :
:e ~/<TAB>
:set wildmenu would also be very helpful.

Related

Show Vim command options

This was a feature I used to have when I was first learning vim, and sometime between me customizing my .vimrc file, I must have disabled it some how.
Lets say I have this command I can enter
:TmuxNavigate
Now this command could take Left, Right, Up, or Down as options. Early on in my learning of Vim, I had a small line above the command line that would show any available commands that start with :TmuxNavigate
I've tried enabling set showcmdor laststatus=2 but wasn't able to enable this feature.
Is this a feature I can enable or have I just completely lost my mind and imagined this? Any help is appreciated.
Just add this line to your ~/.vimrc:
set wildmenu
Every command set up to complete arguments will do what you expect.
See :help 'wildmenu' and :help 'wildmode'.
[space] [Ctrl+d] after command like:
:colorscheme [space] [Ctrl+d]

How to open a terminal in new tab from VIM?

When I'm working with lets say 4 files, all are open in tabs(VIM). I want to save the changes and compile it without having to close the tabs, i.e I want to open a terminal in new tab along with the existing 4?
How should I do this in VIM?
:tab ter
opens a terminal in a new tab instead of opening it in a new window as :ter does. You can also use the equivalent, longer :tab terminal form.
Credits to user wolloda in this Reddit post.
Extra information
Terminating the shell with Ctrl-d or exit closes the terminal buffer.
Ctrl-w N or Ctrl-\ Ctrl-n put the buffer in the terminal-normal mode:
Keystrokes are not forwarded to the shell, but are used by Vim as in a normal buffer
(although the shell job is still running). Then you can use gt to change tabs,
type Ex commands such as :ls, etc. To bring the terminal buffer back to life,
i, a, ...
If you are going to map this, I recommend using :tab ter++kill=hup, so that when you :qa the terminal job does not prevent Vim from quitting.
And this is the signal normal terminal emulators send to its jobs when closed anyway.
For terminal mode mappings, use tnoremap, for example
tnoremap <S-Tab> <C-W>:tabprevious<CR>
tnoremap <C-N> <C-W>N
More information on :help :terminal and :help :tab.
In 2019, vim now has a Terminal mode.
:help terminal
For example, you can use it like this.
# go to terminal-job mode
:terminal
# go to terminal-normal mode
ctrl-w N
# go back to terminal-job mode
i
A more vim like way of doing this would be to use :make
:make
:make will execute the 'makeprg'. It defaults to make which is great of C projects
After running :make the quickfix list will be contain any errors.
Set your compiler via the :compiler command.
Extra parameter can be passed like so :make foo-command
Current filename can be represented by %. e.g. :make %
quickfix list
Use :cnext and :cprev to move between your errors.
:copen to open up the quickfix list in a window (:cclose to close)
:cwindow to open quickfix list window only if there are errors
May want to use better mappings for :cnext and friends. I suggest Tim Pope's unimpaired plugin
Alternatives and Plugins
Just use <c-z> to suspend vim and run your build system. (Cons: loose out on the quickfix list)
Use :! to compile. (Same cons as suspending) e.g. :!make
Syntastic is a syntax checking system that checks files on save
Dispatch can be used to run things in the background. Great for test suites
As #brettanomyces mentioned you may want to consider terminal multiplexers like tmux or screen.
SingleComplile tries and takes some of the work out of using :make
Conclusion
If you are just starting out I would suggest you learn how to use :make and the quickfix list. There is a nice Vimcast episode that intros the quickfix list: Search multiple files with :vimgrep. Additionally Syntastic is a great way to get up and running with linters quickly.
Aside about tabs
Vim's tabs are not like most text editors tab. They are more like viewports into a group of windows/splits. Additionally, Vim is buffer centric, not tab centric like most editors. Therefore using features like the quickfix list is often easier without tabs (See :h 'switchbuf if you must use tabs). Vim's tabs often get in the way of using a splits as there are better window and buffer navigation commands available. I personally have many files open (sometimes 100+) use no tabs and use on average 1-2 splits without any issue. Bottom line: Learn to use buffers effectively.
For more help see the following:
:h :make
:h 'makeprg
:h quickfix
:h :cnext
:h :cope
Vim 8.1 now has a built in terminal that can be opened with the :term command. This provides much more complete integration with the rest of the Vim features.
Original Answer:
I would suggest looking at tmux or screen. I use tmux myself and along with vim-tmux-navigator moving between the terminal and vim is very easy.
For anyone using NeoVim:
The highest voted answer uses :tab ter. This doesn't work on NeoVim (at least for me). However, it's still fairly simple:
:tabe term://bash
tabe is open a new tab and edit file.
term:// is a NeoVim way of opening a terminal
bash is the kind of shell you want to use (e.g. I use zsh, so my command is actually :tabe term://zsh)
Some helpful commands that I created:
" open terminal
if has('nvim')
command Terminal vsplit term://zsh
command TerminalTab tabe term://zsh
else
command Terminal vert term
command TerminalTab tab ter
endif
Another way
Ctrl-w :
That gets me to the command line, then one can enter tablast tabnext or tabprevious
or the short versions tabl, tabn, tabp
Or this way:
Ctrl-w gt and Ctrl-w gT
(Next tab and Previous Tab)
Or Ctrl-w Number gt (for a specific tab)
That works too.

vim: Use insert-mode-like completion for command completion

Is it possible to use a vertical command line completion just the way it appears when using CTRL-N in insert mode?
I personally like
set wildmode=longest,list
It behaves sort of like bash completion. (It also shows the same information as <c-d> when you hit <tab>).
You can have such a menu when doing completion in the command-line window (q:) but you can't have it in the command-line itself.
But set wildmenu (see also :help wildmode) is good enough in my opinion.

Key mapping confusion in VIM,How to make vim works in a smart way?

I want to bind Ctrl-w with :q command in vim That is to say, I want to use Ctrl-w to close the current window of vim,
So I add this to my ~/.vimrc :
nmap <C-W> :q<cr>
When I use this to close a window that has something unsaved,this command cannot work.
So I want to make it works in a smart way: When the content is saved, just close the window. When the content remains unsaved, ask me whether to close the window directly like this command
:0,$s/a/b/gc
I don't know if this is clear enough for you, but thanks in advance.
There's the :confirm command for that. Just put it in front of :quit:
:nmap <C-W> :confirm q<cr>
The simplest thing to do would be to set confirm in your vimrc - this will prompt you before closing without saving (and a few other things, too; see :help confirm).
Otherwise, you could write a little vim script which uses &modified and confirm() (see :help confirm()).

How to open vim command output in separate tab/window?

I'm using vim-rubytest to execute tests from within MacVim.
This prints output in vim's command output window.
The problems are that this output is not scrollable or disappears after i switch to editor.
Is it possible to send this output to separate tab/window in Vim?
I don't use vim-rubytest plugin but looking at the documentation it seems to me that by default vim-rubytest will put the contents into the quickfix list. To open the quickfix window issue the following command:
:copen
You can navigate the quickfix list via :cnext and :cprevious.
I belive the quickfix approach to be the preferred way, but to answer you question you can redirect the output into a register and then paste into a new buffer.
:redir #"
Then execute <leader>T. watch it all go by. Then end the redirection and create a new buffer with the contents inside.
:redir END
:new|pu|0d_
For more help see
:h quickfix
:h :cnext
:h :redir
:h :new
:h :put
:h :delete
The default on vim-rubytest is for let g:rubytest_in_quickfix = 0 this will execute everything on the terminal and echo the results.
In order to "open in a new window" you should set
let g:rubytest_in_quickfix = 1 and then the output will be run and applied to the quickfix. This will open up a separate quickfix window that you can use see all the failures and allow you to jump to the file.
There is an issue with the usage of quickfix that I have filed on github (Reference) that doesn't allow you to open the first error. In the issue I posted a possible fix and have my own fork with it applied + some other minor adjustments to make using quickfix more ideal in my own TDD workflow.

Resources