Toggling line numbers in vimrc doesn't work - vim

I'm new to vim.
I'm using MacVim.
I use
:set number
which shows line numbers.
I've added
set number
to my vimrc, to make show line numbers by default.
My vimrc:
no <down> <Nop>
no <left> <Nop>
no <right> <Nop>
no <up> <Nop>
ino <down> <Nop>
ino <left> <Nop>
ino <right> <Nop>
ino <up> <Nop>
set number
But line numbers don't show up.
Everything in vimrc except set number works fine. What am I doing wrong?

Problem was that I had one .vimrc in the ~/ and one in the ~/.vim/.vimrc.
The one that was in the ~/ was overriding the one in in ~/.vim/.vimrc.

I'd comment but I'm not allowed :(
I usually have had that problem when either the file or the line is corrupted or has Ctrl characters or in someversions of Unix if there was a space in the wrong place
try :set list and make sure there isn't a Tab, missing Line Feed or something
There's a way of viewing the Control Characters that don't display in :set list but can't remember it.
Shove comes to push delete the line and the one above and below. Save and retype it andsee if it fixes it.

Related

Different up/down key functions in different modes in vim

I am using following code in my init file :
noremap <Up> gk
noremap! <Up> <C-O>gk
noremap <Down> gj
noremap! <Down> <C-O>gj
(from: http://vim.wikia.com/wiki/Moving_by_screen_lines_instead_of_file_lines)
This is to move the cursor one 'displayed line up' and not to one line up when using up key. Similar for down key.
However, now when I go to command mode and press ':' to insert a command, I cannot use up key to get previous command. Is there any way to get previous commands with up and down keys while using above code for insert mode? Thanks for your help.
Edit: The output of :verbose cmap <Up> is:
<Up> * <C-O>gk
In the Vim configuration file, the lines
noremap! <Up> <C-O>gk
noremap! <Down> <C-O>gj
will affect the Insert mode and Command-line mode. So If you want it to only affect the Insert mode, you can chanage it with
inoremap <Up> <C-O>gk
inoremap <Down> <C-O>gj
You can check the help with :help noremap! to inspect the modes it works.

Vim map failed unless reload .vimrc

I want to do the following maps in my .vimrc.local
```
inoremap <C-H> <Left>
nnoremap <C-H> <C-W><C-H>
inoremap <C-J> <Down>
inoremap <C-K> <Up>
inoremap <C-L> <Right>
```
When I restart my vim, the fist two mapping failed, and the last three commands succeeded. However, when I source ~/.vimrc.local, then all the five mapping methods are OK. That means, I need to load my .vimrc.local myself.
I've already write source ~/.vimrc.local in my .vimrc . And if I source ~/.vimrc rather than .vimrc.local, it works as well.
What's wrong with my mapping? Is there any conflict? I searched in my .vimrc and .vimrc.local, but didn't find conflicts.
I'm using OS X 10.9 and MacVim Snapshot 71, and the main .vimrc from spf13. There are my .vimrc and .vimrc.local.
How can I do the mapping without manually reload .vimrc?
Thanks!

Vim cannot rebind Home/End keys

I'd like <Home> to perform g<Home> and have tried
map <Home> g<Home>
noremap <Home> g<Home>
map <Home> g^
noremap <Home> g^
map <home> g<home>
noremap <home> g<home>
map <home> g^
noremap <home> g^
Nothing seems to work, the behavior stays the same. At any point I am able to type g+Home to do the right thing (go to home/end of soft line in wrapped file)
typing Ctrl+VHome yields ^[[1~ (and End yields ^[[4~).
I bound it like this:
noremap <ESC>[1~ g^
Please check my answer to a similar question, Can't map Home button in vimrc, maybe it helps.
In special:
From :h xterm-end-home-keys:
On some systems (at least on FreeBSD with XFree86 3.1.2) the codes that the
<End> and <Home> keys send contain a <Nul> character. To make these keys send
the proper key code, add these lines to your ~/.Xdefaults file:
*VT100.Translations: #override \n\
<Key>Home: string("0x1b") string("[7~") \n\
<Key>End: string("0x1b") string("[8~")
If that doesn't work, you could try :set t_kh=^V^[[1~. If it work you can enclose it on a check of your terminal type.
Additional information can be found at :h terminal options

Arrow keys in vim (linux) in insert mode broken for me

When I use the arrow keys in vim in insert mode I get letters inserted instead of movement.
Up produces an A
Down produces a B
Left products a D
Right produces a C
Does anyone know what would cause this?
Thanks in advance
If these keys work fine in normal mode, but do not in insert then you must have some mappings to the first one or two characters (normally <Up> is either <Esc>[A (terminals that use CSI) or <Esc>OA (xterm)). Try checking out output of
verbose imap <Esc>
, there should be not much mappings starting with <Esc> in insert mode (I have none, for example). I can say, that with arrow keys working normally in insert mode, using
inoremap <Esc> <Esc>
produces just the same behavior as if you had problems with terminal recognition or had 'compatible' set.
Your vim seems to be starting in the vi compatibility mode. Do this
Open Vim editor,
Get the path of your home directory by typing :echo $HOME
Check if you have .vimrc file in $HOME location,(if you don't have create it)
Add the following line line to .vimrc file
:set nocompatible
Find more solutions for the same problem here ( Especially if your problem is terminal related, the re-mapping of keys solution might work for you )
The following worked for me. Just put it in your .vimrc
:set term=cons25
Open Vim editor.
Get the path of your home directory by typing: :echo $HOME.
Check if you have .vimrc file in $HOME location, and if you don't have create it.
Add the following line line to .vimrc file: :set nocompatible
Reference: http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell
None of the answer here worked for me. I'm in Linux, with konsole/yakuake terminal and tmux. This fix works for me:
nnoremap <silent> <ESC>OA <ESC>ki
nnoremap <silent> <ESC>OB <ESC>ji
nnoremap <silent> <ESC>OC <ESC>hi
nnoremap <silent> <ESC>OD <ESC>li
inoremap <silent> <ESC>OA <ESC>ki
inoremap <silent> <ESC>OB <ESC>ji
inoremap <silent> <ESC>OC <ESC>hi
inoremap <silent> <ESC>OD <ESC>li

VIM - Move through wrapped lines (in insert mode)

I'm not a fan of 80(or 72) characters pr. line followed by a line-break even if your VIM inserts the line-break itself - you'll easily run into inconsistency problems when editing that line of text afterwards. Otherwise I have nothing against the editor, but somehow editing text as I do in a GUI editor makes me sleep better at night.
So, I discovered that the reason for the line breaks was primarily due to inability to move through softly wrapped lines, and hence I found this article: http://vim.wikia.com/wiki/Move_through_wrapped_lines which works, but I'm looking for a solution that would work in insert-mode as well as edit-mode.
P.S. I'm probably a newbie at VIM :)
Why would you need to move through wrapped lines in insert mode? You'd better move through such lines in command mode with gj and gk and when you need to edit something, press i, edit and go out of insert mode.
The less time you'll be spending in insert mode, the better.
imap <Down> <C-o>gj
and
imap <Up> <C-o>gk
works for me.
My configuration is as follows:
vmap <silent> <Right> l
vmap <silent> <Left> h
vmap <silent> <Up> gk
vmap <silent> <Down> gj
nmap <silent> <Right> l
nmap <silent> <Left> h
nmap <silent> <Up> gk
nmap <silent> <Down> gj
imap <silent> <Up> <C-o>gk
imap <silent> <Down> <C-o>gj
My complete configuration is here:
https://github.com/Waxolunist/vimconf

Resources