New answers tagged

0

FYI recent fedora (at least since 18) installs that alias gobally in /etc/profile.d once vim-enchanced is installed.


12

:2,$v/0$/d deletes the lines that don't end in 0 starting from the second one.


16

If you mean you want to keep every 10th line and delete the rest: %norm 9ddj Explanation: % whole file norm execute the following commands in "normal mode" 9dd delete 9 lines j move down one line (i.e. keep it) note: this deletes the first row. Adapted from http://www.rayninfo.co.uk/vimtips.html Or using the global command: Duplicate the first ...


1

Another solution: truncate -s 0 file


2

By saying you're in user2's shell you imply you've been logged in as user2, the command whoami or echo $LOGNAME will let you know the same. Whatever commands you are firing in the terminal are considered to be fired by the logged-in user, except for those through sudo. The coloumn names in an output of ls is as below, for you reference. The Fourth field is ...


5

No, vim is not set user id (that is, it will not change effective userid). running a command line from vim will give you a shell (that is the word) as user2. By the way, to edit the file you must either be user user3 belong to group user2, merely being user2 is not enough. There used to be a bug in redhat 4.x (or still is) when running visudo, which ...


0

The editor is vi, its very simple to play around, if you need to type anything press escape button and then i (i means insert) if you need to save it then again press escape button and then :wq If you don not want to save and close press escape and then :q!


3

crontab -e enters into default editor (vi editor). The simple shortcuts in vi editor are i - Insert mode (allows you to write data) : mode :w -> we can save data :q -> quit from editor :q! -> force quit :wq -> save and quit any time we can reset the mode of editor by using Esc key. You can use EDITOR=nano crontab -e to edit crontab file by using the ...


12

You can pick any editor you like by setting the $EDITOR variable before calling crontab -e e.g. $ EDITOR=emacs crontab -e will run emacs as your editor. If you have a favourite editor then you can select that. Many programs that call an external editor may also use this $EDITOR variable so you may find it useful to set it permanently in your .profile ...


5

That looks like vi or one of its many clones, probably vim. You can use i to insert, x to delete the current character, dd to delete a line (and copy it to clipboard), p to paste below the current line, and u to undo the last change. Hopefully that will be enough to let you do your change. For more details, search for a vi manual, handbook, or ...


1

Question had been solved at stackoverflow.com: Adding noremap <Esc>a h noremap <Esc>s j noremap <Esc>w k noremap <Esc>d l to .vimrc solved the problem.


2

On most installation I have come across: ALT-something is the same as: ESC (release after press) something So, vim commands are always "ALT-Prefixed". But, as you have found out in the meantime, there is a way to specify this key combination in the vimrc.


0

This is done intentionally in vim: the ":wq" command calls, ex_exit, which calls getout with a nominal exit-code 0, in getout, it checks for an error in ex-mode, commenting /* When running in Ex mode an error causes us to exit with a non-zero exit * code. POSIX requires this, although it's not 100% clear from the * standard. */ if (...


1

In vim, or with vi on a BSD system: Use the vi command :0r !hostname Or, in its longer form, :0read !hostname You would have to press Esc first, of course. The read command usually takes a filename and inserts the contents of that file beneath the current line, but if you specify a shell command with ! in front of it, it will take the output from ...


1

You tagged vi however it sounds like you're looking for a CLI option. While in vi you can use shift + O to insert above and automatically add a new line and just paste your line right in. If you don't want to use an editor you can use sed. sudo sed -i '1iabcd555.india.com' /etc/hosts


1

Would this work using sed? sed -i '1 i\'$HOSTNAME'' file Using this with a file named test1 produces: $ cat test1 one two three four five Then: $ sed -i '1 i\'$HOSTNAME'' test1 leads to: $ cat test1 chris-dell one two three four five


0

The easiest way to do this programmatically is to write to a temporary file and then overwrite the existing one: { printf '%s\n' "$(hostname)"; cat somefile } > somefile.tmp mv somefile.tmp somefile



Top 50 recent answers are included