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.
Related
I'm having a weird issue with vim on Ubuntu. I've been using it for the last few weeks, trying to learn, on Windows and it behaves differently now that I'm using it on Linux.
I noticed that while in insert mode pressing backspace will delete text just like any other editor on Windows, but on Linux the text is "deleted" yet it stays there until I press ESC or write over it.
I was trying to fix this but I'm confused as to whether this is intended behaviour or not. It happens in gvim too.
The reason of this question is this, however:
I deleted my .vimrc file to see if any of my config was at fault and it fixed it. Backspace was now back to its regular self.
But then I tried creating an empty .vimrc file and that made it go back to the delayed delete. It's empty. Why the hell?
So I have no idea what's causing this. Hope my question makes sense my English ain't the best. Thanks.
Alright so looking at :h compatible I found this:
"When a |vimrc| or |gvimrc| file is found while Vim is starting up,
this option is switched off, and all options that have not been
modified will be set to the Vim defaults. Effectively, this means
that when a |vimrc| or |gvimrc| file exists, Vim will use the Vim
defaults, otherwise it will use the Vi defaults. (Note: This doesn't
happen for the system-wide vimrc or gvimrc file, nor for a file given
with the |-u| argument). Also see |compatible-default| and
|posix-compliance|."
So if I'm getting this right, running Vim with a .vimrc file should automatically set nocompatible and running it without one should set compatible... ? Whatever the case, I tried checking with :verbose set compatible? and it always says nocompatible is on so the -N flag shouldn't do anything... Yet it fixes the issue.
Without a vimrc Vim will load /usr/share/vim/vim80/defaults.vim (depending on your vim version). In this file the bs/backspace parameter is set to 2, or actually it is indent,eol,start which is the same as 2 (see :h bs)
Now if you create an empty .vimrc, defaults.vim will not be loaded, so your bs will possibly be 0.
This behaviour is described in :h defaults.vim
So to solve your problem, just put set bs=2 in your .vimrc
Alright I fixed it.
Running vim with the -N command makes it work properly. I'm not sure why but that's what's happening.
I would like to change my sort order dynamically. At times, I want my sources to be listed alphabetical, at times I want only one extension to be shown.
I can currently get it to work by editing NERDTreeSortOrder in my ~/.vimrc.
But how do I do this without re-launching VIM?
I tried just executing ":let NERDTreeSortOrder = ['new sort order']" but that doesn't really change anything. i add it to my vimrc, quit VIM and restart and it works.
By the way, if someone can tell me how to make NerdTree show only a specific extension, that would work for me too. I know I can make NERDTree not show a particular file type by adding it to ignore, but I want the other way around.
Any ideas?
You'll need to refresh the directory (after entering let NERDTreeSortOrder=[...]).
While in the NERDTree buffer, either :
r to limit the refresh to the selected directory
R to refresh from the start of the root node.
As for whitelisting specific file extensions, have at look at this question.
Have your tried source-ing your .vimrc from within vim?
:source $MYVIMRC or :source ~/.vimrc
:source can be shortened to :so, e.g. :so ~/.vimrc
I think the title says it all but just to give some context, I have this set on my .vimrc
set wildignore+=*.o,*.obj,**/.git/*,**/.svn/*,**/node_modules/**,node_modules/**,.git/*,svn/*
And from the readme:-
:CommandT
A prompt will appear at the bottom of the screen along with a file window
showing all of the files in the current directory (as returned by the
|:pwd| command).
It mentions that it should show all files in the current directory but even if I cd into any directory, Command-T still goes all the way up to my Desktop and lists all the files and folders which is not what I want. I just want to search on current working directory like it says in the readme.
I also tried checking if I was indeed in the right directory by doing :pwd and it's showing me I'm in the right directory and still lists out everything. However, if I have .git folder in my root directory then it seems to work.
Am I missing something? If it helps, I also have this in my .vimrc file:-
imap <C-t> <C-c>:CommandT<CR>
vmap <C-t> <C-c>:CommandT<CR>
nmap <C-t> :CommandT<CR>
Add this line to .vimrc file
let g:CommandTTraverseSCM='pwd'
It will search in current directory instead of SCM root directory.
Warning: This is a non-answer answer to your question.
Please take #romainl's advice and look at the plugin's issue tracker.
Documentation
Command T and all good Vim plugins come with documentation. Please read all of it before asking questions. See :h command-t. The things you might have noticed if you had:
g:CommandTScanDotDirectories - basically the default config means CommandT will not search dot directories. Meaning your 'wildignore' probably doesn't need .git/.svn/... entries.
See :h command-t-wildignore for more information on CommandT and 'wildignore'
g:CommandTTraverseSCM dictates how CommandT find its root directory. The default looks for a SCM root marker, e.g. .git. If it can't find one it will fall back to the current directory. Please look at this option for more options. You may want to use let g:CommandTTraverseSCM = 'pwd'
Mappings
I have some concerns:
You should be using *noremap style mapping unless you are mapping to a <Plug>(something) or you really want recursive mappings (Hint: not usually).
Please use <esc> instead of <c-c> as they are not the same. Sure they are similar but they are not the same.
Overshadowing the <c-t> command in normal mode which pops the tag stack.
Overshadowing the <c-t> command in insert mode which increases indentation.
Probably should not even worry about creating mappings for any mode except normal mode because that is the Vim way.
My recommendation is to use the default CommandT mappings which are <leader>t and <leader>b (See :h command-t-mappings). The <leader> defaults to \ however this changes if you change the mapleader. See :h mapleader.
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.
What does a horizontal line in vim mean? While editing a remote file I see a horizontal line in the current line.
I don't see it while editing local files
Edit:
cursorline is not shown until I save the file(:w). When I type :w and enter password, cursorline appears. Why does it have such a behavior? When I edit file in remote machine cursorline is turned off and is not shown.
As others have answered, the effect is probably being caused by the cursorline option.
You can track down what is script made the most recent change to an option by running the command set optname? under the verbose command:
:verbose set cursorline?
You will probably just find that the Netrw plugin set it; Netrw handles local directory browsing and remote directory/file access like your scp:// example. Netrw adjusts cursorline (and cursorcolumn) for its own purposes (e.g. directory listings), but it tries to restore the value to the “user value”. Unfortunately, its idea of the “user value” is captured when part of the Netrw code loads and is not updated afterwards.
My guess is that, somehow (via some other plugin, or bit of configuration), cursorline is set when Netrw loads (and captures its value), but it is later reset by the time you start editing the first file. Then, when you later save the file (:w), Netrw restores the “captured” value. Unfortunately, there does not appear to be any good way to update this “captured” value of the cursorline option (there is no “external” access to the script variable it uses, and it does not “recapture” if you manually reload the file).
What you can do, however, is explicitly load the bit of Netrw that “captures” cursorline when your desired value is active. You could do that with the following two commands early in your ~/.vimrc (possibly at the very top, if necessary—it needs to be before the first time autoload/netrw.vim would ever be used):
set nocursorline
runtime autoload/netrw.vim " will 'capture' cursorline and cursorcolumn values
Netrw will still set/reset cursorline (and cursorcolumn), but as long as the value you normally want matches the value that is active right before Netrw is loaded, then you will not notice it.
I don't quite know the simplest solution to get get netrw to really capture the right value, but at very least (since for me, nocul is right,) adding:
let g:netrw_cursorline=0
To the end of my ~/.vimrc seems to have fixed the problem for me. Hope this helps someone!
It's the cursorLine. Its appearance is defined in your colorscheme. The one on the remote machine is probably different than yours or there's a mismatch between your client/server's $TERM.
Yup, ":set cursorline" or ":set nocursorline" to turn the line on or off.
The command "vim scp://...." copies the remote file onto your local machine (i.e. machine where the "vim" process runs), then opens the file in "vim" for you to edit, then, if you have modified the file, copies the file back onto the remote system. As such, syntax highlighting etc. is determined only by "vim" on your local machine.
Files with the same syntax type (":se syn" to show current syntax highlighting scheme) are highlighted the same way. Do the files, in which you see the difference, have the same syntax type?
Version 142 of netrw.vim has fixed this bug, at least for me (vim 7.3, old netrw.vim version was 140, running under cygwin).
You can get the latest version here: http://www.vim.org/scripts/script.php?script_id=1075