I was working samba on raspberry pi using putty to connect. I configured the smb.conf file using nano as my text editor. Try to use vi editor but it doesn't allow me to put in space or create a new line.
After I restart samba. It creates smb.conf.save file. When I try to nano smb.conf(the original file), it shows nothing like a blank page(see below image). It also crushes since I cannot go back to the command line. I have to close and open it again.
When I try to use vi editor to view smb.conf. I am able to view the text.
Does anyone know what is the problem? How to fix it? Thank you.
Basically vim saves your buffer (unsaved edit) in a temporary file with .save extension so you can use this as backup in case something happens like unexpected system reboot
VIM is a bit different from other text editors. It has multiple modes insert mode (where you can edit text) and command mode (where you can use alphabet keys to do commands like go up using k and delete using dd etc. Once you open vim you are on command mode so you cannot edit your text until pressing I to jump to insert mode.
Check https://www.radford.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm
My answer for your issue will be either to take a quick tutorial about vim then edit using vim or use nano to open .save file edit your file then when save delete the .save extension
Related
I am using linux.
In terminal I can type
vim sample
A vim window for the file 'sample' opens
Here any change can be saved with :w
But I want to open a new vim file having no name and save it with the name sampleName using
:w sampleName
But I am unable to do so.
Typing only vim in terminal gives me a window with about and copyright information
I am not using gvim but vim
You should be able to just run vim with no arguments. It will open vim by itself. To save it to a file, execute the command: :w <new file name>
Issue the Command, :enew and Also Learn about How Vim Manages File Editing
I would recommend reading up on file and buffer usage in Vim in the help file, usr_22.txt.
As architrex has indicated, by default, if one does not have a file(s) listed in the argument list when starting Vim, a new buffer is created. See :help starting.
If you started vim with one file in the file argument list like you described, vim sample, a common way to work with an empty buffer is to issue the :enew command (typically after you would have written changes to the file named, sample, :w).
We can see the new buffer here:
Once one is done modifying the new buffer, you can issue the write command, :w sampleName, with the expected result of writing the file.
Vim's use of buffers is intuitive and you will become more skillful as you use it.
When I started using Vim, I leveraged using NETRW which is a seeded file navigation plugin with Vim for file creation (and placing those new files in buffers).
What follows is one way to leverage NETRW to do this.
If you have already started Vim, I would type :Exp or :e . which are ex commands which will start the file explorer which is a feature of the seeded file navigation plugin, NETRW.
One could start Vim:
Start the file explorer for NETRW:
I would then use the file explorer to navigate to the desired file to create a new file you wish to edit (k is up, j is down, enter key means select).
Next, I would type,%, once I have navigated to the desired location.
You will be notified to "Enter filename". Just enter "sampleName" and press enter.
Go into edit mode (e.g. i) and start typing.
NETRW is a robust file navigation tool. Creating files in the file locations desired is an essential skill to have to utilize Vim well.
You could also read the help files concerning NETRW (e.g. the ex command, :help netrw).
Is there "keyboard-only" way to select an entire vim document in a way that is equivalent to a left-click and drag with a mouse in normal mode? Please do not confuse this with selecting all text in visual mode (ggVG). I want to be able to follow this up with a right-click paste into notepad++ (ggVG/ggVGy followed by a right-click paste in notepad++ does not copy the document). Thanks
Again, the "ggVG" commands are not working, nor are the "+y" commands (which I should have mentioned in my original post). Perhaps it is worth noting that I am working on a Windows local machine (where I have notepad++ open) and am generating the vim file on a linux virtual machine (slurm cluster). Under these working conditions, if I left-click drag over the vim doc and right-click paste in notepad++, the selected text copies over. However, the process is cumbersome for large files, hence my inquiry. Thanks again.
You should have mentioned that, of course, as it is not a meaningless detail at all.
Manual selection in a terminal can only select the text currently displayed in the viewport, which is obviously cumbersome for larger files. The only practical way to copy on the remote machine and paste on the local machine (and vice-versa) is to enable X-forwarding and build Vim on the remote machine against X libraries. This will give you what you want: a shared clipboard.
You won't be able to reach your goal in a practical way if you can't or don't want to install the necessary stuff on the remote machine.
As a lightweight alternative, you could simply scp the remote file to your local machine.
Just use (esc) :%y+. This will copy the entire document to your clipboard. Then you can go to notepad++, or whatever else you want to use, and paste it with a right click.
Explanation:
%: Tells vim the next command will be applied to all lines.
y: to all 'yank' lines
+: Copies all lines to clipboard, You can also use Ctrl + C instead. Note: + is sometimes bound as *. And sometimes both are equivalent.
Or you can also use the slightly longer way: ggVG+.
If you really want to be fancy you can remap Ctrl + A to ggVG or %y by adding this line to your .vimrc:
map <C-a> <esc>ggVG<CR>
Try to use Xshell remote login software. in there is a option called "To Text Editor".
Just open the file using "vi filename.c" it will displayed on the screen after that just made a left click on the work area and choose "To Text Editor--->all" . then these all text moved to a notepad file then u can simply copy and paste in notepad++.
Is there a shortcut key to copy a line from vi editor and then paste it into a terminal.
Currently I select the text with mouse and then press crtl+shift+c (I'm using default settings of KDE) and then do ctrl+shift+v on the konsole. The problem with this option is when the line is long enough to wrap. In that case copy-paste inserts extra spaces which I have to fix after pasting on terminal.
This is very annoying specially when the line copied is very long and contains file names (typically commands used to invoke compiler).
You can yank to the X clipboard by putting the contents in the * register.
To do this use "*yy on the line you want to yank. Then outside of vim you should be able to paste it.
If you don't have access to a clipboard via X or screen or tmux, you can write the contents of the buffer to a temp file, then go to the terminal and invoke $(cat temp-file) or open an editor for the command line and read in the file. Whatever shell you are using probably provides a mechanism for opening an editor on the command line. In bash with vi-style readline keybindings you can type v to get a vi session. If you shell does not provide that functionality, try a different shell.
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.
Hey I have a centos installation, but I found the vim within it is quite worse than the one in ubuntu. I don't know why. I have copied the configurations from ubuntu but the behavior is still not the same, the difference:
I can't use arrow keys in insert mode, when I press "UP", the 'A' will be inserted into the content, and vice versa for all the other arrow keys, what should I set to make arrow keys working right in insert mode? (In view mode it's ok).
I can't copy a line using 'yy' and then close it and then open another file and then 'p' paste to the opened file. Looks like no clipboard suppored across multiple files.
I can't use history feature(I can't go the the line number that I visited last time, the cursor will always go into the first line when I open the last opened file)
I appreciate the helps!
Try this:
in the ubuntu machine, open a file with vim
and do
:mksession ubuntu.vim
put the file ubuntu.vim in the second machine, where you would type the following:
vim -S ubuntu.vim
if you now have the same behavior you just need to check what you need to add in
your .vimrc from the file ubuntu.vim.
If you don't have the same behavior maybe you will have some errors while loading the file...