Posts

Showing posts from January, 2021

Vim: searching for text containing a slash or a question mark

Vim: searching for text containing a slash or a question mark Vim: the search command To activate a text search in Vim, press one of the following trigger keys in your keyboard: the slash "/" key (do not confuse with the back-slash "\" key) the question mark key. By pressing the slash "/" key will activate a forward search. By pressing the question mark "/" key will activate a backward search. To move the cursor to the results in your document, press the "n" key (mnemonic for “ next ”). To invert the direction of the cursor, press the "N" key, (“upper n”) . What about if you need to search for a slash or a question mark , i.e. the same trigger characters , in your document? You can prepend the Escape character to the trigger key. The Escape character The Escape character is the back-slash key: "\" . Just an example: if you need to forward search (then with / trigger k...

Vim: vertical motions through full or wrapped lines

In Vim a line is a set of characters ending with a Carriage Return. What’s so special about that definition? Think about wrapped lines that exceed the right edge: Vim handles each wrapped line as belonging to one line only. Standard vertical motions in Vim using j e k keys or the arrow keys occur within full lines. You can jump through wrapped lines by adding the g key to j e k . But, did you know that you can have both movements available without adding any keys? You can remap arrow keys by insering the following code in the .vimrc configuration file: nnoremap <Down> gj nnoremap <Up> gk vnoremap <Down> gj vnoremap <Up> gk inoremap <Down> <C-o>gj inoremap <Up> <C-o>gk From now you will be able to use the arrow keys for the motions through wrapped lines and the jk keys for the default Vim motions.