Disableing Vim's folder view - vim

When I enter Vim's folder view I always enter trouble, as you can see here.
Is it possible to simply disable this folder View?
So that I never have to enter it again by accident.
And if so, how do I do that?

The "folder view" is provided by the netrw plugin (cp. :help netrw-intro-browse) that is included in the default Vim installation. You can disable it by putting
:let g:loaded_netrwPlugin = 1
into your ~/.vimrc file. However, your real problem is bad :autocmds that do not handle so-called scratch buffers (i.e. artificial buffers that do not correspond to an actual file, but are used to display plugin functionality). You'll probably encounter similar problems with other plugins, too, so rather fix or remove those autocmds! Disabling netrw is just working around the problem.

Related

vim81 configuration wrong after I added .vimrc

I uninstalled vim74 and compiled vim81 and installed it. However I found it strange, comparing to vim74. When there's no .vimrc file under HOME dir, I open a c++ file and syntax highlight is working and I can use Backspace to delete letters. However when I add a .vimrc under HOME dir and just put set number into it, when the c++ source file is opened, no highlight, and Backspace not working. Why is that ? I used to add some configurations in .vimrc under vim74 before, and this situation never happens.
After complaints that Vim in its default configuration is hard to use (especially for beginners), it was decided to enable a default configuration if the user hasn't created his own ~/.vimrc (yet). This was introduced with Vim 8.0, and explains what you're seeing (namely: syntax highlighting and sensible backspace behavior). Read more about the details at :help defaults.vim.
The help also has instructions how to keep the defaults when adding your own ~/.vimrc configuration:
If you create your own .vimrc, it is recommended to add these lines somewhere
near the top:
unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim
Then Vim works like before you had a .vimrc.
Tip: Don't go all crazy with adding various snippets (especially not those you don't fully understand) and plugins to your ~/.vimrc, even though the Internet is full of them. Rather, build it up gradually, depending on needs, and back up your understanding with careful studying of the excellent :help. Also, avoid pre-packaged Vim distributions; they're even worse.

Can not switch to previous page in gvim

I have a very weird problem which did not exist in my environment before but now happened. When editing files, I'm used to doing this way:
gvim . #open current directory browsing
scroll up/down to select file, enter then edit.
ctrl-6 #back to previous directory
However one day I found the step3 was failed, it said "No alternate file".
My .vimrc file only contains:
colorscheme darkblue
set number
set autoindent
set nowrap
set ignorecase
set cursorline
I tried to clean all content in .cshrc but the same.
Can anyone tell me what's wrong with my gvim ?
Thanks in advance.
This looks to be a change in behavior introduced in Vim 7.4. The netrw view is no longer stored as an alternate file. See this discussion.
The Vim maintainers seemed split on what the correct behavior should be, but Bram himself offered up this advice with a mapping:
I do realize that editing the directory of the current file is
something I often do, but I never bothered to set up a mapping for
it. Typing ":e %:h" is not too difficult, but CTRL-O to jump back to
the netrw %directory view was easier.
I now added a mapping:
map ,d :e %:h<CR>
Let's see if I can get used to that.
Another related discussion can be found here.
You are likely using netrw to edit a directory. This is the equivalent of :Explore. Sadly netrw has a bad habit of not maintaining the alternative buffer, #. You maybe able to upgrade netrw or use :Rexplore (:Rex for short) to resume exploring.
Another option is to just use :e with wildcards and tab completion to explore files. Use <c-d> to list out completions as well.

How to map cmd+s to save all?

I'm developing some front-end project with the help of Yeoman.
I run the developing webserver by grunt serverand, because there is livereload.js in the project, for watching files change and refreshing the webpage, sometimes, I need to modify multiple files for one purpose(.html, .css, .js ...) and it's kind of waste for browser when each file saves.
So is there a way for MacVim, map cmd + s to :wa ?
nnoremap <D-s> :wa in your .vimrc should do the trick.
nnoremap means this mapping is only available in Normal mode, and is not recursive.
:wa means write all, i.e. save all the current open buffers.
If you don't want to use a new mapping, you can simply type :wa to achieve the same things, but this is a matter of preferences only.
I know this is old but I came searching with the same question.
tl;dr: ⌥+⌘+S to save all.
You can, supposedly, map <D-s> to :wa but it's not as simple as adding the mapping to your .gvimrc file. See the third bullet below.
From the MacVim docs:
cmd-key cmd-shortcuts
Creating key mappings that involve the Cmd key ( in Vim notation) can
sometimes be slightly involved. Here are all the things you need to consider:
Make sure the shortcut is not used by a menu item by looking through the
menus. If it is then you need to unbind it before you can map to it. This
is described under the help for the |:macmenu| command.
Bindings to are case sensitive: is not the same as . If
you want to map something to Cmd+Shift+d, then you need to use , not
or .
Some command key shortcuts are reserved by Mac OS X and cannot be mapped to
(e.g. ). However, some of these shortcuts can be freed up in the
System Preferences under Keyboard (e.g. Cmd+Space).
The good news? In trying to sort this out I realized that MacVim is a very courteous MacVim indeed and implements, by default anyway, many standard Mac shortcuts including: ⌥+⌘+S for "Save All". Open MacVim, click the file menu and then hit the option key to see it in action.

how to set vim menu reload for different filetypes

i use vim to edit different filetypes.
it seems vim can load the filetype plugin correctly, for different filetypes the highlight, indent and comment are all working well.
but the menubar seems not working.
eg. i installed vim-latex, therefore after i open a .tex file, the menu-bar has all the menus Tex-suite, Tex-enviroment, Tex-Math, etc.
but when i switch back to a .py file, these menus are still there... and even the keymap for .tex file compling is still there. when i type <leader>ll, vim still compiles the .tex file in previous buffer...
How should i reset vim menus (and the keymaps) when a different filetype is loaded?
thanks!
I didn't know vim-latex before, but it looks like a powerful suite that totally takes over Vim, and currently does not support undoing its massive customizations once it's been loaded.
You can get rid of the menu via
:aunmenu TeX-Suite
and likewise remove the mapping via
:nunmap <buffer> <Leader>ll
But I guess simply quitting Vim and re-launching it is the easiest, pragmatic solution.
Of course, you can file enhancement requests against the project, but I guess this is not high on their agenda, and some people may find the toggling of the menu when switching buffers more annoying than the lingering menu.

Vim: Maintain the history of a file after it has been changed and reloaded

If I'm editing a file in Vim, then some external program changes the file, Vim tells me:
W11: Warning: File "test.erl" has changed since editing started
See ":help W11" for more info.
[O]K, (L)oad File:
If I Load the file, though, all the undo history is lost.
Is there any way to avoid that?
Update: it appears that this is one of the new features in Vim 7.3: https://groups.google.com/group/vim_announce/browse_thread/thread/66c02efd1523554b
I don't believe this is possible.
There is a very useful patch available for the vim source code available here that keeps the undo history after exiting vim and restarting. However, I've just tried it and it seems to fail when the file is edited externally. It might be worth contacting the author or reporting a bug on the patch website to see if this can be overcome.
G'day,
I'm not sure but does setting autoread, i.e. entering :set autoread leave the undo history for the file when it changes?
Hmmmm. I'm thinking probably not because the change history is maintained as line numbers and vim doesn't know if those line numbers are still relevant to the changed file.
BTW WTF are you editing a file that is being changed by external forces anyway? Sounds dangerous to me. (-:
This is a workaround I used before Vim 7.3:
" :e usually clears undo history, so we don't really do :e any more.
" Instead we delete the contents of the buffer, then read the file in, which
" is an operation we can undo. We must delete the top (empty) line also.
:map :e<Enter> :%d<Enter>:r<Enter>:0<Enter>dd
When you see the warning prompt, you would have to hit ok instead of load, and then perform the load yourself: :e<Enter>
There are two disadvantages (although I found the tradeoff acceptable):
You lose the line you were on. Your cursor is left sitting at the top of the file.
Vim still thinks the buffer is out of sync with the file, so when you next save, you may need to do :w! instead of the normal :w, and you will need to hit y to confirm the overwrite.
Edit: There might be a workaround for the second problem.
Edit: The first problem could be addressed with a bit more scripting (see :h line.)
I don't see how vim could keep track of something it didn't do.
So, as to the question, I would suggest - source control ... but that's probably not the answer you're looking for.

Resources