Tag Info

New answers tagged

1

To match "something", but not after a specific "word", you can use \@<!; /\(word\)\@<! something/ For replacing "something" by "somethingelse", but only if "something" is not after "word": :%s/\(word\)\@<! something/ somethingelse/ From inside vim, show the description with :help /\@<!: \@<! Matches with zero width if the preceding ...


0

Instead of a % for a whole file replace, you could try with a range for the address: 0,/^References$/s/\s*\n*{\\&}\s*\n*/ /g 0,/^References$/s/\([A-Z]\)\.\([A-Z]\)\./\1\. \2\./g 0,/^References$/s/\(\w*\-\w*\|\w*\),\s*\n*\([A-Z]\)\./\r\\snm{\1}\r\2\./g (Assumes that References is the only word in the line. Modify the regex as needed.)


0

Type Alt+L to return to command mode. It doesn't require any remapping or vim config change. It works because on most terminal emulators Alt+KEY sends an Esc followed by KEY (on xterm you might need to add a Xterm*metaSendsEscape: true line into your ~/.Xdefaults file). That behavior allows you to even "create" other insert mode combinations that work ...


7

You're looking for :set splitright You can also influence this for individual commands, e.g. :rightbelow vsplit


1

To indent the all the lines below the current line =G So, to indent entire file, go to the beginning of the file (gg) and then indent all the lines below the current line (=G) gg=G To indent the current line == So, to indent n lines below the current line n== For example, to indent 4 lines below the current line 4== These are the simplest ...


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).



Top 50 recent answers are included