1

In my .vimrc-file I have these commands:

" Add normal cursor-behavior on screen
noremap  <buffer> <silent> k gk
noremap  <buffer> <silent> j gj
noremap  <buffer> <silent> 0 g0
noremap  <buffer> <silent> $ g$

So when I press j, then it goes down one visual line on the screen. However... Sometimes when I load a document, then that doesn't always work. It's strange because sometimes it works and sometimes it doesn't.

For instance, when I created a temp.txt-file on my desktop, copied in a long line and made a :vsplit (to make the screen more narrow)... Then it worked as it should.

But if I used vim ftp://username@host//, opened a file in a tab, did a :vsplit, then it didn't work! ... Here comes the strange part. I then close that file, with the ftp-connection still open. Then I repeat the exact same procedure, and then it works.

The thing that always fixes it, is to write :so $MYVIMRC. Regardless of where I am (FTP-server, locally, whereever), - then writing that, fixes it.

I tried to move the four lines to the bottom of my .vimrc-file, but with no luck. My best guess is that Vim loads some other .vimrc-file after my $MYVIMRC-file sometimes, which overwrites this command. So I checked, by writing :version, which gave this output:

system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"

Are there a way, where I can ensure that Vim, in a way, always do a :so $MYVIMRC as the last thing, after it has loaded?

I have Vim-version 7.4, compiled by Homebrew and are working on a Mac.

4
  • 1
    Try removing <buffer> keyword, I think it doesn't make sense when defined in .vimrc in global scope (without autocmd. or smth like that).
    – grodzik
    Commented Apr 13, 2017 at 11:48
  • ^that. Vimrc isn't read for each buffer that's loaded, and mappings with <buffer> are only set for that buffer, so this would only apply to the first buffer (and to any in which you manually run :so $MYVIMRC). @grodzik maybe post an answer.
    – muru
    Commented Apr 13, 2017 at 12:29
  • yeah, <buffer> makes no sense outside of autocmd. But as another aside, please note that ftp transmission is not secure and your username and password are transmitted unencrypted. Consider scp or sftp instead if this matters in your working enviroment.
    – Wolfie
    Commented Apr 13, 2017 at 12:42
  • That seems to work! Yeah, @grodzik - please post your comment as an answer.
    – Zeth
    Commented Apr 13, 2017 at 13:40

1 Answer 1

4

Remove <buffer> keyword. Adding it makes a mapping local to a buffer (:h map-<buffer>), and if used in global scope in.vimrc makes it valid for the first buffer only (or the one in which .vimrc was sourced).

2
  • What does <buffer> do, by the way?
    – Zeth
    Commented Apr 14, 2017 at 9:33
  • Like I wrote, makes mapping local to a single buffer, see help map-<buffer>
    – grodzik
    Commented Apr 14, 2017 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.