Open file with vim but keep the terminal open as well? - vim

Is there a way to open a new vim file in basically a new terminal window(urxvt) ?
For example if I am currently in ~/X/Y.txt and I write
vim --new-window(basically the command needed to open a new window) Y.txt
I still want my current urxvt session while opening the Y.txt in a vim-Session.

gvim will open up vim in a GUI (i.e., not in the terminal).

You can use vim's client-server model. Run one instance as a server and edit files with option --remote.
Another solution would be to use terminal multiplexors like GNU screen, tmux or such.
Other variants are: use a terminal with tabs, use gvim.

I highly, highly, strongly recommend downloading NERDTree. It makes your Vim terminal look (relatively, comparatively) similar to a "normal" IDE, with a narrow file-and-folder bar on the left side, and a "main" terminal window taking up the rest of the screen. You use Ctrl+W to navigate back and forth between the two screens. Plus, in the sidebar, you can use normal Vim commands to move up and down. Whoever created that plugin put a lot of work into it.

Related

Is it possible to open VIM not in full screen?

Sometimes I need to edit a small config file and return to my terminal workflow.
Opening VIM by default will cover the entire screen, just for a small change.
Is there any option to open vim, not in fullscreen?
If not, is there any terminal text editor that can do that?
Unfortunately Vim doesn't provide any way to modify your terminal window. But you can use terminal emulators like Tmux for multi-window support. And don't forget that you can do :vert term in Vim to split your window, but with some limited possibilities

FileManager for vim

Is there a way to make Vim work like notepad++ with explorer plugin or other text editors as pspad, ultraedit and editplus?
that is
keep a fileexplorer always left (left sidebar of 15% width)
and opens all files in the content window (85% of width) and every file in a new tab (above).
I checked nerdtree and vimexplorer plugin but could not find any way to do what I want.
Check out NERD Tree. This isn't the best screenshot, but it'll give you an idea of what to expect:
To your question there is definitely many ways you can possibly get the outcome. When you mentioned NERDTree does not work the way you want, I believe you have not tried it out well enough. I would recommend you read the documentation of the NERDTree plugin. Derek's answer just shows you that with NERDTree and minibufexplorer.
One solution I could suggest is have a windows file explorer open beside your gvim window. Follow instructions in the vim.wikia page to open files in a tab when you double click on the file. If you are using Mac, MacVim has an option to open new files in a tab by default.
Now that I have provided a solution, let me remind you that Vim is unlike most of the other editors you might have used earlier. Look at the answer titled "Your problem with Vim is that you don't grok vi.", here. Vim is different, learn to grok it.
Now the point of tabs in Vim. Tabs in Vim are different, look at an answer in SO here. Tabs in vi are more like workspaces. In Linux or Mac you have the concept of workspaces where you can place your application windows together. For example assume I am working on developing a website. In one workspace I would keep my code editor, my web browser and probably a terminal. And for all my personal stuffs I would you another workspace. Like for my social stuffs I would have another workspace with my twitter client, my chat messenger and a browser for facebook. Similarly in Vim use tabs as workspaces for your different files. You might be editing couple of files. Group the ones you edit, use window splits which vim is best for. This is my vim layout:
.
I havent used tabs but use NERDTree, minibufexplorer and serves my need. I don't have to use my mouse at all, it makes my editing more efficient. Take some time reading good articles about Vim. You will see that you actually don't need most of the GUI stuffs many other editors gloat about. Try using Command-T plugin for opening files. You will find it a lot more efficient.
Read the following to get a better idea about tabs, buffers and windows in Vim:
http://jonathan.jsphere.com/post/9927807318/taming-vim-4-buffers-windows-tabs
http://blog.interlinked.org/tutorials/vim_tutorial.html
I personally use a combination of minibufexplorer and NERDTree, and it works very well for me. minibufexplorer keeps a window at the top with all the files I've opened, which I can switch between using ctrl-tab. NERDTree is open on the left, and choosing a file opens it in my main editor window, and lists it in the minibufexplorer window.
VIM includes netrw, which is already a filebrowser and I like it a lot more than NERDTree.
I have included the function below in my local .alias file.
Thus, from a terminal or console execute vc (mnemonics for V.im C.ommander) and you'll get a nice double pane browser with ssh, ftp, file execution and a large array of capabilities.
In SH alike shells try:
vc ()
{
local TARGET='';
[ -z "$#" ] && TARGET=. || TARGET="$#";
vim \
-c "set cursorline" \
-c vsplit \
-c "normal gh" \
-c "let &titlestring=\"netrw\"" \
-c "set acd" "$TARGET";
return 0
}
Enjoy!
PS:// If you need netrw filetype definitions (i.e., executing a movie player for movie files and so forth, i'll publish mine)

Open vim tab in new (GUI) window?

I'd like to move the current tab into a new (visual/real) window in MacVim.
It's probably difficult, as:
there is nothing in the vim help and only very few - not helpful - hits on google
MacVim does not support it (link, 2009)
So I am wondering if someone has found a way to achieve this?
The closest I think you can come is using mksession
This will have several drawbacks (like, initially the secondary session will open a few more buffers than ultimately desired).
However, it will preserve your mappings, settings, history, window layout (if you had multiple windows inside the current tab, they will all get cloned).
If this idea tickles your fancy, you could look at creating a script that will filter parts out of the session file (which is Yust Another Vim Text Script)
:mksession! $HOME/detach.vim
:tabclose
:silent! !gvim remote --servername Detach -nR +'silent! source H:\detach.vim' +tabonly
save all current windows, mappings, settings (:he mksession)
close the tab we are about to detach
clone the session (detach.vim) into a remote vim
:silent! (try not to talk too much)
!gvim remote --servername Detach; launch a new remote Vim server if it doesn't yet exist, or talk to the existing server named Detach
-nR TODO Fix This is here to avoid the use of swapfiles (because I found no way to suppress the dreaded ATTENTION messages[1]). However, this may be unsafe advice depending on your situation, which is why I also include -R for read-only mode
+'silent! source H:\detach.vim' +tabonly -- In the remote vim, source the session to clone, and keep only the active tab (that was already closed in step 1.)
A little rough around the edges, for sure, but quite close to what you intended, I feel.
If you are comfortable, you can drop the -nR flags and just click through a few annoying swapfile attention messages (keyboard: Q).
[1] :he ATTENTION
Post-scripts:
on windows you might want to use :silent! !start /b gvim .... in case you have terminal windows sticking around
also on windows, you might get annoying behaviour if the resulting gvim window is too small. The :simalt ~x sequence is one hacky way to maximize the window (assuming English UI, because x is the accelerator for Maximize)
as icing on the cake, vim 7.3 has 'persistent undo'. See e.g. :se undofile
I don't think this is possible because, when you open a new instance of (g)vim you don't have access to the undo-history of the previous vim instance. All you can do is (in command mode):
:!gvim %
It will open the current file in a new instance of gvim. At least this is all I could think of. I may be wrong

Interactive terminal in VIM

I'm using Vim for editing source code, but I would also like to have a terminal embedded in vim's window (just like in Kate, you know).
Now I have seen the vimsh plugin that turns a vim buffer into an interactive terminal, but I don't like 2 things about it:
It opens automatically at startup. Can I disable it and invoke the terminal with a special command whenever I wish?
It splits the window in two and occupies the top window, but I would like it to occupy the bottom window. Can this be arranged?
PS: I'm not exactly a vim guru :)
Maybe this is what you want: Conque Shell - VIM Plugin
There's also an older patch that you can apply. It requires recompilation of the VIM source code though.
http://www.wana.at/vimshell/
Maybe I am not going to reply exactly to your question but I'll propose anyway a different approach on working with Vim and the terminal.
The first approach is to run shell commands directly from vim in command mode prepending them with a "!":
:!ls
will run the shell ls command and display you the output in a temporary window. This is useful if you just want to run a single or few commands.
If you want to mess around longer I suggest to suspend your vim session with Ctrl-z, work in the shell and issue fg as your last command to get back to vim.
Hope it helps you.
Another option you could try is using tmux/screen to split your terminal, so that you can then run vim in one pane and have your shell in another. I also liberally use ControlZ to drop into a shell from vim and then fg to get back to vim after finishing with the shell.

What's the best (Linux-compatible) buffer/session manager for Vim?

Is there a good project / session manager for vim? A session (or project) is a named lists of files, e.g. "bitonic_sort" could identify files "~/A/bitonic_sort.sk", "~/B/bitonic_sort.smt2", etc.
(rationale) I have a project where I need to edit files from many different locations, and it is too cumbersome to open them manually each time I resume work. (so, it looks like things like nerdtree brought up at this sister question, Favorite (G)Vim plugins/scripts?, won't work). I also need separate sessions (i.e. lists of files) for different projects, not just a recent document list.
After all documents have been loaded as buffers, any enhancements to switching between them is a plus (e.g. start typing a name, and matching documents are displayed). Thanks in advance.
Vim has built-in session manager. To save your current session use:
:mks session1.vim
This basically create a Vim script named session1.vim, which will restore your opened file if you source it or start Vim like this:
vim -S session1.vim
To overwrite your saved sessions, use :mks! your_saved_session.vim. Combine with a custom key map and this will be the solution. For more about Vim session read :help :mks. Vim also has views manager which is quite similar. Read more from: :help :mkview
For switching between buffers, you can use FuzzyFinder; but I prefer this key map:
nmap <C-tab> :bn<CR>
imap <C-tab> <ESC>:bn<CR>i
Add it to .vimrc and I can use Ctrl + Tab to switch between buffers just like Firefox tabs. Hope this help.
I'm not sure exactly what you're asking for... but if you want to turn on tab-completion when opening files in vim, add this to your ~/.vimrc:
" Auto-complete file names after <TAB> like bash does.
set wildmode=longest,list
set wildignore=.svn,CVS,*.swp
Also, take a look at screen. From the man page:
When screen is called, it creates a single window with a shell in it (or the specified command) and
then gets out of your way so that you can use the program as you normally would. Then, at any time,
you can create new (full-screen) windows with other programs in them (including more shells), kill
existing windows, view a list of windows, turn output logging on and off, copy-and-paste text between
windows, view the scrollback history, switch between windows in whatever manner you wish, etc. All
windows run their programs completely independent of each other. Programs continue to run when their
window is currently not visible and even when the whole screen session is detached from the user's
terminal. When a program terminates, screen (per default) kills the window that contained it. If
this window was in the foreground, the display switches to the previous window; if none are left,
screen exits.
It's pretty much like having several xterms open, except unlike graphical xterms you can access your screen session if you access your machine remotely (e.g. by sshing to it). You could leave up several different instances of vim in separate screens with all the files you want open, and just never exit them.
The very basic setup I use is one vim window, one compile window, and one testing/debugging window.
And since we're talking about vim, check out this post: Post your Vim config. Lots of cool tweaks and spiffy stuff in there.
You can try the vim-workspace plugin, its session management features are automated and relatively simple (compared to vim-session): https://github.com/thaerkh/vim-workspace

Resources