← Back to Upcase

.vimrc file help

my ~/.vimrc file is not being loaded.
This is the full contents of my file

imap <C-s> <esc>:w

Even further, while I’m in vim and I test a mapping like

 :nmap Q :q   

It doesn’t take effect.
I have opened and closed vim and my terminal many times.

Hello @MrNagoo, I think the issue is that you need to add <cr> which represents hitting return. Without that, Vim will type out but not execute the command.

Also, for the insert mode mapping you can use <C-o> which allows you to pop into normal mode, run a single command, and automatically go back into insert mode. Combining these, the mappings would be:

imap <C-s> <C-o>:w<cr>


nmap Q :q<cr>

My end goal is to esc out of insert mode. I just added the :w<cr> to mimic Ben’s suggestion. I like it more than the imap jk or kj escape.

Also, in the video, you said you could temporarily test a mapping while in a vim file by adding a mapping as a command :nmap key key. And it is supposed to work in the file. It does not for me. Also the ~/.vimrc still refuses to be read. All of my beginner style questions like this will be answered on my tech blog in a start to finish type of way.

It seems like I spend 95% of my time configuring and learning how to configure something, fixing something that broke. Only 5% of my time coding.

Hi @MrNagoo, if your goal is just to get out of insert mode, then you can map directly to <esc>. Adding :w<cr> will also save the file, which it doesn’t sound like you want.

You can test mappings as you list and they will work until you quit Vim (not just for the file you’re editing). Can you try running the follow from normal mode :nmap <C-u> :split<cr>, then hit <C-u> (that is the control and u keys at the same time). This should split your vim session into two windows. This will confirm things are working.

You can also test if mappings are working with another Vim command, just to be sure. If you have the following mapping in your vimrc nmap Q :q<cr> then you can check by running :verbose nmap Q and hitting enter. You should see a note about the mapping and your vimrc.

At first this stuff can be very confusing, but I promise it will become second nature soon.

Ok, so my file is really acting up.

imap <C-s> <esc>:w<cr>   DOES NOT exit insert mode and save buffer
nmap <C-u> :split<cr>   WORKS
nmap Q :q<cr>   DOES NOT WORK
imap jj <esc> WORKS

What in the world is happening.

@MrNagoo for the <C-s> it’s a shell issue. I use ZSH for example, and it just so happens that both <C-s> and <C-q> are flow controls. So I had to edit my .zshrc file to disable them.

I did this by adding stty -ixon -ixoff to my .zshrc and killing my iterm and relaunching ( source .zshrc would work as well, but i like definitives )

That’ll at least make it so that the save will work.

For the nmap Q :q you might think about doing
command! Q q instead, this is what I did in my vimrc to account for a problem between the chair and keyboard most of the time.

Though as a quick test, I added in your nmap Q :q<cr> to my vimrc and reloaded the source and it seems to work fine. However when I remove the stty settings from my zshrc and reload the source, it stops working. So this fix will fix both of your issues.

@benorenstein and @christoomey may want to make note of this as well, it seems like there are a lot of these questions popping up that this fix would answer. I know when I went through the vim trails I got hungup on it too, so I went to google to find my answers. Also evidenced by your own zshrc file: https://github.com/r00k/dotfiles/blob/master/zshrc#L18

Thanks for the update. I found out that my wasn’t working because that is what I remapped my tmux prefix to (It was suggested on the tmux trail). I’m not much of a shell pro. I guess I use Bash. I haven’t really had much of an issue.

That makes perfect sense actually… I haven’t done the tmux trail, but I have my tmux mapped to <C-a>, and have my caps lock key mapped to control within OSX itself ( who needs to type in caps? ).

If you don’t know what shell you’re using, there are a multitude of ways to find out… such as: which $SHELL which will give you the location of the binary file for it ( mine is /bin/zsh ) which says I use zsh or z shell. Knowing which shell you are using, is half the battle.