MacVim: Opening webview or displaying tooltips like TextMate - vim

I am starting on VIM and trying to understand it a bit. I currently use TextMate for web development, so I can build nice commands which take my current document/selection and display as a web view very quickly or send some results through tooltips.
I believe it's more appropriate to refer this question to MacVim since it has access to GUI elements so sometimes it might be possible?
"HTML Output for Commands" is a good explanation.
So I would like to know if it's posibble to output commands to a HTML window just like TextMate?
Or would I have to create my own program that accepts STDIN and display it as an html output on a view?
The same for the tooltips?
I was hoping that as MacVim is has access to Cocoa library and GUI elements perhaps it could already have some feature like this?
Sorry if I am misunderstanding things here, I really feel that it would be a good idea to migrate but obviously I would like to keep the nice and quick tools that I use and not losing a good visual appeal.

so I would like to know if its posibble to output commands to an html window just like TextMate?
You could have vim issue a command at the command-line which would tell a browser to open a file you're editing.
On a Mac, using either vim at the command-line or MacVim, if you were editing a file called "test.html" in the buffer and it was in your Desktop folder:
:!open ~/Desktop/test.html
will open, or re-open the file in the browser. So, when you make a change you issue that and the browser will come to the foreground with the latest version of the file. You could use the other options to "open" to specify which browser to use. And, you could easily add a key press to open the current file, which is "%" on the command line.
If you want to capture the output of a command in vim, there are a couple ways to do that. If you execute a command vim will capture its output in a temporary buffer for viewing.
:!ls
displays:
:!ls
Desktop Downloads Library Music Photo Tools Public VirtualBox VMs bin
Documents Editors Movies Music Tools Pictures Sites Web Tools
You can also see what's in Command - R like functionality in MacVim and Vim - Displaying Code Output in a New Window á la Textmate?.
I'm not sure what you mean by "tooltips". Usually that refers to pop-up text at the tip of your mouse offering context sensitive help. You can't send text through that, so your use of the word is confusing.
MacVim and vim do have snippet-like capability, plus are scriptable, can work on text that is the current selection, plus a whole lot more. It's important to understand that MacVim is a GUI layer on top of the regular vim editor, so there are somethings it won't do because vim's engine doesn't make it easy. That hasn't ever bothered me, because if I need a particular TextMate feature I'll fire it up, use that particular thing, then jump back if I feel like it. But, that's not too common a need for me.
You might want to look at some of the related threads here on SO, over on the right hand side of the page, plus look at some of vim's plugins like:
taglist.vim
vimspell
matchit.zip
align
surround
Tabular
I use the above ones all the time. The following ones I'd miss if I didn't have them.
Command-T
SnipMate
Rails.vim
EDIT:
Capturing the temporary buffer to a new buffer in Vim is pretty easy:
:redir #a
:sil !ls -al
:redir end
:vnew
"agp
The second line :sil !ls -al could be any execution of a command. :sil tells Vim to not echo the output to the temporary buffer, instead capture it silently, which gets rid of the "Press any key" pause.
:vnew creates a vertical split with a new buffer in it. You could use :tabnew instead if you want a new tab.
"agp tells it to use buffer #a and paste the output into the current buffer and leave the cursor below the pasted text.

Related

How do you hyperlink text in vim editor?

I need to set some text to be hyperlinked to a website via the vim editor. How do I accomplish that?
Vim is not a word processor. Vim displays text exactly as it is on the disk. You can do some minor "formatting" of text such as folding lines, syntax highlighting, concealing a few characters, but that's it. None of this information is actually stored in the file itself, instead, it is applied from "outside the file" with Vim. This is different from .doc files, where the formatting is stored in the file.
Note that gx opens links. Perhaps this is what you want?
What you want can maybe be done with:
A conceal pattern combined with some custom mappings. I haven't tried doing this, but it's probably possible.
The only way to "link" something in Vim is to another file using tags. See :help tags-and-searches. Perhaps this feature can be abused into opening web pages, I don't suggest that you try.
In short, you're trying to use Vim for a task it wasn't really designed to do, so doing that will be hard and ugly, if possible at all.
If you don't require a link that can be "clicked" with a mouse and don't mind having some extra text showing you can use the utl (universal text link) plugin. Get the details at https://www.vim.org/scripts/script.php?script_id=293. It is old, but still works for me. To link to google for instance the text would have < url:www.google.com > in the text. To use the link, move your cursor somewhere on or between the brackets and input \gu from command mode. This will cause your browser to go to Google's site. Of course there is some setup in the utl_rc.vim file to point it at your browser.
I should also note that you can use this to move between text files, or within a file as well. The details are at the link I gave above.

Return focus to vim when using screens plugin after ScreenShellFocus?

The screens plugin turns vim into a kind of dreampie, only its a whole lot better because you have more control over what gets send even when you have multiple buffers and specific text within those buffers.
To follow my environment setup, merely install screens with vim, and then at the command line, do screen, reach the shell, then type vim in. Edit a shell script of some kind with it, then do :ScreenShell *shell type here, eg python/bash/irb* which spawns a shell below. You can use :ScreenShellSend to send the visually selected text to the shell or all of the file if none is selected.
My problem is, say I want to restart the shell that I'm running using this plugin and sending it some text. I need to do :ScreenShellFocus, call exit, and then start it up again. But then I need to be able to return to the same vim session that is directly above the shell that I'm affecting. I realize that I can use screen to just reach the vim session, but the only way I can do that now is to select it with ^a 1, which really only replaces the lower portion, the one that supposed to be the shell, with the vim buffer being edited. This is stupid because now you have vim buffer on top of vim buffer.
So my question is, how do I return the cursor to the vim session above after doing :ScreenShellFocus?
(yes I know my example of killing and restarting a shell may be circumvented by other logic, but I'm not that acquainted with the GNU screen util, and I think there's a way to do it like this, which I think preserves the workflow of the programmer)
<C-a><Tab>
is the mapping used in screen to cycle through "regions". Since you have only two, it moves the focus to the other region.
Since you are effectively using screen, you should learn how to use it to make this plugin really useful.
$ man screen

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)

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

Using Vim's tabs like buffers

I have looked at the ability to use tabs in Vim (with :tabe, :tabnew, etc.) as a replacement for my current practice of having many files open in the same window in hidden buffers.
I would like every distinct file that I have open to always be in its own tab. However, there are some things that get in the way of this. How do I fix these:
When commands like gf and ^] jump to a location in another file, the file opens in a new buffer in the current tab. Is there a way to have all of these sorts of commands open the file in a new tab, or switch to the existing tab with the file if it is already open?
When switching buffers I can use
:b <part of filename><tab>
and it will complete the names of files in existing buffers. <part of filename> can even be the middle of a filename instead of the beginning. Is there an equivalent for switching tabs?
Stop, stop, stop.
This is not how Vim's tabs are designed to be used. In fact, they're misnamed. A better name would be "viewport" or "layout", because that's what a tab is—it's a different layout of windows of all of your existing buffers.
Trying to beat Vim into 1 tab == 1 buffer is an exercise in futility. Vim doesn't know or care and it will not respect it on all commands—in particular, anything that uses the quickfix buffer (:make, :grep, and :helpgrep are the ones that spring to mind) will happily ignore tabs and there's nothing you can do to stop that.
Instead:
:set hidden
If you don't have this set already, then do so. It makes vim work like every other multiple-file editor on the planet. You can have edited buffers that aren't visible in a window somewhere.
Use :bn, :bp, :b #, :b name, and ctrl-6 to switch between buffers. I like ctrl-6 myself (alone it switches to the previously used buffer, or #ctrl-6 switches to buffer number #).
Use :ls to list buffers, or a plugin like MiniBufExpl or BufExplorer.
Bit late to the party here but surprised I didn't see the following in this list:
:tab sball - this opens a new tab for each open buffer.
:help switchbuf - this controls buffer switching behaviour, try :set switchbuf=usetab,newtab. This should mean switching to the existing tab if the buffer is open, or creating a new one if not.
Vim :help window explains the confusion "tabs vs buffers" pretty well.
A buffer is the in-memory text of a file.
A window is a viewport
on a buffer.
A tab page is a collection of windows.
Opening multiple files is achieved in vim with buffers. In other editors (e.g. notepad++) this is done with tabs, so the name tab in vim maybe misleading.
Windows are for the purpose of splitting the workspace and displaying multiple files (buffers) together on one screen. In other editors this could be achieved by opening multiple GUI windows and rearranging them on the desktop.
Finally in this analogy vim's tab pages would correspond to multiple desktops, that is different rearrangements of windows.
As vim help: tab-page explains a tab page can be used, when one wants to temporarily edit a file, but does not want to change anything in the current layout of windows and buffers. In such a case another tab page can be used just for the purpose of editing that particular file.
Of course you have to remember that displaying the same file in many tab pages or windows would result in displaying the same working copy (buffer).
Contrary to some of the other answers here, I say that you can use tabs however you want. vim was designed to be versatile and customizable, rather than forcing you to work according to predefined parameters. We all know how us programmers love to impose our "ethics" on everyone else, so this achievement is certainly a primary feature.
<C-w>gf is the tab equivalent of buffers' gf command. <C-PageUp> and <C-PageDown> will switch between tabs. (In Byobu, these two commands never work for me, but they work outside of Byobu/tmux. Alternatives are gt and gT.) <C-w>T will move the current window to a new tab page.
If you'd prefer that vim use an existing tab if possible, rather than creating a duplicate tab, add :set switchbuf=usetab to your .vimrc file. You can add newtab to the list (:set switchbuf=usetab,newtab) to force QuickFix commands that display compile errors to open in separate tabs. I prefer split instead, which opens the compile errors in a split window.
If you have mouse support enabled with :set mouse=a, you can interact with the tabs by clicking on them. There's also a + button by default that will create a new tab.
For the documentation on tabs, type :help tab-page in normal mode. (After you do that, you can practice moving a window to a tab using <C-w>T.) There's a long list of commands. Some of the window commands have to do with tabs, so you might want to look at that documentation as well via :help windows.
Addition: 2013-12-19
To open multiple files in vim with each file in a separate tab, use vim -p file1 file2 .... If you're like me and always forget to add -p, you can add it at the end, as vim follows the normal command line option parsing rules. Alternatively, you can add a bash alias mapping vim to vim -p.
I ran into the same problem. I wanted tabs to work like buffers and I never quite manage to get them to. The solution that I finally settled on was to make buffers behave like tabs!
Check out the plugin called Mini Buffer Explorer, once installed and configured, you'll be able to work with buffers virtaully the same way as tabs without losing any functionality.
This is an answer for those not familiar with Vim and coming from other text editors (in my case Sublime Text).
I read through all these answers and it still wasn't clear. If you read through them enough things begin to make sense, but it took me hours of going back and forth between questions.
The first thing is, as others have explained:
Tab Pages, sound a lot like tabs, they act like tabs and look a lot like tabs in most other GUI editors, but they're not. I think it's an a bad mental model that was built on in Vim, which unfortunately clouds the extra power that you have within a tab page.
The first description that I understood was from #crenate's answer is that they are the equivalent to multiple desktops. When seen in that regard you'd only ever have a couple of desktops open but have lots of GUI windows open within each one.
I would say they are similar to in other editors/browsers:
Tab groupings
Sublime Text workspaces (i.e. a list of the open files that you have in a project)
When you see them like that you realise the power of them that you can easily group sets of files (buffers) together e.g. your CSS files, your HTML files and your JS files in different tab pages. Which is actually pretty awesome.
Other descriptions that I find confusing
Viewport
This makes no sense to me. A viewport which although it does have a defined dictionary term, I've only heard referring to Vim windows in the :help window doc. Viewport is not a term I've ever heard with regards to editors like Sublime Text, Visual Studio, Atom, Notepad++. In fact I'd never heard about it for Vim until I started to try using tab pages.
If you view tab pages like multiple desktops, then referring to a desktop as a single window seems odd.
Workspaces
This possibly makes more sense, the dictionary definition is:
A memory storage facility for temporary use.
So it's like a place where you store a group of buffers.
I didn't initially sound like Sublime Text's concept of a workspace which is a list of all the files that you have open in your project:
the sublime-workspace file, which contains user specific data, such as the open files and the modifications to each.
However thinking about it more, this does actually agree. If you regard a Vim tab page like a Sublime Text project, then it would seem odd to have just one file open in each project and keep switching between projects. Hence why using a tab page to have open only one file is odd.
Collection of windows
The :help window refers to tab pages this way. Plus numerous other answers use the same concept. However until you get your head around what a vim window is, then that's not much use, like building a castle on sand.
As I referred to above, a vim window is the same as a viewport and quiet excellently explained in this linux.com article:
A really useful feature in Vim is the ability to split the viewable area between one or more files, or just to split the window to view two bits of the same file more easily. The Vim documentation refers to this as a viewport or window, interchangeably.
You may already be familiar with this feature if you've ever used Vim's help feature by using :help topic or pressing the F1 key. When you enter help, Vim splits the viewport and opens the help documentation in the top viewport, leaving your document open in the bottom viewport.
I find it odd that a tab page is referred to as a collection of windows instead of a collection of buffers. But I guess you can have two separate tab pages open each with multiple windows all pointing at the same buffer, at least that's what I understand so far.
You can map commands that normally manipulate buffers to manipulate tabs, as I've done with gf in my .vimrc:
map gf :tabe <cfile><CR>
I'm sure you can do the same with [^
I don't think vim supports this for tabs (yet). I use gt and gT to move to the next and previous tabs, respectively. You can also use Ngt, where N is the tab number. One peeve I have is that, by default, the tab number is not displayed in the tab line. To fix this, I put a couple functions at the end of my .vimrc file (I didn't paste here because it's long and didn't format correctly).
I use buffers like tabs, using the BufExplorer plugin and a few macros:
" CTRL+b opens the buffer list
map <C-b> <esc>:BufExplorer<cr>
" gz in command mode closes the current buffer
map gz :bdelete<cr>
" g[bB] in command mode switch to the next/prev. buffer
map gb :bnext<cr>
map gB :bprev<cr>
With BufExplorer you don't have a tab bar at the top, but on the other hand it saves space on your screen, plus you can have an infinite number of files/buffers open and the buffer list is searchable...
Looking at
:help tabs
it doesn't look like vim wants to work the way you do...
Buffers are shared across tabs, so it doesn't seem possible to lock a given buffer to appear only on a certain tab.
It's a good idea, though.
You could probably get the effect you want by using a terminal that supports tabs, like multi-gnome-terminal, then running vim instances in each terminal tab. Not perfect, though...
If you want buffers to work like tabs, check out the tabline plugin.
That uses a single window, and adds a line on the top to simulate the tabs (just showing the list of buffers). This came out a long time ago when tabs were only supported in GVim but not in the command line vim. Since it is only operating with buffers, everything integrates well with the rest of vim.
relevant:
Vim: can global marks switch tabs instead of the file in the current tab?
maybe useful to solve a little part of OP's problem:
nno \ <Cmd>call To_global_mark()<cr>
fun! To_global_mark()
-tab drop /tmp/useless.md
exe 'normal! `' .. toupper(input("To global mark: "))
endf

Resources