Hot answers tagged vi
I think you want something like this: :w !sudo tee "%" I first saw it on commandlinefu. The quotes are only necessary if the file path contains spaces.
Larks answer is probably the most likely. You may not wish to change your root accounts vi to vim permanently as if your resources are low vi is almost guaranteed to always work, I'm not so sure about vim. You are probably using (color) /usr/bin/vim under your normal user and /bin/vi under sudo or root. You can check by using: which vi once under ...
You appear to be having this issue, which is because at some point nvi started opening files O_RDWR instead of O_RDONLY. If your vi is in fact nvi, I'd try using a different vi, say vim.
vi will be more common, but theyre not 100% the same. The basics are, yet vim (vi improved) is as the name suggests more advanced when it comes to features. If you want to use an editor that is available at most systems, use vi. If you want to use one with more functions, use vim, but be prepared to install it or fall back to vi on certain systems where it ...
On a RHEL system, /bin/vi is typically a minimal version of vim, without any syntax highlighting support. /usr/bin/vim is the full-featured editor. It is very likely that in your user environment, vi is an alias for vim. Try this: sudo vim /some/file Do you get syntax highlighting now?
Is this what you mean? :r !date or to add one week to the current date: :r !date -d “today 1 week” Also see this post: http://stackoverflow.com/questions/56052/best-way-to-insert-timestamp-in-vim
I suspect that you have an alias vim=vi in ~/.bashrc. Try this to run 'real' command, not alias: \vim /path/to/php/file Looks like your are running CentOS. Make sure that you installed vim-enhanced package: rpm -qa | grep vim vim-minimal-7.0.109-4.el5_2.4z vim-enhanced-7.0.109-7.el5 vim-common-7.0.109-7.el5
You need to check if the /etc/.pwd.lock exists and if it's there rm /etc/.pwd.lock In this way you can solve your issue
Your vi is probably /bin/vi from package vim-minimal which does not support syntax highlighting. sudo vi launches /bin/vi for you. Bash only does alias expansion on the first word in your command line, so in: sudo vi vi is not substituted to vim even if you have that alias defined. The solution is define another alias (for the user invoking sudo): ...
For sh based shells: export EDITOR=/path/to/nano For C shell based: setenv EDITOR /path/to/nano Remember that unless you save these setting to your login profile script (/home/user/.bash_profile for example), you lose the setting at log out. If I remember correctly, FreeBSD uses C shell as the default user shell.
I hope I'm not offending you by answering, that to run the current file (not buffer) you just :!% UPD: To run buffer to interpreter's standard input (without saving to a file first): :w !/bin/sh The latter can be also used with python, with perl -w, etc. By the way, a super useful technique is to filter a buffer through external command: 1G!Ggrep -v ...
How are you logging their activities right now? The easiest is to block them from launching shells from vi. # vi /home/user/.exrc set exrc set shell=/bin/false # chown root:root /home/user/.exrc # chmod 644 /home/user/.exrc # chattr +i /home/user/.exrc If you're using a special shell to log their commands, you could change vi to use that shell only.
Esc will only throw you back into command mode in VI or Vim. To Save and quit press Shift + Z + Z, :wq, or :x in command mode. If you are opening the file in read only mode you will have to hit :q!. Consider looking at this cheatsheet as well for more macros VI cheatsheet
You can also turn on process accounting ( s/can/should/ !) You can then use: lastcomm(1) to see the command run and if they were run after a fork, with or without an exec. Combined with a host based IDS this should give you what you need "that the King's justice may be done upon him."
Giving someone sudo in vi is always a bad idea. They can get out of vi with a root-shell by issuing the :shell command. You don't want that. An alternative for you might be sudoedit. You can then give your users/groups rights for sudoedit in the sudoers-file: %JBossAdmins <hostname>: sudoedit /etc/httpd/* %JBossAdmins <hostname>: sudoedit ...
You could use acls instead and do something like setfacl -m g:JBossAdmins:rw /path/to/file which would grant r/w permission to anyone in the JBossAdmins group to the specific files.
You could start by following http://blog.danielfischer.com/2010/11/19/a-starting-guide-to-vim-from-textmate/
Try these generic ideas: Ctrl+L to refresh screen reset to reset the terminal to its default state export TERM=xterm to test if the above ideas don't work
Are you talking about the shell history? vi shell mode (:sh) launches the user's default shell If that is bash then you can make sure that history logging is always enabled by editing the global /etc/bashrc and adding: set HISTFILE=~/.bash_history shopt -s histappend PROMPT_COMMAND='history -a' that will ensure that every user command gets logged to a ...
You can use find for finding the target files and then pipe it to sed: find | xargs sed -i 's/foo/bar/g' Only replace in .txt files: find . -name "*.txt" -print | xargs sed -i 's/foo/bar/g' (from this blog post)
Ah yes, time for a perl oneliner. How about this? perl -pi -e 's/old text/new text/' file or maybe you want to change all the *.txt files in the current directory? In that case, how about combining it with GNU parallel: parallel perl -i.bak -pe 's/foo/bar/' ::: *.txt With parallel, the ::: means use eveything after this as input files. or, to change ...
Put the following in you ~/.exrc file map! ^[OA ^[ka map! ^[OB ^[ja map! ^[OD ^[i map! ^[OC ^[la Note: ^[ is the “ctrl-v Esc” key presses. Copy and paste will not work.
:g/^[0-9\*]/s/^/##DISABLED##/ This "g/RE/" part selects all lines that begin with a number or the * character. The "s/RE/replacement/" then does the work on all selected lines.
By default in 5.4 vi is default. I forget what version that started in. This will add the necessary alias for you: cat <<_EOF >>/root/.bashrc alias "vi"="/usr/bin/vim" _EOF
Update: From what you said about the backspace and the arrow keys, that sounds like it could be the terminal, not the editor. So your editor is not getting the right keys. Are using a particular xterm? are you on the same machine? Are you using screen? Vi and VIM should have the same shortcuts. Are you sure you are not using an Emacs editor like nano ...
You may be using a different clone or a cut down version of vim. Ubuntu by default uses vim-tiny if I remember correctly. You can find out which one is being used by checking the link "/etc/alternatives/vi"**. If it points to /usr/bin/vim.tiny you have a very minimal vim installed. If it points to some other file you can use "dpkg -S filename" to figure ...
Assuming a US keyboard, Press i to go into insert mode, and then shift-3. You can use either shift key, and press it the same time as the '3' key. The three key is after two, and before four.
There is the very remote possibility that the user is using an antique unix that has # mapped to delete and @ mapped to kill (^U on most traditional modern systems). If his system is configured this way, he will not be able to type a # because every time he does it will delete whatever character is to the left of where he is trying to type the #. The ...
looking to this http://www.viemu.com/a%5Fvi%5Fvim%5Fgraphical%5Fcheat%5Fsheet%5Ftutorial.html
Try esc : 10 sp ctrl-w to switch between. They are referred to as viewports in vi parlance.
Only top voted, non community-wiki answers of a minimum length are eligible