I work on multiple MAC OS X systems, which do not save changes after log out. As you know VIM is on every new mac, just type in vim in the terminal. I always bring my vimrc file with me, and the problem is that every single time I start vim i have to load it with :so command.
I want to use the fact that vim is available on every unix, but I also want to take advantage of the nifty integration with the terminal for doing quick tests, I just switch back to the terminal, but for that I need to close vim. When I reopen it, I again have to load the vimrc. And I am a newb, I don't even have plugins yet...
I want to keep the integration with the terminal and only develop a super quick way of introducing my changes to vim. Think of the conditions as if though you are sitting on newly installed operating system.
Thanks !
Not directly to your question, but you can always invoke vim with -u, which will let you specify your vimrc file instead of launching vim and then running :so.
The default location for your .vimrc file is ~/.vimrc (on the mac, ~ is /Users/_you_, eg /Users/matt). If you can write your file there, it will be loaded when vim starts up every time.
The system vimrc file on the mac is at /usr/share/vim/vimrc, but it sounds like these systems are not under your control, so you won't be able to write that file. Have a look at: How can I override ~/.vim and ~/.vimrc paths (but no others) in vim?, which uses the -u option to change the path vim looks for plugins under. But, in all cases, you must either be able to write your .vimrc into your home directory (which it sounds like your system does not permit) or specify the path to it at runtime (as with the command-line option I mention above, or with the normal command :so which you're currently using).
Depending on the kind of testing you need to do, you can always run shell commands within vim, by using the ! in normal mode. For instance, I frequently make changes to a python file in a buffer, and then (in normal mode) run !nosetests within vim—that writes terminal output into a temporary buffer at the bottom, and doesn't require me to leave or suspend vim. I can review the output, and any key-press takes me back to my buffer.
I don't have any experience with Mac-Os terminal. However I think if you could cp your .vimrc file to your home directory. everytime you start vim, vim will load the .vimrc file from your home directory.
If you want to swtich back to terminal from vim to do some testing/execute some commands and back to vim. you could consider to:
open multiple terminal windows
try something like screen or tmux. personaly I am using tmux, and it's very nice.
try Conque Shell plugin: http://www.vim.org/scripts/script.php?script_id=2771 I have this plugin installed too.
type Ctrl-z in vim to back to terminal
If you want to sync your .vimrc on different machines, you could put your .vimrc file in
a scm repository like gitHub, bitbucket... (I perfer this option, since you could have different branches for different settings)
dropbox
I hope this helps.
How is it possible that your changes are not saved after you log out? What would be the point of such a machine? An internet kiosk in an airport? Do you log as a user without a "home" directory?
If you have a "home" directory, just create a blank ~/.vimrc and put your settings there.
If you don't have a "home" directory but you are able to write somewhere else, create a blank vimrc file where you can, write your settings there and learn this command by heart:
$ vim -u /path/to/your/vimrc
If you don't have a "home" directory and you are really sure that you can't save anything on these machines, put your settings in a file somewhere online, preferably a place under your control, and learn this command by heart:
$ vim -u http://domain.name/yourvimrc
If you are lucky, the command you use will be remembered by your shell for you and it will be easy to issue it again without much typing.
For running your tests, you can either:
Hit <C-z> to suspend Vim. You are back at the prompt from where you started Vim and you can do your thing. Type $ fg to go back to Vim.
Type :sh to launch a new shell from the current directory. To go back to Vim, type $ exit.
Related
I'm following a tutorial on Uniswap forking (just to learn how this works) and I'm stuck a particular step.
How does one go from:
vim migrations/2_deploy_contracts.js
to
I'm only able to see:
How do I see the folders and directories ?
The user in that particular video is using the NERDTree plugin for Vim. Vim is very powerful and extensible, and it's possible to load a variety of extensions written in Vimscript to customize the interface, add editor features (such as LSP support), or various other functionality.
They're also using a custom colorscheme which is probably based on the Solarized palette. You can also load a custom colorscheme with the :colorscheme ex command.
There is another thing to notice, besides mentioned NerdTree plugin.
I think you are running your command from the wrong place.
vim migrations/2_deploy_contracts.js
This command tries to open the file set by relative path, or creates a new file, if that does not exist. As we see from your screenshots - the file exists in the tutorial, but it does not exist on your machine (the [+] mark after the filename on the second screenshot shows that).
My guess you need to cd to the right directory first (tutorial project root) and then only run your vim command to open the file.
As for your question about seeing the files and directories, you can do it without NerdTree plugin, using built-in netrw. Just type :Ex in vim normal mode.
In Vim,
I can open Vim Ex command Window with q:
It seems to me all the commands are not shared in other instance of Vim.
e.g. I have other Vim instance in a second console.
I'm wondering whether I can share all the Ex commands that I have typed for last ten days
No, command history is not shared. Histories (as well as marks, jumps, opened files) are stored in a viminfo file. The contents are written when quitting Vim, and read during startup.
But (and here comes the interesting part), you can manually trigger these with the :rv[iminfo] and :wv[iminfo] commands. So, first execute :wv in the one Vim instance to export its history, then import via :rv in the second instance. This could even be automated via :autocmds.
I have recently started using vim and I really like it. I have added a few easy mappings in my vimrc file.
But the problem is I get to use a lot of remote machines a lot of time and I can't copy my vimrc on to them but most of the times I won't have enough permissions to do that.
So, I was wondering if there is any way I can put all my vim mappings in a file and tell vim to run it every time it loads, just like a vimrc?
The action that is "parsing" the .vimrc is called source.
In runtime, you can reapply/reparse your .vimrc by using
:source ~/.vimrc
So if you can somehow copy your .vimrc, even if not in your home, but a folder like /tmp you should be able to source it from there, with
:source /tmp/.vimrc
This question has more details and solutions.
One option would be to specify an alternative .vimrc file while launching the program.
The vim man pages has this to say about specifying a vimrc file:
-u {vimrc}
Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use this
to edit a special kind of files. It can also be used to skip all
initializations by giving the name "NONE".
See ":help initialization" within vim for more details.
Note that this option overrides the default vimrc file, so you'll have to specify all of your settings/options in this file.
As was mentioned in another answer, you can place your custom vimrc file anywhere you want (or have access to) and then specify the the -u option with the path to your vimrc file.
You could even combine this method with managing your custom vimrc file in an online version control system (like github) - this way you will be able to wget your file from the web instead of having to manually copy it from machine to machine.
On one of my dev machines I have unlimited undos, I can hold u and go all the way back to when I opened the file.
On another, pressing u toggles between the last two changes I made, no more.
The first dev machine I have Administrator access to and the vim installer had free reign. The second I do not and vim had to be installed off the normal OS paths and have to launch vim with a 'Sendto'. Perhaps this is related and I'm missing some rc commands.
Also noticed I have to run 'syn on' to get highlighting on that box. vimrc was also blank so now I'm sure it has something to do with it.
From other threads I don't believe this is related to the persistent undo feature, but simply a .swp or ~ issue (whatever those files are used for..)
Deadlines have prompted punting what is probably a simple issue.. How do I fix this?
vimrc was blank on the affected box.
I added these lines from my other dev box and everything was hapy again.
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
Looks like you need a vimrc file on the second box: see :he compatible-default.
If there is no vimrc file, vim runs in vi compatible mode, and there is no syntax highlighting etc...
Create one. Output of :version will show you more where the files are expected.
If undo still does not work have a look at :he undo-two-ways.
I'm a recent vim convert (from fancy IDEs like eclipse.)
I love the :make command in vim and use it extensively; however I also like to edit multiple projects (with separate makefiles.)
So usually to edit more than one project I will do
pushd project1
vim project1.cpp
[suspend signal]
pushd ../project2
vim project2.cpp
and now I can switch between the two projects with ctrl+z i.e. suspend signal, and fg.
When this becomes an issue is when I want to open one project in the context of another so I can do copy/pasting. So if instead in the above I do
pushd project1
vim project1.cpp
:vsp ../project2/project2.cpp
I can edit both concurrently in the same vim process, however I can't effectively build one or the other with the :make command, it will only build project 1.
Does anyone have some kind of scheme that gives them the best of both worlds: being able to edit concurrently while still being able to build multiple projects with the :make command all from the same vim process?
Are the make commands you want to execute the same for each? So the problem is just the current directory? You can use :lcd to change the directory only for the current window, so that it will run in the appropriate directory for each. To make this more automatic, you could set up an autocommand (on BufWinEnter, I think) for when you create that split window to run :lcd expand('%:h'), or just map a key to that if you don't want to always do it.
(You could also map a key/create a custom command for a combination of the lcd and make, probably saving keystrokes but then unnecessarily cd'ing before each make. Not that that takes long.)
P.S. The reason I asked if the make commands were the same is that you can actually set makeprg and other associated options locally (use :setlocal instead of :set).
vim's :make command really just executes the program configured as makeprg in the current directory (make by default).
By starting every vim process inside a project directory, you indirectly set the current directory for that vim session, but of course you can change the current directory inside a running session, e.g. when you started in project1/ you can simple cd to project2/ and build it inside vim with
:cd project2
:make
or like if you only what to change the directory for the current window, do what Jefromi suggests
:lcd project2
:make
There are plugins that say they makes this easier (this one seems to be popular), but I never needed to use them.