vim - How to open multiple windows inside multiple tabs from command line? - vim

I did my best to find the answer to this; my apologies if I missed it.
Some quick background: I'm looking at the protocol parsers in Bro, specifically those that have been created using BinPAC. In each folder I'm interested in, there are multiple files I want to open, using the naming convention {protocol-name}-protocol.pac, and {protocol-name}-analyzer.pac. The best way to view each protocol's files is side-by-side.
Now, what I want to do is have a separate tab open for each pair. That is, the first tab will have {protocol1}-protocol.pac in one window, and {protocol1}-analyzer.pac in an adjacent window, the second tab will have {protocol2}-protocol.pac in one window, and {protocol2}-analyzer.pac in an adjacent window, and so on.
I'm trying to figure out a way to do the above for all of the relevant folders in one command from the command line. I know how to open all the relevant files in separate tabs, or separate windows, but I can't figure out a way to combine these to get the behavior I want. I could do this manually i.e. open one pair, create a new tab and open another pair etc., but that's obnoxious and repetitive, so I'd much rather do it in one command if possible.
Anyone have any idea how to do this? Or if it's even possible?

It should be possible using --remote-tab option of vim
First start a vim server
$ gvim --servername MYSERVER &
Now add your protocol files one by one to the vim server, while adding replace the -protocol in the file name to -analyzer and open it in vs[plit] to get the corresponding analyzer file.
$ find . -name \*.pac -exec gvim --servername MYSERVER --remote-tab "+execute 'vs ' . substitute(expand('%:p'), '-protocol', '-analyzer', '')" {} \;
Refer http://vimdoc.sourceforge.net/htmldoc/remote.html for more details.
Hope this is helpful

Related

Multi cursor editing in multiple (open) documents

I have 10-20 configuration files in which I have to change the same setting quite often.
I was thinking about multi cursor approach (like in Sublime Text), but in multiple documents at the same time.
I can use find/replace in files, etc, but I would love to see what is being edited and selecting same 'setting key' just by pressing CMD + D would be just amazing.
Anyone knows an editor which can do multi-cursor editing in multiple buffers/documents? Or maybe another way of efficiently editing multiple files which are almost identical?
This is not possible in Sublime, nor any other editor of which I'm aware. In Sublime, for example, you can have multiple open files in different tabs and/or windows, but only one has the focus at any one time. It just doesn't make much sense to have input going to multiple windows at once.
Your problem is just crying out for a scripted solution. In Sublime you can create macros and Python-based plugins, as well as using regex-based search and replace. If you're using a shell like bash with access to the standard array of command-line utilities, you can use any number of ways (sed, awk, Python, Perl, expect, and many more) to identify the desired files, select the setting that needs to be changed, and change it, either automatically or with confirmation at each step.

Creating a generic command to edit and quickly execute (python) scripts

I am currently using tmux to create two panes and have vim open in one and plain terminal on the other.
I am using tmuxinator to automate the proccess but I can't figure out a way to make it more generic for different files in different project.
Here is my project.yml for tmuxinator
windows:
- editor:
layout: 9a26,204x53,0,0{115x53,0,0,0,88x53,116,0,1}
panes:
- editor:
- workon dev
- vim ~/repos/project/ #somehow specify this file through arguements
- commandline:
- workon dev
and here is the vim map I use to execute the current file to the pane on the right
:map <Leader>rl :w<Bar>execute 'silent !tmux send-keys -t right "python $(pwd)/%" ENTER'<Bar>redraw!<C-M>
I was wondering if there is a way to give an arguement to the tmuxinator project command or something of this sort for the file that vim is going to open.
Kind of an alias that I could type tmux-alias-for-vim-and-python dev-file.py without having to create a project.yml for each and every different project/file I want to work on.
I may be following an incorrect approach to using tmux/tmuxinator this way so I am open to other suggestion that could accomplish the same thing without tmuxinator
There is no existing trivial way to achieve this.
tmux/tmuxinator aren't really set up to work this way. The best way I can think to have something like this would be to have a template tmuxinator file and set up a shell script so that the script
Takes the arguments you need to pass to the template
Uses those arguments to create a new tmuxinator file
Launches tmuxinator using the new file name as the argument
Once you've done that, put the project up on GitHub. I'm sure there are plenty of people who'd like to have something like this.

Opening files in tabs in Macvim

I am trying to learn MacVim with the Janus build. I've done the Vim tutorial and now I want to dive in and create some simple websites. My first project is a site that will convert roman numerals to arabic. But I can't seem to do the simplest thing - create new files in seperate tabs in one window for html, css, and js - using MacVim. I can create blank files from the terminal and then open the finder and drag these files to an open MacVim window and achieve my goal but it seems like a very convoluted approach. What I want to do is launch MacVim and create my blank html file in the open window and then create a blank css file in an adjacent tab and then create a blank js file in a third adjacent tab and then get to work on them. But when I use the command line in MacVim to create a new file (:!mvim roman.html), I get a new window. So I end up with a series of windows instead of a series of tabs. I googled around and it seems like others have had this problem. Their solution is to modify .bashrc or .bash_profie with an alias (MacVim Open File In Existing Window), but when I tried this and attempted to open a file in MacVim, I got a file filled with garbage, not an empty file. I'm also trying to make sense of NERDTRee. Maybe there is a simple solution there but I am just starting to explore it. Any guidance would be appreciated. Thanks.
You didn't ask for that much but here we go…
Drop Janus as soon as you can. This piece of shit gives you a false sense of comfort while actively preventing you from learning how to use Vim and making it a lot harder than necessary to customize it to your liking.
Vim's tabs are not like tabs in other editors: they are not and can't be 1-to-1 proxies for files. In Vim, a file is loaded in a "buffer" and that buffer may or may not be displayed in zero or more "windows", in zero or more "tabs". This particularity will probably bite you one of these days so you'd better get used to deal with buffers.
In Vim, creating a new file works the same as in any editor: you edit a new empty file and, when you are done, you write it to disk.
:e[dit] file.html
(editing)
:w[rite]
Use :sp[lit] file.js to edit file.js in a new horizontally window.
Use :vs[plit] file.html to edit file.html in a new vertical window.
Use :tabe[dit] file.css to edit file.css in a new tab.
If you want to postpone the decision of the filename, :enew, :new, :vnew and :tabnew create empty buffers in place, in an horizontal window, in a vertical one and a tab.
You don't really need to create those files from outside of Vim.
From the Finder, the simplest way to edit a file in MacVim is to right-click on it and choose "Edit in MacVim". Same for three files.
There is a drop menu, somewhere in MacVim's Preferences window, that lets you define the default behavior when MacVim is launched by other programs. Try it.
Since you seem to have installed the mvim script, editing a file in the MacVim GUI is done with $ mvim filename and editing the same file directly in your shell is done with $ mvim -v filename.
You can also open multiples files (even if they don't exist) in their own tabs from your shell:
$ mvim -p file1 file2 file3
Your command, :!mvim filename, does exactly what it's supposed to do: it launches a new MacVim instance.
Vim already comes with a file explorer that does a lot more than NERDTree called Netrw. See :help netrw.
Did I tell you that you shouldn't use tabs if you don't have a solid understanding of what they are and what they do?
I think the command you want is :tabe something.html. That creates a new tab in the current window with the file something.html in it, and will create a new file if that doesn't exist. (Technically it won't create the new file until you save it).
If you like using tabs, it's probably worth your time to read :help tab-page-commands.
Command + T
Creates a new tab in MacVim.

vi text search with exclude (linux)

I have a huge log file (25.3 million lines) with errors and I won't to search it without holding down the up button. How can you search this with vi? I've seen similar at directory levels but not particular files. At the moment I've searched a date e.g. /Tue 15 Jan
and navigated down but I'm not sure when problems may have began (only when noticed) so I need a general search.
My general idea from within the file would be /ORA-/!ORA-00020
meaning that I want to find those strings containing "ORA-" but ignoring those that are "ORA-00020". Any idea how this can be done viewing a particular file?
Thanks for any info
You do
grep -v "ORA\-00020" error.log > error2.log
then you search error2.log
I don't know the exactly way on vi, but we have kind of ways to get the result:
we can use cat/grep commands and write the answers in another file (so we have much smaller file) and then you can search in it, if it will be ok.
you can use vim instead vi and use TagList Vim Plugin.
Additional info at:
http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/
http://vim-taglist.sourceforge.net/faq.html

A few vim questions

So I was hoping that some old school Vim'ers could help me out. These are all separate questions and normally I would put them up each on their own but I'm not sure if that qualifies as question whoring here.
Plus I think if you know enough to be asking any of these questions they will all be coming up in the near future:
I have a library I'm writing and a series of applications that use that library. There doesn't seem to be an easy way(from what I can tell) to build a ctags file for the library and build one for each of my applications and make sure one references the other when I'm in vim.
Using gf to open files from command mode is awesome, but a lot of my include files
don't contain the full path. They refer to an include directory I set in the IDE. How can I set this directory as another point for Vim to start looking for files?
Is there a way to compile a file inside Vim and send the output to a buffer? I'm currently using MSVS 2k3 but I'll be porting over to Linux in a few weeks so if this is possible on either system I'd appreciate it.
Re 3)
If you put a makefile in your root dir, you can simply write
:make
This will run make and (iirc) put any errors into a seperate buffer, and make vim goto the first compile error. From there you can navigate all erroring lines using :next-error
Also, see this page
http://wiki.beyondunreal.com/Legacy:Vim
and
http://linux.byexamples.com/archives/287/perform-grep-and-make-in-vim/
for details on how to show the result in a seperate console.
1- tags files are independent, and can be used together. See :h 'tags'
I can't tell what is the easy way to build tags files. I have one that consists in using two plugins of mine:
one (draft) plugin that knows how to update C++ tags files (it should be easy to adapt it to other filetypes),
and another (local_vimrc) that helps me define directories-local .vimrc. Thus for any files within a given directory hierarchy, I can adapt the &tags options to use the relevant tag files, and the current tag file that will be rebuilt automatically (or when a keybinding is triggered). (Plugins like project should do the trick as well)
2- :h 'path'
3- :h :make
HTH.
2)
:cd {path}
For help:
:he cd
A few others like :lcd might be better suited. Just scroll down that help page.
This is rather off topic, but might still be useful: if you're using Visual Studio a lot and like Vim, you might want to look at ViEmu. It's the best Vim-emulation for any IDE I've yet seen, and the cost is really low. :) And no, I'm not getting a commission. :P
It's not obvious, but if you open a directory instead of a file, it's nicely browseable.
e.g.
:e . (colon-e-dot)
:e .. (colon-e-dot-dot)
will let you browse from your current directory or its parent.
(understanding that you were probably hoping for a capability to have vim accept e.g.
:e abc.txt
and have it look in several directories, which I don't know how to do.)

Resources