Is it possible to use vim with the mouse?
If so, how?
You can enable the mouse with :set mouse=a (The letter 'a' means enable it in all modes)
With GVim, you can select text and move the cursor, and select menu options with the mouse. Copy and paste, by right-clicking etc... But I guess this misses the point of using VIM.
You can map certain actions to mouse left click and right click. And there are plenty of already mapped actions to work with ctags and other things.
:help mouse-using
Related
I use (neo)vim with mouse=a and scrolloff=5. Clicking on one of the top or bottom five lines with the mouse causes the screen to jump (so that the new cursor position is more centered), which distracts me. Is there any way to disable "so=5" for mouse-clicking only?
I use (neo)vim in different terminal emulators on linux.
You can disable the scrolloff value using a click mapping, refer :help <LeftMouse> However, you'll have to re-enable the scroll setting afterwards as re-enabling the setting in the mapping would again cause the view to jump up/down.
This will disable the scrolloff setting and the view will remain unchanged:
nnoremap <LeftMouse> :let &so=0<cr><LeftMouse>
With the above, the view will not jump, but you'll have to re-enable so
We could re-enable it in the same mapping, but that would mean, you'll see the same behavior of view jumping up or down as so is applied immediately after it's set.
nnoremap <LeftMouse> :let temp=&so<cr>:let &so=0<cr><LeftMouse>:let &so=temp<cr>
So, there isn't an ideal solution to what yo want (at least I know of). You could either disable so completely and use something like zz or get used to the behavior of so on mouse click.
I use vim in xterms on Arch linux. Wanting to automatically set marks for subsequent command ranges I wrote this mapping
map <LeftMouse> mp:let g:oc=g:nc<cr>:let g:nc=getpos('.')<cr>:call setpos("'o", g:oc)<cr>:call cursor(g:nc[1], g:nc[2])<cr>
but now the mouse no longer places the cursor at the clicked location. How can I keep standard mouse function, and add to it rather than replacing it?
It seems its not possible to modify LeftMouse, but you can achieve the effect of it using LeftRelease. So my mapping does what I want as
nmap <LeftRelease> mp:let g:oc=g:nc<cr>:let g:nc=getpos('.')<cr>:call setpos("'o", g:oc)<cr>
and the standard function of is unchanged.
You can :set mouse=a for using visual select mode. (This is not what you wanted but it is a trick).
Then, click on text, you will see that it is getting selected. Then, you can release it.
A mapping like
:map gv ma
will set the last recently selected text as mark a.
Other way:
Instead of :set mouse=a, you can press v and then select a letter or a word, depending upon your convenience and then ma for marking it as mark a.
A short mapping for it will be
:map vly ma
I was wondering if is there any way to change the place of the tabs. Anyone can help me about this? I would like to have vim as my favourite ide..:)
Check out help :tabm[ove]. Essentially you could do:
:tabm +N to move current tab N places to the right. Or :tabm -N to move N places left.
Vim is not an IDE, it's an editor. You won't turn it into an IDE, no matter how hard you try.
Anyway, read :h tabmove:
:tabmove 0
moves the current tab to the first position
:tabmove 2
moves the current tab to after the 2 tab
:tabmove
moves the current tab to the last position
What do you exactly mean by "place of the tabs"? The other answers have already shown how to move individual tab pages around.
If you're inquiring about where Vim places the tab labels, that cannot be changed; they will always be between the GUI menu and the windows. In GVIM, you can only "downgrade" the tab appearance from graphical to textual via
:set guioptions-=e
When using the tabline (with guioptions-=e), you can drag and drop tabs with your mouse.
There is a patch pending (but not applied yet as of Vim 7.4.1054) to expand this to the GUI tabs as well:
https://groups.google.com/forum/#!msg/vim_dev/LnZVZYls1yk/fj_Gz0vhnrsJ
Split Manipulation
Ctrl+W, R (Swap top/bottom or left/right split)
Ctrl+W, T (Break out current window into a new tabview)
Ctrl+W, o (Close every window in the current tabview but the current one)
I have a two part question regarding mouse clicks on gvim.
1.) I would like to change my gvim double left mouse click into something similar to the windows environment (ie Notepad, Microsoft Word), wherein it: highlights the current word, and replaces it with whatever I type. This is akin to pressing 'cw' for changeword in vim.
2.) I would like my single mouse click to place a cursor upon the selected text and enter insert mode. Again like how a mouse normally behaves in Windows.
1) nmap <2-LeftMouse> ciw
You could use viw here, which will visually select the current word, but then you will still have to press c to replace it.
2) nmap <LeftMouse> <Leftmouse>i
Or replace the i with an a if you would prefer to append, rather than insert.
You can use behave mswin or so $VIMRUNTIME/mswin.vim so set up a lot of stuff so that it works more like a regular windows program.
The specific setting you are looking for are:
set select=mouse
this causes the mouse to start select mode instead of visual mode. Select mode causes the selection to be deleted and insert mode to be entered when a printable key is pressed.
As in Prince Goulash's answer
nmap <LeftMouse> <LeftMouse>i
will turn on a sort of click-to-type mode.
I usually:
Choose the needed file.
Open it in a tab(t character, by default).
But how I can jump back to NERDTree to open one more file in a tab?
Temporary solution I use now in my .vimrc file:
map <F10> :NERDTree /path/to/root/of/my/project
But it's not very useful to start navigation again and again from the root directory.
Ctrl-ww
This will move between open windows (so you could hop between the NERDTree window, the file you are editing and the help window, for example... just hold down Ctrl and press w twice).
Ctrl+ww cycle though all windows
Ctrl+wh takes you left a window
Ctrl+wj takes you down a window
Ctrl+wk takes you up a window
Ctrl+wl takes you right a window
NERDTree opens up in another window. That split view you're seeing? They're called windows in vim parlance. All the window commands start with CTRL-W. To move from adjacent windows that are left and right of one another, you can change focus to the window to the left of your current window with CTRL-w h, and move focus to the right with CTRL-w l. Likewise, CTRL-w j and CTRL-w k will move you between horizontally split windows (i.e., one window is above the other). There's a lot more you can do with windows as described here.
You can also use the :NERDTreeToggle command to make your tree open and close. I usually bind that do t.
If you use T instead of t there is no need to jump back because the new tab will be opened, but vim's focus will simply remain within NERDTree.
You can focus on a split window using # ctrl-ww.
for example, pressing:
1 ctrl-ww
would focus on the first window, usually being NERDTree.
Since it's not mentioned and it's really helpful:
ctrl-wp
which I memorize as go to the previously selected window.
It works as a there and back command. After having opened a new file from the tree in a new window press ctrl-wp to switch back to the NERDTree and use it again to return to your previous window.
PS: it is worth to mention that ctrl-wp is actually documented as go to the preview window (see: :help preview-window and :help ctrl-w).
It is also the only keystroke which works to switch inside and explore the COC preview documentation window.
ctrl-ww Could be useful when you have limited tabs open. But could get annoying when you have too many tabs open.
I type in :NERDTree again to get the focus back on NERDTree tab instantly wherever my cursor's focus is. Hope that helps
The top answers here mention using T to open a file in a new tab silently, or Ctrl+WW to hop back to nerd-tree window after file is opened normally.
IF WORKING WITH BUFFERS: use go to open a file in a new buffer, silently, meaning your focus will remain on nerd-tree.
Use this to open multiple files fast :)
You can change the tabs by ctrl-pgup and ctrl-pgdown. On that tab you came from the NERDTree is still selected and you can open another tab.
In more recent versions of NERDTree you can use the command :NERDTreeFocus, which will move focus to the NERDTree window.
gt = next Tap
gT = previous Tab
if you want you can enable the mouse support editing ~/.vimrc file.
put set mouse=a
after that you enable files click in NERDTree.
All The Shortcuts And Functionality is At
press CTRL-?