I assume this is common operation but can't find any information about this. When in copy mode (Ctrl + [) Is there a shortcut to copy the word under the cursor without manually creating the selection?
I've tried to switch to vi-mode and use yw but it doesn't look like it works (in fact, I'm not entirely sure what vi-mode does besides mapping the arrow keys to hjkl).
Any idea how to achieve this?
Edit: As pointed out by #Sebastian Graf, tmux now has a native command: send-keys -X select-word for selecting a word. What follows I leave for posterity ...
bind -n -T copy-mode-vi C-d send-keys b \; send -X begin-selection \; send-keys E
I'm using the above to at least select the current word under the cursor. The shortcut is C-d as inspired by Sublime Text. You will need to have also set set-window-option -g mode-keys vi, but I believe that is default. In vi-mode the b moves the cursor to the beginning of the current word, then it begins selecting with begin-selection, then moves the cursor to the end of the current word with E.
So you could also copy the word with:
bind -n -T copy-mode-vi C-d send-keys b \; send -X begin-selection \; send-keys E \; send -x copy-selection.
I've included all the commands here, because I couldn't find anywhere on the Internet that actually formatted it nicely.
Function Vi Emacs
-------------------------------------------
Back to indentation ^ M-m
Bottom of history G M-<
Clear selection Esc C-g
Copy selection Enter M-w
Cursor down j Down
Cursor left h Left
Cursor right l Right
Cursor to bottom line L
Cursor to middle line M M-r
Cursor to top line H M-R
Cursor up k Up
Delete entire line d C-u
Delete/Copy to end of line D C-k
End of line $ C-e
Go to line : g
Half page down C-d M-Down
Half page up C-u M-Up
Jump forward f f
Jump backward F F
Jump again ; ;
Jump again in reverse , ,
Next page C-f PgDown
Next space W
Next space, end of word E
Next word w
Next word end e M-f
Paste buffer p C-y
Previous page C-b PgUp
Previous word b M-b
Previous space B
Quit mode q Esc
Rectangle toggle v R
Scroll down C-Down/C-e C-Down
Scroll up C-Up/C-y C-Up
Search again n n
Search again in reverse N N
Search backward ? C-r
Search forward / C-s
Start of line 0 C-a
Start selection Space C-Space
Top of history g M->
Transpose chars C-t
Related
In IntelliJ IDEs, I can add any duplicate words by using the 'Add selected text for next occurrence' key shortcut. When multiple words are selected simultaneously, I can then change all of them at once using the IdeaVim plugin and ciw key presses.
However, I haven't been able to do this successfully for sentences. For example, if I select a group of text between double quotes: " hello there ", what ends up happening is that I will be able to select/highlight duplicate groups of hello there, but pressing any key results in me only updating the first selection of hello there and not the other selections.
I do realize that I can achieve the same effect simply by doing a find/replace through the entire page, but I like the convenience of adding an occurrence one at a time with just a press of a button. Any suggestions?
There are several ways to achieve the behavior you mentioned. However if you are looking for a method that have the visual effect similar to the Intellij, you may need to use the plugin for vim, such as vim-multiple-cursors.
Here are some vim's ways to do that:
Next Occurence + Redo Last Command:
/ to search for all occurence (/ hello there )
n to navigate to next occurence
v and arrow key/l to select region
Substitute region with s or delete text under region with x
n for next occurence and . (dot) to redo last command and repeat n + .
MACRO:
/ to search for all occurence (/ hello there )
qq to start recording macro to key q
Do step 2-4 from previous method
q to stop recording macro
# then q to apply the macro from key q
Note: If you want to repeat step 5 n times, simply append a number before # (ex. 5#q to apply macro 5 times. If there are only 4 occurence, then macro will only be applied 4 timers.)
Find and Replace:
:%s/ hello there /new value/g to globally replace " hello there " to "new value"
To replace the occurrence in certain place, use visual block v to select the block then :'<,'>s/ hello there /new value/g to replace only in selected area
I have an SQL query that has over 5000 characters. I don't have access to mouse, just the terminal Vim editor. During testing, I need to change values of this query here and there. It is so long that, the next line number appears after 2 screens of pressing page-down.
So if I have to edit, I go to the beginning/end of the line and starts pressing j k h l as required. This is very tiresome. Sometimes, doing a search helps. I hope you can understand the situation.
How can I make the editing easier?
These settings will help you immensely:
"Make long lines wrap
set wrap
"Make wraps *not* occur in the middle of a word
set linebreak
"Make the last line look OK
set display+=lastline
"Make 'j' and 'k' go down a visual line, not an entire line
nnoremap j gj
nnoremap k gk
"Make the arrow keys also go down a visual line
nnoremap <Up> gk
nnoremap <Down> gj
"Allow the option to move up entire lines
nnoremap gj j
nnoremap gk k
Since lines starting with " are comments, you can just directly copy and paste this into your .vimrc.
Another useful feature is the bar command |. If you type 200 |, this will jump to the 200th character on the current line.
If you want, you could also include these settings:
nnoremap $ g$
nnoremap 0 g0
nnoremap g$ $
nnoremap g0 0
With these settings, you can use g0 and g$ to jump to the first/last character on this visual line, rather than than the first/last character on the extremely long line. These settings don't hurt, but IMO the first group of settings I posted are more useful.
The following code executes perfectly:
do for [i=1:$M_Orbs]{
set table 'L_z_'.i.'.dat'
plot [0:250] "L_z_expectation.dat" u 1:2+2*((i-1)*$M_Orbs+i) smooth cspline w l
unset table
set table 'Nocc_'.i.'.dat'
plot [0:250] "NO_PR.out" u 1:2+$M_Orbs-i smooth cspline t 'M='.i w l
unset table
}
But I have trouble when I try and combine these files in a loop using the paste command:
plot for [i=1:$M_Orbs] '< paste 'L_z_'.i.'.dat' 'Nocc_'.i.'.dat'' u 1:(\$2*\$5)
This line brings up the error,
plot for [i=1:2] '< paste 'L_z_'.i.'.dat' 'Nocc_'.i.'.dat'' u 1:($2*$5)
^
line 0: x range is invalid
I'm pretty sure the error occurs because gnuplot tries to execute the paste command before assigning i to it's value in the for loop. Is there another way of escaping the i, or atleast implimenting the same idea in another way?
You have wrong quotes.
Inside single quotes ' you can use either double quotes " without escaping them, or double single quotes '' (which is the way single quotes are escaped).
But the filenames given to paste mustn't be quoted, so your plot command becomes:
plot for [i=1:$M_Orbs] '< paste L_z_'.i.'.dat Nocc_'.i.'.dat' u 1:(column(2)*column(5))
column(2) is the long version of $2, but must not be escaped.
You could also use sprintf to format your file names:
plot for [i=1:$M_Orbs] '< paste '.sprintf('L_z_%d.dat Nocc_%d.dat', i, i) u 1:(\$2*\$5)
I prefer the latter variant, because it allows you e.g. to pad the numbers with zeros: sprintf('L_z_%03d.dat', ).
Is there an shortcut in nano for moving through a line faster? I have some log files with gigantic lines and getting to the middle of them is awful.
I know I could use a different text editor that doesn't have this particular problem (less will wrap lines), but I'm used to nano and I like a lot of its other features.
Here are the shortcuts for moving through a line in nano.
Use these to go faster through a line:
ctrl + space move one word forward in a line.
alt + space move one word backwards in a line.
Other line shortcuts:
ctrl + f move one character forward in a line.
ctrl + b move one character backwards in a line.
ctrl + a move to the beginning of a line.
ctrl + e move to the end of a line
To move to a specific line use ctrl + _.
You may want to check out more Nano Keyboard Commands
I would like to develop a selection-tool for Screen which ignores the leading spaces and numbers in selection.
Problems
What is the code which affects selection-tool C-a Esc in Screen?
To make an algorithm which ignores the linenumbers and the space at the beginning from the selection:
alt text http://files.getdropbox.com/u/175564/%20selection-less.png
The following Perl-regex seems to match the beginning of the line
{5}[1-9]{1-4} {8} # not tested
The selection tool apparently works by concatenating an increase in selection to the current selection. For instance, one line is selected. I select another one: a new line is added to the selection queue. The reverse is true also for a decrease in selection.
I want to put the Perl regex on when the selection obverses \n such that the ignorance of the line is considered.
I think you want to select columns. That'd be much easier than a regex.
From the screen manpage:
c or C to set the left or right margin respectively. If no
repeat count is given, both default to the current
cursor position.
Example: Try this on a rather full text screen: "C-a [
M 20 l SPACE c 10 l 5 j C SPACE".
This moves one to the middle line of the screen, moves
in 20 columns left, marks the beginning of the paste
buffer, sets the left column, moves 5 columns down, sets
the right column, and then marks the end of the paste
buffer. Now try:
"C-a [ M 20 l SPACE 10 l 5 j SPACE"
and notice the difference in the amount of text copied.
So, in your screenshot, press C-a [, move the cursor to the beginning of your text, press SPACE and then press c. Move to the end of your selection and then press SPACE again. Now you have the text you want.
Hope this wasn't too much info. You tagged it with beginner so I wasn't sure if you were a perl or screen beginner.