Sometimes Vim plugins suggest a load order, but Vim nowaday natively supports loading plugins with no plugin manager. You just put a submodule in a folder such as ~/.vim/pack/vendor/start and it'll automatically load. So, my question is how do you ensure a load order similar to how people would previously. Older way of doing things example below:
Plug 'preservim/nerdtree' |
\ Plug 'Xuyuanp/nerdtree-git-plugin' |
\ Plug 'ryanoasis/vim-devicons'
Taken from https://github.com/Xuyuanp/nerdtree-git-plugin#faq.
Let's try a little experiment…
Create the following dummy files with their corresponding content:
Filepath
Content
pack/dummy/start/nerdtree/plugin/foo.vim
echom "nerdtree"
pack/dummy/start/nerdtree-git-plugin/plugin/bar.vim
echom "nerdtree-git-plugin"
pack/dummy/start/vim-devicons/plugin/baz.vim
echom "vim-devicons"
Start Vim and you should see something like the following:
$ vim
nerdtree
nerdtree-git-plugin
vim-devicons
Press ENTER or type command to continue
which is consistant with:
:filter dummy scriptnames
40: ~/.vim/pack/dummy/start/nerdtree/plugin/foo.vim
41: ~/.vim/pack/dummy/start/nerdtree-git-plugin/plugin/bar.vim
42: ~/.vim/pack/dummy/start/vim-devicons/plugin/baz.vim
Press ENTER or type command to continue
Based on this experiment, we can conclude that the built-in "package" feature will "load" plugins found in start/ in the filesystem order which happens to be the same as the prescribed order anyway. Of course, your filesystem may order directories differently than mine, so YMMV.
In theory, the :help :packadd command should allow you to "manage" your plugins from your vimrc, like you would with a plugin manager. Let's experiment with it…
Rename start/ to opt/:
pack/dummy/opt/nerdtree/
pack/dummy/opt/nerdtree-git-plugin/
pack/dummy/opt/vim-devicons/
Add the following lines to your vimrc after any syntax on or filetype on line:
packadd! nerdtree
packadd! nerdtree-git-plugin
packadd! vim-devicons
Start Vim:
$ vim
vim-devicons
nerdtree-git-plugin
nerdtree
Press ENTER or type command to continue
What?
Well… I guess you could experiment with ordering, here, until you get the desired order but that reverse order looks like a bug to me.
Related
As part of learning Haskell, for fun I'm attempting to use Raspberry PI. Having encountered a myriad of issues installing ghci on the PI I've resolved to using just ghc.
So to create, compile & run a new Haskell file :
vi first.hs
i
main = putStrLn "First"
Esc
:w
:q
ghc -o first first.hs
./first
Output is : "First"
I would like to automate the commands :
Esc
:w
:q
ghc -o first first.hs
./first
Can these be added as new command from within vi / vim, something like :
:mycustomcommands
And run from within the vi / vim editor ?
Maybe you could try adding something like this to your vimrc:
function! ExecuteHS()
w
!ghc -o first %
!./first
endfunction
And to use this function you just have to call it like that :call ExecuteHS(). Vim will be put on background during the execution of your file and will then come back on foreground at the end of the execution.
As a bonus you can add the folowing line to your vimrc
nnoremap <key> :call ExecuteHS()<CR>
Replacing <key> with your prefered key combination <Leader>e for example. This way you'll simply have to hit ,e (if you didn't changed your leader key) in normal mode to call the function.
That's probably not the cleanest way to do it but it should work for what you want.
Absolutely in vim, though not necessarily in other vi flavors. See this tutorial on defining custom commands. Put the custom command in your vimrc and it will always be available as :Customcmd or whatever you call it. For one-button access, you can use :remap to assign a hotkey to your custom command or the sequence of built-in commands you want to run. This is a tutorial on keymappings that will give you more information.
I second #statox's referral to https://vi.stackexchange.com :)
I use vim-haskell, which includes a couple nice things. In particular, it includes a file for setting up cabal-install as the compiler, which is a very nice way of working. Dump this in ~/.vim/compiler/cabal-build.vim:
CompilerSet makeprg=cabal\ build
CompilerSet errorformat=
\%W%f:%l:%c:\ Warning:%m,
\%W%f:%l:%c:\ Warning:,
\%E%f:%l:%c:%m,
\%E%f:%l:%c:,
\%C\ \ %#%m,
\%-G%.%#,
\%-G%.%#
And this in ~/.vim/ftplugin/haskell.vim:
compiler cabal-build
(The argument to compiler should match the name of the file you put in ~/.vim/compiler.) Then you can run :make in vim and it will save any changed buffers (assuming autowrite is set) and build your project. When there are errors, it will populate the quick-fix list, which lets you jump to the specific file and line numbers of each error or warning with a key. Read more about this feature with :help quickfix. Once everything is working, you can :!cabal run to run it.
I have installed cvim and NodeTree plugins and generated an exuberant ctags file for my build tree.
This is what my ~/.vim/.vimrc file looks like:
:noremap :TlistToggle
:let Tlist_Show_One_File = 1
:let Tlist_Exit_OnlyWindow = 1
:let Tlist_Use_Right_Window = 1
set tags=./tags;/
set number
set tabstop=4
set incsearch
When I start editing a file, I notice that Ctrl ] does not work and I have to resort to typing ta: funcname - which gets tiring after a while. Interestingly enough, Ctrl T pops me off the tag stack as expected - I don't understand whats going on - how do I fix this?
Incidentally, vim (appears to) completely ignores the contents of my .vimrc file and I always have to type the same commands in the editor, so as to get the settings I want - very annoying.
Last but not the least, I used to be able to type :make in the editor window, drop to the console and then have the build results displayed in a little window which I can then go to and select a line (with an error or warning say), and then have the editor automagically take me to the offending line - unfortunately, I don't remember the plugin (or commands) I used to allow me to build from within vim.
So, how do I:
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
Fix my .vimrc file so that contents are actually applied to my vim session.
Find the appropriate plugin to install to allow builds (using make) from within vim
You're asking about a weird mix of problems.
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
The tags functionality is working; I suspect that you have a mapping blocking Ctrl-]. Try
:verbose nmap <C-]>
and
:nunmap <C-]>
Fix my .vimrc file so that contents are actually applied to my vim session.
:echo $MYVIMRC
will tell you the location of the .vimrc that Vim uses. Also, check the output of :scriptnames which scripts get loaded, and read :help vimrc to understand the logic Vim applies.
Find the appropriate plugin to install to allow builds (using make) from within vim
That's built into Vim. With the appropriate 'makeprg' set (it defaults to make), you can run :make. Vim parses the output (through the 'errorformat' option), and you can open the quickfix list via :copen.
Your vimrc is:
~/.vim/.vimrc
If you run Vim 7.4, it should be:
~/.vim/vimrc
or
~/.vimrc
If you run Vim 7.3 or older, it should be:
~/.vimrc
And... what Ingo said.
I code in Vim, not an IDE.
My source code is often nested 2-3 directories deep.
~/foo$ find
xyz
bar/abc
bar/def
~/foo$ vim
// inside of vim
:e bar/abc
... some work ...
:e <-- is there a way I can have this :e start in ~/foo/bar instead of ~/foo ?
Basically, I want :e to start the directory in "pathname of last edited file"
Thanks!
There's a lot of reasons not to like autochdir as it messes up some plugins and if you end up doing :e ../../../foo.txt you are not gaining anything. Just as an idea try this cmap I knocked up
:cnoremap red edit <c-r>=expand("%:h")<cr>/
then you can type :red and get
:e /the/path/to/your/current/files/dir/
(edit: perhaps use z instead of red as there are commands that start with red)
To expand the topic, also check out the FuzzyFinder plugin and some custom mappings to rapidly jump to common files you are always editing. Eg
10 or so of your regular files should be no more than 2 keystrokes away. It helps if they are systematically named
Here's an idea I use for django.
http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings
Try the autochdir option. It will automatically change the current working directory to whatever file was most recently opened or selected. In .vimrc:
set autochdir
For more info, :help autochdir
To always change the working directory to the current file's directory I have this in my .vimrc:
if has("autocmd")
autocmd BufEnter * :lcd %:p:h
endif " has("autocmd")
Sorry, but vim's :edit command takes a path which is interpreted relative to the present working directory of the vim instance.
You do have a :cd command which you could use to :cd bar then work for a while, then :cd ...
Hope that help some.
Some time ago I asked questions related to this on the vim mailing list: http://www.mail-archive.com/vim_use#googlegroups.com/msg03266.html Maybe you will find useful tips in that thread.
I tested a lot of plugins, but since CLI based GUIs are not my taste, I simply ended up using standard vim with a few configuration settings.
As honk pointed out, this line sets the working directory to the same as the file your working on:
autocmd BufEnter * lcd %:p:h
My other tip is to use the wildmenu. It makes it easier to get an overview of the files in your current directory when you go :e and then TAB. I'm a python programmer so the last line shows how to hide auto generated files that the python interpreter spits out, but you could use it to hide java .class files or c .obj files or whatever.
set wildmode=list:longest
set wildignore=*.pyc,*pyo
:cd changes directory
:pwd prints the current one.
why not just :E? Explore directory of current file.
:help :E
This isn't exactly what you wanted, but check out NERDTree.
On vim/gVim I just have cd C:/blah/blah at the top of my vimrc. I imagine it works on all platforms.
I personally use vagrant for each project so one CD is enough, but I think you can get vim to use different config files too, -u flag I think.
Or map a key to each project you have so pressing Ctrl+F1 does cd path/to/project/1 and Ctrl+F2 does cd path/to/project/2 perhaps?
Note: I don't use any plugins
By making use of the remote feature in vim, is it possible to reuse an instance of vim to load up multiple files as needed.
It will be nice to have that facility from within the same terminal instance.
I am more keen to have a tab based interface, which available in vim 7+
The scenario should be
Open terminal
vim file1.cpp
Edit - Save - Ctrl+Z to get to prompt
open another file
vim file2.cpp
Now we have file1.cpp and file2.cpp open in the same editor
Is that possible?!
I'm not sure if this can be done in exactly the manner that you're specifying, but something very similar can probably be done using a vim server running on your local machine.
Look into the :help remote.txt in Vim.
If your version of vim was compiled with +clientserver you can use vim to create a vim server, and then execute commands on it, e.g. opening another file.
The --servername switch can create a new server, and the --remote switch can send additional commands or files to it.
e.g.
vim --servername test file1.txt
vim --servername test --remote file2.txt
I've had a look, and the vim I'm using as standard on xubuntu on one of my computers doesn't have it, but there are some instructions here that may help if yours has it compiled. If it isn't, installing gvim and symlinking is apparently an option (as gvim has it included by default), or compiling the binaries from source.
Edit:
I've had more of a play with gvim and this doesn't look possible to do this within the terminal. Control-Z suspends the job at the process level. I thought it might work with screen, but no communication seems to take place unless gvim has launched in a graphical window,
This is easy to do if you compiled VIM with +clientserver, as Andy suggested in a previous answer.
I did the following:
I started up VIM as a server:
vim --servername abc
I suspended it with CTRL+Z and did:
vim --servername abc --remote ~/.cshrc
fg
Now VIM had ~/.cshrc open.
Then I did:
vim --servername abc --remote ~/.aliases
fg
Now VIM had one buffer with ~/.cshrc and another with ~/.aliases.
Then I did:
vim --servername abc --remote-tab ~/foo_bar
fg
And now I VIM had one tab with the two previous buffers open and another tab with ~/foo_bar open.
In call cases VIM was running in the terminal, not as a GUI.
I have a couple suggestions for you, though neither is exactly what you're talking about. The first is NERD Tree, which gives you a nice tree-based file browser for opening other files. Very handy. I also set up a hot key (ctrl+o) to open NERD Tree for me. I keep an alias of whatever project I'm on in ~/curr/trunk, so this always works for me:
map <C-O> :NERDTreeToggle ~/curr/trunk/<CR>
The other thing that I would suggest is to do away with ctrl+z. It's somewhat clunky, and everyone I know who uses that method tends to get lost and end up with 3 or 4 vim's running in the background. Take a look at how to open a shell for yourself. I use a map for ;s to execute a shell script:
map ;s :!~/.vim/shell.sh<CR>
Which executes:
#!/bin/sh
/usr/local/bin/bash -l;
I also have a bit of magic in my .profile for making it obvious I'm in VIM:
if [ "$VIMRUNTIME" != "" ] ; then
export PS1="\u#\h \W \t$ vim> "
fi
</2 cents>
You can split the current screen and open two (or more) files in the following way:
For a horizontal split, do:
:sp 'filename'
and for a vertical split, do:
:vsp 'filename'
To tab between the two, hit ctrl+w, then use an arrow key to navigate to whichever file you want to edit.
Also, if you want to just switch files (and only have one open), you can do this:
:e 'filename'
G'day,
Or if you want to have multiple files but use the whole vim window for one file at a time you can just enter
:e 'filename'
to open the new file. You can do this multiple times. To see what you've currently got open, enter
:ls
To bounce between the files you've got open you can use cntl-^ (shift-cnt-6) and that will alternate between the main and secondary files (shown with a % and # in the file list)
Or you can enter
:n b
where n is the number at the beginning of the file you want in the list shown by the 'ls'command.
HTH
cheers,
You can set the hidden feature on vim, to allow it to have multiple files open:
:set hidden
Then you can open as many files as you want, without bothering to save them every time you want to switch a "buffer":
:e 'filename'
You have several commands to navigate the buffers:
:bnext
:bprev
:buffers
Of course, as mentioned by samoz, you can split your screen to see multiple buffers on the same window.
I'd suggest to read this for a good introduction about vim, it will save you a lot of time.
Good luck!
I have multiple plugins in Vim and some of them modify the default behavior of Vim. For example I use Vimacs plugin, which makes Vim behave like emacs in the insert mode alone. Sometime I want to turn off the Vimacs plugin without moving the vimacs.vim out of the plugins directory. Is there a way to do it?
You can do this if you use a plugin manager like Vundle or Pathogen, which will keep the plugin in its own directory underneath the ~/.vim/bundle/ directory.
In that case, just find out the runtimepath of the vimacs plugin with the following command:
set runtimepath?
Let's say it's ~/.vim/bundle/vimacs.
Then, put this command in your .vimrc:
set runtimepath-=~/.vim/bundle/vimacs
To load vimacs, just comment that line out and relaunch Vim (or source your .vimrc).
See which variable vimacs check on start. On the begin of the script file find something Like if exists('g:vimacs_is_loaded").... Then set this variable in your .vimrc or while start vim with vim --cmd "let g:vimacs_is_loaded = 1".
In case you are using pathogen, this post gives a better answer, in my opinion. Since I have frequent need to disable snippets when using latex, also added this in my ~/.config/ranger/rc.conf:
map bs shell vim --cmd "let g:pathogen_blacklist = [ 'ultisnips', 'vim-snipmate' ]" %f
This way, whenever I want to open a file with snippets disabled, it is easy.