Manipulating text in XCode, moving one line - xcode

In emacs I have various functions to manipulate text. Now that I'm using xcode, I suppose I could make emacs my default editor, but I want to browse obj-c objects and such, so I'd rather just implement my most used text manipulation commands for xcode.
First on my list, I'd like a command that moves the text of the current line up/down one line, keeping the cursor on the current line.
In emacs this is:
(defun move-one-line-downward ()
"Move current line downward once."
(interactive)
(forward-line)
(transpose-lines 1)
(forward-line -1))
I'd be happiest if I could write a script in Python that would do the equivalent in XCode, but as far as I can tell, I need to talk to AppleScript to do this.
Can someone walk me through how to do this with XCode?

Xcode 4 has a new set of command for moving the line where the cursor is or the selected text with command + option + [ or ]
⌥⌘[ or ⌥⌘]
http://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/xcode_help-command_shortcuts/MenuCommands/MenuCommands014.html

What you’re wanting to do can be achieved through Xcode’s “User Scripts”—and it helpfully comes with a pair of scripts that almost do what you want. (I’m using Xcode 3.2 here, but I think these were also there in 3.1)
Look in /Developer/Library/Xcode/User Scripts/; there are two applescripts there, Move Line Up.scpt and Move Line Down.scpt. Here’s what’s in Move Line Up:
(*
To edit this script, choose Save As... and save it in your home directory, then re-add it to the User Scripts list.
*)
using terms from application "Xcode"
tell first text document
set {startLine, endLine} to selected paragraph range
if startLine > 1 then
set theText to (paragraphs startLine through endLine)
set theText to (theText as string)
delete (paragraphs startLine through endLine)
make new paragraph at beginning of paragraph (startLine - 1) with data theText
set selected paragraph range to {startLine - 1, endLine - 1}
else
beep 1
end if
end tell
end using terms from
These almost do what you want, except they select the whole line afterwards; I’m no applescript expert, but you probably want to store the selected character range. Have a look at the Xcode scripting dictionary (in AppleScript Editor, File -> Open Dictionary -> Xcode) to find out the types of objects you can manipulate.
You can add your own scripts to Xcode with the “Edit User Scripts”menu item in the script menu; and assign shortcut keys to the scripts in that window also, by double-clicking in the right-hand column beside the entry for the script menu item.
You can also use shell scripts (perl, python, bash, whatever) in the User Scripts menu, but these process only the selection or the whole file, so might be a bit heavyweight for moving a single line up or down.
See all the docuemntation on User Scripts here: http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeWorkspace/310-User_Scrips/user_scripts.html
I hope this helps!

I think your question is more generic that Xcode/emacs. Most IDE can't do stuff that editors can do and vice versa.
What I do is to use Xcode for 'simple' stuff and compile/debug. When I want to do lot's of coding (hm ... text editing) I open multiple files in one Vim (no offense to emacs ... vim is my editor of choice) and use all the vim tricks available.
I follow the same process when I need to do lots of coding on Windows (Visual Studio). I have VS opened just for compiling/debugging but I do most coding in separate Vim window.
I don't need to do any of that on Unix because I just open file in Vim and run Makefile from within Vim, jumping directly to errors and so on (:mak) ...
I'm sure that there are some extremely clever things to get Xcode do stuff that are already in Vim and Vim to do stuff that Xcode can do but I'm focusing on coding so not much time to play around.

Also, you can hook up emacs (or vi, or bbedit, or ed, I imagine) to xcode, so that they will talk to each other. When you tell xcode to open a file it will call emacsclient, etc. You can even get emacs to tell xcode where to put a breakpoint (I don't remember how, but I asked a question here a while back, and it works great)

Related

Switching between files without closing vim editor [duplicate]

I've started using Vim to develop Perl scripts and am starting to find it very powerful.
One thing I like is to be able to open multiple files at once with:
vi main.pl maintenance.pl
and then hop between them with:
:n
:prev
and see which file are open with:
:args
And to add a file, I can say:
:n test.pl
which I expect would then be added to my list of files, but instead it wipes out my current file list and when I type :args I only have test.pl open.
So how can I add and remove files in my args list?
Why not use tabs (introduced in Vim 7)?
You can switch between tabs with :tabn and :tabp,
With :tabe <filepath> you can add a new tab; and with a regular :q or :wq you close a tab.
If you map :tabn and :tabp to your F7/F8 keys you can easily switch between files.
If there are not that many files or you don't have Vim 7 you can also split your screen in multiple files: :sp <filepath>. Then you can switch between splitscreens with Ctrl+W and then an arrow key in the direction you want to move (or instead of arrow keys, w for next and W for previous splitscreen)
Listing
To see a list of current buffers, I use:
:ls
Opening
To open a new file, I use
:e ../myFile.pl
with enhanced tab completion (put set wildmenu in your .vimrc).
Note: you can also use :find which will search a set of paths for you, but you need to customize those paths first.
Switching
To switch between all open files, I use
:b myfile
with enhanced tab completion (still set wildmenu).
Note: :b# chooses the last visited file, so you can use it to switch quickly between two files.
Using windows
Ctrl-W s and Ctrl-W v to split the current window horizontally and vertically. You can also use :split and :vertical split (:sp and :vs)
Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l) to navigate through open windows.
Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one.
Starting vim with a -o or -O flag opens each file in its own split.
With all these I don't need tabs in Vim, and my fingers find my buffers, not my eyes.
Note: if you want all files to go to the same instance of Vim, start Vim with the --remote-silent option.
:ls
for list of open buffers
:bp previous buffer
:bn next buffer
:bn (n a number) move to n'th buffer
:b <filename-part> with tab-key providing auto-completion (awesome !!)
In some versions of vim, bn and bp are actually bnext and bprevious respectively. Tab auto-complete is helpful in this case.
Or when you are in normal mode, use ^ to switch to the last file you were working on.
Plus, you can save sessions of vim
:mksession! ~/today.ses
The above command saves the current open file buffers and settings to ~/today.ses. You can load that session by using
vim -S ~/today.ses
No hassle remembering where you left off yesterday. ;)
To add to the args list:
:argadd
To delete from the args list:
:argdelete
In your example, you could use :argedit test.pl to add test.pl to the args list and edit the file in one step.
:help args gives much more detail and advanced usage
I use buffer commands - :bn (next buffer), :bp (previous buffer) :buffers (list open buffers) :b<n> (open buffer n) :bd (delete buffer). :e <filename> will just open into a new buffer.
I think you may be using the wrong command for looking at the list of files that you have open.
Try doing an :ls to see the list of files that you have open and you'll see:
1 %a "./checkin.pl" line 1
2 # "./grabakamailogs.pl" line 1
3 "./grabwmlogs.pl" line 0
etc.
You can then bounce through the files by referring to them by the numbers listed, e.g.
:3b
or you can split your screen by entering the number but using sb instead of just b.
As an aside % refers to the file currently visible and # refers to the alternate file.
You can easily toggle between these two files by pressing Ctrl Shift 6
Edit: like :ls you can use :reg to see the current contents of your registers including the 0-9 registers that contain what you've deleted. This is especially useful if you want to reuse some text that you've previously deleted.
Vim (but not the original Vi!) has tabs which I find (in many contexts) superior to buffers. You can say :tabe [filename] to open a file in a new tab. Cycling between tabs is done by clicking on the tab or by the key combinations [n]gt and gT. Graphical Vim even has graphical tabs.
Things like :e and :badd will only accept ONE argument, therefore the following will fail
:e foo.txt bar.txt
:e /foo/bar/*.txt
:badd /foo/bar/*
If you want to add multiple files from within vim, use arga[dd]
:arga foo.txt bar.txt
:arga /foo/bar/*.txt
:argadd /foo/bar/*
Many answers here! What I use without reinventing the wheel - the most famous plugins (that are not going to die any time soon and are used by many people) to be ultra fast and geeky.
ctrlpvim/ctrlp.vim - to find file by name fuzzy search by its location or just its name
jlanzarotta/bufexplorer - to browse opened buffers (when you do not remember how many files you opened and modified recently and you do not remember where they are, probably because you searched for them with Ag)
rking/ag.vim to search the files with respect to gitignore
scrooloose/nerdtree to see the directory structure, lookaround, add/delete/modify files
EDIT: Recently I have been using dyng/ctrlsf.vim to search with contextual view (like Sublime search) and I switched the engine from ag to ripgrep. The performance is outstanding.
EDIT2: Along with CtrlSF you can use mg979/vim-visual-multi, make changes to multiple files at once and then at the end save them in one go.
Some answers in this thread suggest using tabs and others suggest using buffer to accomplish the same thing. Tabs and Buffers are different. I strongly suggest you read this article "Vim Tab madness - Buffers vs Tabs".
Here's a nice summary I pulled from the article:
Summary:
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.
To change all buffers to tab view.
:tab sball
will open all the buffers to tab view. Then we can use any tab related commands
gt or :tabn " go to next tab
gT or :tabp or :tabN " go to previous tab
details at :help tab-page-commands.
We can instruct vim to open ,as tab view, multiple files by vim -p file1 file2.
alias vim='vim -p' will be useful.
The same thing can also be achieved by having following autocommand in ~/.vimrc
au VimEnter * if !&diff | tab all | tabfirst | endif
Anyway to answer the question:
To add to arg list: arga file,
To delete from arg list: argd pattern
More at :help arglist
When using multiple files in vim, I use these commands mostly (with ~350 files open):
:b <partial filename><tab> (jump to a buffer)
:bw (buffer wipe, remove a buffer)
:e <file path> (edit, open a new buffer>
pltags - enable jumping to subroutine/method definitions
You may want to use Vim global marks.
This way you can quickly bounce between files, and even to the marked location in the file. Also, the key commands are short:
'C takes me to the code I'm working with,
'T takes me to the unit test I'm working with.
When you change places, resetting the marks is quick too:
mC marks the new code spot,
mT marks the new test spot.
If using only vim built-in commands, the best one that I ever saw to switch among multiple buffers is this:
nnoremap <Leader>f :set nomore<Bar>:ls<Bar>:set more<CR>:b<Space>
It perfectly combines both :ls and :b commands -- listing all opened buffers and waiting for you to input the command to switch buffer.
Given above mapping in vimrc, once you type <Leader>f,
All opened buffers are displayed
You can:
Type 23 to go to buffer 23,
Type # to go to the alternative/MRU buffer,
Type partial name of file, then type <Tab>, or <C-i> to autocomplete,
Or just <CR> or <Esc> to stay on current buffer
A snapshot of output for the above key mapping is:
:set nomore|:ls|:set more
1 h "script.py" line 1
2 #h + "file1.txt" line 6 -- '#' for alternative buffer
3 %a "README.md" line 17 -- '%' for current buffer
4 "file3.txt" line 0 -- line 0 for hasn't switched to
5 + "/etc/passwd" line 42 -- '+' for modified
:b '<Cursor> here'
In the above snapshot:
Second column: %a for current, h for hidden, # for previous, empty for hasn't been switched to.
Third column: + for modified.
Also, I strongly suggest set hidden. See :help 'hidden'.
I use the same .vimrc file for gVim and the command line Vim. I tend to use tabs in gVim and buffers in the command line Vim, so I have my .vimrc set up to make working with both of them easier:
" Movement between tabs OR buffers
nnoremap L :call MyNext()<CR>
nnoremap H :call MyPrev()<CR>
" MyNext() and MyPrev(): Movement between tabs OR buffers
function! MyNext()
if exists( '*tabpagenr' ) && tabpagenr('$') != 1
" Tab support && tabs open
normal gt
else
" No tab support, or no tabs open
execute ":bnext"
endif
endfunction
function! MyPrev()
if exists( '*tabpagenr' ) && tabpagenr('$') != '1'
" Tab support && tabs open
normal gT
else
" No tab support, or no tabs open
execute ":bprev"
endif
endfunction
This clobbers the existing mappings for H and L, but it makes switching between files extremely fast and easy. Just hit H for next and L for previous; whether you're using tabs or buffers, you'll get the intended results.
If you are going to use multiple buffers, I think the most important thing is to
set hidden
so that it will let you switch buffers even if you have unsaved changes in the one you are leaving.
I use the following, this gives you lots of features that you'd expect to have in other editors such as Sublime Text / Textmate
Use buffers not 'tab pages'. Buffers are the same concept as tabs in almost all other editors.
If you want the same look of having tabs you can use the vim-airline plugin with the following setting in your .vimrc: let g:airline#extensions#tabline#enabled = 1. This automatically displays all the buffers as tab headers when you have no tab pages opened
Use Tim Pope's vim-unimpaired which gives [b and ]b for moving to previous/next buffers respectively (plus a whole host of other goodies)
Have set wildmenu in your .vimrc then when you type :b <file part> + Tab for a buffer you will get a list of possible buffers that you can use left/right arrows to scroll through
Use Tim Pope's vim-obsession plugin to store sessions that play nicely with airline (I had lots of pain with sessions and plugins)
Use Tim Pope's vim-vinegar plugin. This works with the native :Explore but makes it much easier to work with. You just type - to open the explorer, which is the same key as to go up a directory in the explorer. Makes navigating faster (however with fzf I rarely use this)
fzf (which can be installed as a vim plugin) is also a really powerful fuzzy finder that you can use for searching for files (and buffers too). fzf also plays very nicely with fd (a faster version of find)
Use Ripgrep with vim-ripgrep to search through your code base and then you can use :cdo on the results to do search and replace
My way to effectively work with multiple files is to use tmux.
It allows you to split windows vertically and horizontally, as in:
I have it working this way on both my mac and linux machines and I find it better than the native window pane switching mechanism that's provided (on Macs). I find the switching easier and only with tmux have I been able to get the 'new page at the same current directory' working on my mac (despite the fact that there seems to be options to open new panes in the same directory) which is a surprisingly critical piece. An instant new pane at the current location is amazingly useful. A method that does new panes with the same key combos for both OS's is critical for me and a bonus for all for future personal compatibility.
Aside from multiple tmux panes, I've also tried using multiple tabs, e.g. and multiple new windows, e.g. and ultimately I've found that multiple tmux panes to be the most useful for me. I am very 'visual' and like to keep my various contexts right in front of me, connected together as panes.
tmux also support horizontal and vertical panes which the older screen didn't (though mac's iterm2 seems to support it, but again, the current directory setting didn't work for me). tmux 1.8
In my and other many vim users, the best option is to,
Open the file using,
:e file_name.extension
And then just Ctrl + 6 to change to the last buffer. Or, you can always press
:ls to list the buffer and then change the buffer using b followed by the buffer number.
We make a vertical or horizontal split using
:vsp for vertical split
:sp for horizantal split
And then <C-W><C-H/K/L/j> to change the working split.
You can ofcourse edit any file in any number of splits.
I use the command line and git a lot, so I have this alias in my bashrc:
alias gvim="gvim --servername \$(git rev-parse --show-toplevel || echo 'default') --remote-tab"
This will open each new file in a new tab on an existing window and will create one window for each git repository.
So if you open two files from repo A, and 3 files from repo B, you will end up with two windows, one for repo A with two tabs and one for repo B with three tabs.
If the file you are opening is not contained in a git repo it will go to a default window.
To jump between tabs I use these mappings:
nmap <C-p> :tabprevious<CR>
nmap <C-n> :tabnext<CR>
To open multiple files at once you should combine this with one of the other solutions.
I use multiple buffers that are set hidden in my ~/.vimrc file.
The mini-buffer explorer script is nice too to get a nice compact listing of your buffers. Then :b1 or :b2... to go to the appropriate buffer or use the mini-buffer explorer and tab through the buffers.
have a try following maps for convenience editing multiple files
" split windows
nmap <leader>sh :leftabove vnew<CR>
nmap <leader>sl :rightbelow vnew<CR>
nmap <leader>sk :leftabove new<CR>
nmap <leader>sj :rightbelow new<CR>
" moving around
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
nmap <C-h> <C-w>h
I made a very simple video showing the workflow that I use. Basically I use the Ctrl-P Vim plugin, and I mapped the buffer navigation to the Enter key.
In this way I can press Enter in normal mode, look at the list of open files (that shows up in a small new window at the bottom of the screen), select the file I want to edit and press Enter again. To quickly search through multiple open files, just type part of the file name, select the file and press Enter.
I don't have many files open in the video, but it becomes incredibly helpful when you start having a lot of them.
Since the plugin sorts the buffers using a MRU ordering, you can just press Enter twice and jump to the most recent file you were editing.
After the plugin is installed, the only configuration you need is:
nmap <CR> :CtrlPBuffer<CR>
Of course you can map it to a different key, but I find the mapping to enter to be very handy.
I would suggest using the plugin
NERDtree
Here is the github link with instructions.
Nerdtree
I use vim-plug as a plugin manager, but you can use Vundle as well.
vim-plug
Vundle
When I started using VIM I didn't realize that tabs were supposed to be used as different window layouts, and buffer serves the role for multiple file editing / switching between each other. Actually in the beginning tabs are not even there before v7.0 and I just opened one VIM inside a terminal tab (I was using gnome-terminal at the moment), and switch between tabs using alt+numbers, since I thought using commands like :buffers, :bn and :bp were too much for me. When VIM 7.0 was released I find it's easier to manager a lot of files and switched to it, but recently I just realized that buffers should always be the way to go, unless one thing: you need to configure it to make it works right.
So I tried vim-airline and enabled the visual on-top tab-like buffer bar, but graphic was having problem with my iTerm2, so I tried a couple of others and it seems that MBE works the best for me. I also set shift+h/l as shortcuts, since the original ones (moving to the head/tail of the current page) is not very useful to me.
map <S-h> :bprev<Return>
map <S-l> :bnext<Return>
It seems to be even easier than gt and gT, and :e is easier than :tabnew too. I find :bd is not as convenient as :q though (MBE is having some problem with it) but I can live with all files in buffer I think.
Most of the answers in this thread are using plain vim commands which is of course fine but I thought I would provide an extensive answer using a combination of plugins and functions that I find particularly useful (at least some of these tips came from Gary Bernhardt's file navigation tips):
To toggle between the last two file just press <leader> twice. I recommend assigning <leader> to the spacebar:
nnoremap <leader><leader> <c-^>
For quickly moving around a project the answer is a fuzzy matching solution such as CtrlP. I bind it to <leader>a for quick access.
In the case I want to see a visual representation of the currently open buffers I use the BufExplorer plugin. Simple but effective.
If I want to browse around the file system I would use the command line or an external utility (Quicklsilver, Afred etc.) but to look at the current project structure NERD Tree is a classic. Do not use this though in the place of 2 as your main file finding method. It will really slow you down. I use the binding <leader>ff.
These should be enough for finding and opening files. From there of course use horizontal and vertical splits. Concerning splits I find these functions particularly useful:
Open new splits in smaller areas when there is not enough room and expand them on navigation. Refer here for comments on what these do exactly:
set winwidth=84
set winheight=5
set winminheight=5
set winheight=999
nnoremap <C-w>v :111vs<CR>
nnoremap <C-w>s :rightbelow split<CR>
set splitright
Move from split to split easily:
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
if you're on osx and want to be able to click on your tabs, use MouseTerm and SIMBL (taken from here). Also, check out this related discussion.
You can be an absolute madman and alias vim to vim -p by adding in your .bashrc:
alias vim="vim -p"
This will result in opening multiple files from the shell in tabs, without having to invoke :tab ball from within vim afterwards.
To open 2 or more files with vim type: vim -p file1 file2
After that command to go threw that files you can use CTRL+Shift+↑ or ↓ , it will change your files in vim.
If u want to add one more file vim and work on it use: :tabnew file3
Also u can use which will not create a new tab and will open file on screen slicing your screen: :new file3
If u want to use a plugin that will help u work with directories
and files i suggest u NERDTree.
To download it u need to have vim-plug so to download other plugins also NERDTree to type this commands in your ~/.vimrc.
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'scrooloose/nerdtree'
call plug#end()
Then save .vimrc via command :wq , get back to it and type: :PlugInstall
After that the plugins will be installed and u could use your NERDTree with other plugins.

How to use vim in the terminal?

How does one setup and start using vim in the terminal on OS X?
I want to start writing my C code using vim in the terminal rather than a separate text editor. How does one get started on this?
The basics like: opening, creating, saving files via terminal using vim and writing code using vim. Also, does one compile directly using vim in the terminal?
Get started quickly
You simply type vim into the terminal to open it and start a new file.
You can pass a filename as an option and it will open that file, e.g. vim main.c. You can open multiple files by passing multiple file arguments.
Vim has different modes, unlike most editors you have probably used. You begin in NORMAL mode, which is where you will spend most of your time once you become familiar with vim.
To return to NORMAL mode after changing to a different mode, press Esc. It's a good idea to map your Caps Lock key to Esc, as it's closer and nobody really uses the Caps Lock key.
The first mode to try is INSERT mode, which is entered with a for append after cursor, or i for insert before cursor.
To enter VISUAL mode, where you can select text, use v. There are many other variants of this mode, which you will discover as you learn more about vim.
To save your file, ensure you're in NORMAL mode and then enter the command :w. When you press :, you will see your command appear in the bottom status bar. To save and exit, use :x. To quit without saving, use :q. If you had made a change you wanted to discard, use :q!.
Configure vim to your liking
You can edit your ~/.vimrc file to configure vim to your liking. It's best to look at a few first (here's mine) and then decide which options suits your style.
This is how mine looks:
To get the file explorer on the left, use NERDTree. For the status bar, use vim-airline. Finally, the color scheme is solarized.
Further learning
You can use man vim for some help inside the terminal. Alternatively, run vimtutor which is a good hands-on starting point.
It's a good idea to print out a Vim Cheatsheet and keep it in front of you while you're learning vim.
Run vim from the terminal. For the basics, you're advised to run the command vimtutor.
# On your terminal command line:
$ vim
If you have a specific file to edit, pass it as an argument.
$ vim yourfile.cpp
Likewise, launch the tutorial
$ vimtutor
You can definetely build your code from Vim, that's what the :make command does.
However, you need to go through the basics first : type vimtutor in your terminal and follow the instructions to the end.
After you have completed it a few times, open an existing (non-important) text file and try out all the things you learned from vimtutor: entering/leaving insert mode, undoing changes, quitting/saving, yanking/putting, moving and so on.
For a while you won't be productive at all with Vim and will probably be tempted to go back to your previous IDE/editor. Do that, but keep up with Vim a little bit every day. You'll probably be stopped by very weird and unexpected things but it will happen less and less.
In a few months you'll find yourself hitting o, v and i all the time in every textfield everywhere.
Have fun!
if you want to open all your .cpp files with one command, and have the window split in as many tiles as opened files, you can use:
vim -o $(find name ".cpp")
if you want to include a template in the place you are, you can use:
:r ~/myHeaderTemplate
will import the file "myHeaderTemplate in the place the cursor was before starting the command.
you can conversely select visually some code and save it to a file
select visually,
add w ~/myPartialfile.txt
when you select visualy, after type ":" in order to enter a command, you'll see "'<,'>" appear after the ":"
'<,'>w ~/myfile $
^ if you add "~/myfile" to the command, the selected part of the file will be saved to myfile.
if you're editing a file an want to copy it :
:saveas newFileWithNewName
If you want to learn by reading yourself:
Open MacOS terminal app.
Write this and press enter -> vimtutor
For quit write this and click -> :q

Are these NotePad++ features available in TextMate?

I'm a NotePad++ user, new to TextMate.
There are some features that I really like in NP++ but couldn't figure out if TextMate support them.
Double click on a variable and have all instances highlighted
View 2 text windows side by side
Drag a file onto another opened Window
For this one, I don't know how to generate a screenshot ;-p. Basically, you can drag a file from Windows Explorer and drop it into NP++ to have it opened.
A lot of long time TextMate users are leaving TextMate land, actually. So, I'm not sure it's the right time to move to TextMate.
Emacs and Vim both do what you want and more. If you can afford the learning curve it's definitely worth it.
As for your question:
View 2 text windows side by side
You can have two or more windows for the same document. Assuming you are in a "project" right-click your file in the drawer and choose Open "foo.ext" in New Window. The two "views" contents are more or less in sync but doing cool things like columnar editing tends to break the syncing.
Due to how Mac OS X manages windows, the new window will probably be too large/too small and/or placed in a less than useful place. I use ShiftIt system wide to manage my windows and in such a case have them the same size side by side.
Double click on a variable and have all instances highlighted
What do you use this for? Is this visual highlight or non-contiguous selection?
Type ctrlw to select the word, then ⌘e to make the word your search term, then ⇧⌘f or Edit > Find > Find in Project… It will show all instances of the search term in another window. You can then "jump" to any occurence and do whatever you want.
If you only want to jump from occurence to occurence, select the word then type ⌘e then ⌘g to jump to the next occurence.
Another way is to type ctrls, a little text field appears at the bottom of your window where you can type a word and see its first occurence selected in real time. Repeatly typing ctrls will cycle through the occurences.
Drag a file onto another opened Window
You can drag & drop a file on TextMate's icon in the Dock. You can also right-click the file and choose Open with TextMate *or Open with…*. If you are in a "project" you can right-click and choose Add Existing Files…. Opening multiple files in TextMate will automatically create a "project" for you.
View 2 text windows side by side
I just tried this and it doesn't seem to recognize this functionality. the only time any sort of "add" icon came up was when I dragged the file into an open document and then released, but that resulted in adding the contents of the file into the document.
I just did a quick google search for "textmate split view" and it still doesn't seem to be supported according to some of the answers i found (one from macromates wiki).
Double click on a variable and have all instances highlighted
This also doesn't seem to be supported. This post suggests using the command + f (find), put the word into find, then command + g to jump to the next instance of that word.
There are definitely some things that can be added to textmate to make it more robust. If you are looking for something similar and are on a windows machine, you should check out e text editor. I loved that editor when I was working on a windows machine - split view is supported, but not sure about the highlighting. One thing that e also beats out textmate is the real time regular expression highlighting.

Vim Question Regarding Views

I have been reading a lot of the questions here on vim. I can't locate something that I want to do with vim but I am sure its possible.
I like vim(I am still new at it) using tabs and I have adjusted my vimrc so that H & L keys take me back and forth between tabs.
I was hoping to find a way to be able to use tab commands to open up a tab as output, so that if I am writing something in my case Ruby and I want to test it I could run it and flip to a new tab with the output. Or flip a tab to an interactive console to test code. This is possible?
As an aside is it possible to expand tabs to views so if I had two tabs open say script and output I could :spx or similar and have tabs come to split screen.
You can load the ruby output into a vim window in a couple of ways. One way would be to open a new split window and then load output of command:
" vimscript command to open new split window
wincmd n
" run ruby command and insert output at line 1
1,1!ruby foo.rb
alternatively you could get view the output on a new tab with a single window:
tabnew
1,1!ruby foo.rb
I know it's not the answer you want, but use buffers and ditch the tabs. I have a screencast going over how to use splits to manage your window.
http://lococast.net/archives/111
As for the ruby output, that seems like it might be covered here:
https://superuser.com/questions/133886/vim-displaying-code-output-in-a-new-window-a-la-textmate
In answer to your question about opening up a tab as output, I don't think there's any built in way to do this. There's the RunView plugin (see my answers to this question and this one), but I don't think that it supports using a separate tab (it works with a split window: what I think you refer to when you say 'view').
Regarding an interactive console: no, this is not possible. See :help design-not.
As for general use of Vim, try to get used to the idea of buffers and the fact that each 'view' (my term), whether it be a split window, a tab or whatever is just a means of looking at a particular buffer. You can have multiple views on a single buffer, so you can have a source file vertical split with two headers in one tab and the same source file vertically split with another header and a different bit of the same source file in another tab. This is very powerful once you get used to it. The Ctrl-W keyboard shortcuts are your friend (e.g. Ctrl-W, h to go left one window).
As for changing a tab into a split window, I don't think there's a direct way to do this (how would Vim know which tabs you wanted to join?). You can break a split into a tab with Ctrl-W + T, but to go back you'd have to create a couple of mappings. This is off the top of my head but something like this might work:
command! TakeThis let takebufnr = bufnr("")<CR>
command! SplitTaken exe 'split #' . takebufnr<CR>
nmap ,t :TakeThis<CR>
nmap ,s :SplitTaken<CR>
Then press ,t on the buffer you want to grab and ,s on the one you want to split with the 'taken' buffer.

Xcode Mark similar to emacs

Is it possible to bookmark a line in Xcode similar to the "mark" functionality in emacs? Also is there a shortcut used I can use to jump to a line number? My source code is becoming long and hard to navigate.
Yes; if you place the text caret on the line that you want to bookmark and select Edit > Add to Bookmarks (or ⌘D) you can add that line to the bookmarks in your project. You can then access these bookmarks from the Bookmarks item in the Groups & Files pane.
To go to a certain line, choose Edit > Go to Line... from the menu (or ⌘L), and type in the line number you want to navigate to.
I would also recommend that you use the #pragma mark directive to help you navigate around in source files. It takes the format:
#pragma mark <Label>
And will show up in the functions popup menu at the top of your source file; it makes it much easier to navigate around your code by grouping together common functions, improving the overall structure and readability of your code.
You can also use the "mark" key sequence, control-# or control-space, then you can use Delete to Mark (control-W), Select to Mark (control-X control-M), and Swap With Mark (control-X control-X). These emacs-like key bindings are supported in all Cocoa text views in Mac OS X, and you can customize the keybindings for Xcode in Xcode > Preferences > Key Bindings > Text Key Bindings.
You can bookmark an individual line in a file:
in your .emacs file
(global-set-key "\C-cb" 'bookmark-map)
sets it up, so:
control-c b m sets a bookmark (you can name it whatever you want.)
control-c b j jumps to a bookmark (it asks which bookmark you want)
Also:
(global-set-key [f1] 'goto-line)
sets F1 to ask for a line number and jump to that file

Resources