Tag Info

New answers tagged

1

To indent the all the lines below the current line =G So, to indent entire file, go to the beginning of the file and then indent all the lines below the current line gg=G To indent the current line == So, to indent 4 lines including the current line and the below 3 lines 4== This is what many people want most of the times.


0

In command mode: :%s/_reg_\([0-9]\+\)$/[\1]/ Here we use \+ to match one or more group of numbers at the end. So we don't have substitute with lines like cad/pqr_reg_.


0

Just use this: :%s/_reg_\([0-9]*\)$/[\1]/ That is, catch the number with \( and \) and then print it back with \1. Note also there is no need to /g, because you perform it just once per line.


1

The only different between them is cursor position. From :help motion.txt: f f{char} To [count]'th occurrence of {char} to the right. The cursor is placed on {char} inclusive. ...


1

Yes the main difference between them is the cursor position as you said. This comes in handy when you want to delete or change some characters for example. Suppose you have the following line: print "Hello, world!\n"; exit Suppose you want to change everything before the semicolon. To do that, you go to the beginning of the line (^) and then change ...


3

Well, I just tried this on 2 machines (SUN OS / Linux) and works on both: In vi (<> represents actions to do / to write): :<write start line number>,<write end line number>y<press enter> Then move the cursor with arrow/hjkl keys on where do you want to paste. Then simply press p or P Example: :1,3y This will copy line 1 ...


6

Try using ex commands in vi (according to Solaris User Guide) :line#,line# co line# Example: :283,295 co 512 This command copys line 283 to line 295 and pastes that after line 512 (to activate line numbers in vi use :set nu).


7

You can count words and lines inside vi using vi's own counter: Press g and then CTRL-g. Then the bottom line look for example like this: Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644 Or use vi's method to call shell commands: :w !wc -w This calls the save (:w) command first and then wc -w and shows the output. Example: :w !wc -w 344 ...


0

Thanks for the answers. I ended up solving the issue by changing the the folder owner to myself, using chown. This resulted in me not having to use sudo everytime I wanted to create/edit a file.


1

You need to run vim as root. sudo vim /var/www/file


2

Sorry I am not able to comment yet. Try to run command :sudo -s by this you will login as root. Then, I guess, you can do whatever work you want to.


3

In vim, you can use redir command. In command mode: :redir > vim.output | set fileencoding | redir END Then output of set fileencoding will be save to vim.output. There is many other options of redir, you can see :help redir for more details. This works in vim, not in vi.


0

Check that line similar to below is present in your file /etc/bash_completion: complete -f -X '*.@(o|so|so.!(conf)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite Execute this command on shell. Alternatively add above line in the file /etc/bash_completion and execute: ...



Top 50 recent answers are included