Globally Map "Escape Key" to "jj" in vim (mac) - macos

I have been using vim for awhile but I have not been able to figure out how to map the escape globally - every time I open a file, I have to map the escape key to jj like this:
:imap jj <Esc>
Is there a way to change the runtime defaults so that Esc is already mapped to jj?
I found the default.vim file, but you cannot edit it on a mac (with standard mac software). Should I download something to edit this file? Is there another easier way?
Any help is much appreciated!

The place for your local changes is called .vimrc and you typically create one in your home directory with the commands you want to execute on startup.
Run vimtutor on the (system) command line and spend a few minutes learning how to use this editor. Then dig into the facilities provided by :help in Vim. E.g. run :help vimrc in Vim.

Related

how do you enable command line editing with vim keys using mac terminal?

I'm reading this book and I really do not understand what this author is talking about. It appears that you can program your mac to go forward one character by either hitting l or ^F. I do not understand the difference between emac key stroke and vim keystroke. He also says run this command and 'place it in your $HOME/.bash_profile but I cannot figure out how to place the command in the bas_profile.
The Author is talking about make you terminal console behaves like vi, this means typing set -o vi in your terminal, the console will work similar vi. So you will be able to navigate using the motion keys of vi, use INSERT mode, x to delete, etc.
You can set that permanently if you include this command in your ~/.bash_profile file.
If you are not sure what it does, I don't recommend so.

How to map mac command key in vim?

I want to map my NERDTREE toggle to Cmd + space but I don't know what character represents Mac's command key in .vimrc. I searched and found that we can use 'D' to represent cmd key from this link, but it doesn't work.
BTW I am using vim from the terminal not MacVim.
iTerm2 can do this - here I mapped command enter to :wq
It is true that <D- maps to command key. You can see it by :help <D-.
However, this will not work in your vim+terminal. It only works in MacVim. See here
The best shot for your intention is to map the combination as hex code, sending to terminal.
Still I will not recommend doing this. command is too important for mac os environment. For example, anyone uses an input method can't map it to command+space.\
Please consider using the usual method here: <leader>.
With IdeaVim you can use: <M-*>, for example <M-c> means Cmd + c
An example of mapping CMD+p to vim's Meta P to call :CtrlP command.
This has the advantage that Meta is usually not used for anything so it won't clash with existing commands.
And on .vimrc you'd add
map <M-p> :CtrlP<CR>

Textmate tutorial terminal mac-osx

I have installed Textmate editor on my terminal and I am looking for some tutorial to discover Textmate's command lines ? Does anyone has a some links ?
Best,
Newben
The textmate bin that is optionally installed for command line access is really nothing but a simple manner to open files in the OSX gui application.
That said, there are a few handy shortcuts. -w issues a "wait" while opening the file, thus following commands in a sequence will wait until the document is closed to execute. For example:
alias bashrc="mate -w ~/.bashrc; source ~/.bashrc"
That said, if you are looking for a good command set for using within the gui itself, let me know and I will fill in a list of handy commands (it has been my default editor for 6 years now).
Edit: Here are the beginnings of my TextMate docs. I currently have the Cheat Sheet in a state that should prove useful. I will be adding to it and writing up some more extensive docs in the near future.
TextMate Cheat Sheet
You can invoke it from the command line with:
mate path/to/file/you/want/to/edit.txt
You can use more than one file, space separated. To see more options do:
mate --help
This if you installed the commandline option. which you can also do from preferences at any time (its just a symlink)

Vim: Mac vs. Linux ^M Problem

I use Vim and GIT to develop my project on a Linux/Ubuntu machine. In the past, I used to use Windows, which means line ends were DOS format. Now after moving to Linux, I always see ^M confusing/annoying characters at the end of the line. Some people here:
How to convert the ^M linebreak to 'normal' linebreak in a file opened in vim?
suggested that I should make a find/replace or use tools like dos2unix. These are good suggestions, but with a version-controlled project it means I have to add unnecessary commits for the files after change, and it is a big task anyway that is not worth spending time on it. So:
Is there anyway to make Vim tolerant for this? That is, if the file is DOS line-ended, it keeps it like this, and use its formatting for new newlines, and so on.
I have added this line to my .vimrc file.
set fileformats=unix,mac,dos
If you don't know what a vimrc file is, it's simply the file that configure (and allows you to customize) your vim. By default vim will be looking for a file called .vimrc (notice the dot at the beginning) in the user's home folder. If it cannot find it, it will source it from /etc/vimrc.
Yes, you can set the following in vim to say it's a dos format file:
:set ff=dos
And, likewise:
:set ff=unix
The best answer I found is #Keith answer in the comments:
"With subversion you can set a property svn:eol-style=native that will cause it to convert line endings to.. native type for all platforms automatically. I don't know if git has that feature, but you might look into that first. It probably does."
And these links might be useful link is how to set:
http://help.github.com/dealing-with-lineendings/
http://git-scm.com/docs/gitattributes

How do I open a file in Vim from inside a Conque shell

Often I find my self navigating the filesystem from a Conque shell in Vim and want to open a specific file inside my existing MacVim session. Is this possible ? - I was hoping for something like:
shell> open some/file.txt
and then have file.txt pop up inside my existing Vim window (preferably in a new tab).
Note: I am using #wycats vim dot files (not sure this matters).
Type from ConqueShell
mvim --remote-tab-silent filename
This will open the file in a new tab in MacVim
You could also write a Bash alias to shorten the command (assuming you are using bash).
Put in your ~/.profile
alias vim='mvim --remote-tab-silent'
this would enable you to type
vim filename
from ConqueShell or bash, and have it open in a new MacVim tab, rather than terminal vim. It of course does disable your ability to run standard vim (although you could still use the vi command), so maybe you would want to name the alias differently.
Just to add, this will work only if you placed the mvim executable on your path E.G. /usr/bin/mvim. It comes with the MacVim.app
Often I find my self navigating the filesystem from a Conque shell
The beauty of running a shell from inside vim is you have all of vim and the shell at your disposal.
gf is your friend. Once you get the file you want displayed on the screen in some way, you can enter normal mode, move the cursor to the file you want to edit, then use the gf command to navigate to the file. There are many ways to use this. Any program or command that outputs file names is great for this (ll, git status, etc). You could also type the filename into the shell, just to make it visible on the screen without actually running any terminal commands (tab completion is handy here).
It is possible, you can start vim as server and then add as many files as you want, but I'm not very familiar with this, so I can't give you just a direction.

Resources