Vim Send Alt-F10 Keys at Startup - linux

I need to send Alt-F10 key combination at vim startup. I am on Linux Mint. I tried: au GUIEnter * call feedkeys("\<M-F10>").
But that didn't work.
Thanks.

You are probably looking for the :simalt command.
VimFAQ 33.3. - 'How do I start GUI Vim in a maximized window always?' shows a example similar to what you have attempted:
autocmd GUIEnter * simalt ~x
Edit:
The simalt command is only available for ms-windows, so it will only display an error message on Linux.
You can make gVim become similar to a maximized window by using large values for 'lines' and 'columns' options, by adding the following to your vimrc:
set columns=1000
set lines=100
You could change to maximized state by using feedkeys, as you mentioned you have tried. On Linux Mint with LXDE the command call feedkeys("\<M-F10>") displays gVim 'File' menu: 'Open, Save, Print, Exit, etc'. Here the command to open the menu and hit 'Maximize' is Alt+space,x. But unfortunately it is not easy to send <A-space> from gVim, similar to what is discussed on this post. If your windows manager also relays on Alt+space you should try to change its configuration (for LXDE it is on ~/.config/openbox/lxde-rc.xml) to use some other key combination and then send it through feedkeys().
A third option is the shell plugin, which provides a :Maximize command.

Related

pageup and pagedown does not work in vim using konsole

I have just recently moved to SLES12 from SLES11
Using vim in SLES11 pageup and page down worked perfectly while SLES12 it is not. (in gvim - it does work)
I am trying several solutions written in others threads like without success :(
map <CTRL-V><CTRL-PAGEUP> :tabp<CR>
map <C-PageUp> :echo "hello"<CR>
map ^[[5^ :echo "hello"<CR>
I think it might related to the fact of the bindkeys of the terminals as one of the threads mention- but I do not find which one is related to pageup/down.
any clue?
This is a problem with the way your terminal is set up.
As you have stated you are using Konsole, you can check the settings by right clicking on an open terminal window and selecting Edit Current Profile:
That should open up another window like:
On this screen select the keyboard option on the left and check your keyboards. For a quick win you can try changing the keybinding or reset to default. If that isn't enough you will need to go into the keybinding and ensure the PgUp is producing the expected code: ^[[5~. Doing so should be fairly straightforward.

Can I send commands to an already open tmux session?

I've started using vim a couple of months ago and I'm loving it. I mostly code on a vim pane (using iTerm2 on OS X) and I keep an ipython console running inside a screen session on another pane. I've managed to find a way to send lines of code or even the whole script from vim to execute on the ipython console, but I don't know if this is possible with tmux. Everyone else is telling me to change from screen to tmux (which actually seems like good advice, in light of tmux's features) but before taking the leap I wanted to make sure this is possible.
Based on the answer/tip by byaruhaf, I've managed to send commands to an already open tmux session. I thought I'll add here a small how-to so that everyone else can take advantage of this.
I installed vim-tmux-runner and edited my .vimrc file in the following way:
let g:vtr_filteype_runner_overrides = {
\ 'python': '%run {file}' }
augroup Pythonic
autocmd!
autocmd FileType python nmap <leader>l :VtrSendFile<CR>
autocmd Filetype python xmap <leader>l :VtrSendLinesToRunner<CR>
augroup END
Let me explain this a bit. The first autocmd line allows one to hit <leader>l in NORMAL mode and have vim-tmux-runner send '%run {filename}' to a tmux session in which an ipython session is running (this is my workflow). Note that the 'let' line on top is the one which sets the command to be run by VtrSendFile to be '%run'. (On that same line, please note that "filteype" is not a typo, it works like this and not with "filetype").
The second autocmd line allows one to select a few lines in vim and, while in VISUAL MODE hit <leader>l and send those lines to a tmux ipython session.
As pasting code in ipython can be tricky, there are other options that might be of use in this case, just check the docs on vim-tmux-runner for more info.
Thanks byaruhaf for the great tip.
Yes it is possible to send commands to an already open tmux session.
i recommend you use this plugin vim-tmux-runner . you can see this Vim & Tmux video for a demo of the plugin by Jack Franklin

How to emulate <F11> press on startup in vimrc

<F11> makes it full screen in ubuntu (I changed the settings and chose show the menus for a window In the window's title bar rather than in the menu bar) and hides the global menu panel (at the top with the battery and wifi symbols). I didn't want to press <F11> every single time I opened gvim so what do I have to write in .vimrc for this?
The mappings and Vimscript commands that you can put into your ~/.vimrc are only for scripting Vim itself; you cannot directly control your environment with it. The only way is through launching an external command (via :! or :call system(...), for example wmctrl with the right arguments. Alternatively, you could modify the shortcut / command that launches GVIM to include this maximization, so you don't need to "break out" from inside Vim.
I'm using the :Fullscreen command of the shell.vim - Improved integration between Vim and its environment plugin; it works well on Windows and Gnome. You can launch that automatically by putting Fullscreen into your ~/.gvimrc.

How to maximize vim's windows on startup with .vimrc?

Can I add something to my .vimrc or .gvimrc to make gvim always start up in a maximized GUI window?
It looks like if you're using Windows, it's as easy as adding this line into your .vimrc:
au GUIEnter * simalt ~x
(type :help maximize or :help win16-maximized for details)
Apparently there's no standard way to do it on other platforms from your vimrc. The simplest trick without knowing which platform is to add
set lines=999 columns=999
to your .gvimrc. There are a few other tricks that can help at the Vim Wiki's Maximize or set initial window size page.
On linux with most window managers and wmctrl installed you can maximize Gvim using the following command:
call system('wmctrl -i -b add,maximized_vert,maximized_horz -r '.v:windowid)
. Note: I am intentionally avoiding -b add,fullscreen mentioned in man wmctrl as it means different thing: at least in fluxbox that means that from now on this desktop you can see only either gvim or something else at a time, not both, and gvim is left without window decorations (not that I really care about them). E.g. if you popup yakuake* gvim disappears until yakuake hides.
* terminal emulator, pops like console in some FPS games
You can set the initial size of the Vim Window by adding the following line to ~/.vimrc :
set lines=50 columns=100(just an example)
I set my vim to my screen resolution, i.e. set lines=768 columns=1366. Now my Vim editor automatically launches in fullscreen.

How do I run a terminal inside of Vim?

I am used to Emacs, but I am trying out Vim to see which one I like better.
One thing that I like about Emacs is the ability to run a terminal inside Emacs. Is this possible inside of Vim? I know that you can execute commands from Vim, but I would like to be able to run a terminal inside of a tab.
Outdated from August 2011
Check out Conque Shell (also on GitHub). Lets you run any interactive program inside vim, not just a shell.
I'm not sure exactly what you're trying to achieve (I've never used Emacs), but you can run commands in Vim by typing:
:! somecommand [ENTER]
And if you want to type in several commands, or play around in a shell for a while, you can always use:
:! bash (or your favourite shell) [ENTER]
Once the command or shell terminates, you'll be given the option to press Enter to return to your editor window
Vim is intentionally lightweight and lacking in the ability to do non-editorish type things, just as running a full-blown shell inside a Vim pane/tab, but as mentioned above there are third-party addons such as vim-shell that allow you to do that sort of thing.
Typically if I want to switch between Vim and my shell (Bash), I just hit CTRL+Z to pause the Vim process, play around in my shell, then type 'fg' when I want to go back to Vim - keeping my editor and my shell nice and separate.
Updated answer (11 years later...):
I would recommend using tmux instead of screen as suggested in the original answer below, if you choose to use that solution.
Vim 8.1 now has a built in terminal that can be opened with the :term command. This provides much more complete integration with the rest of the Vim features.
I would definitely recommend screen for something like this. Vim is a text editor, not a shell.
I would use Ctrl+AS to split the current window horizontally, or in Ubuntu's screen and other patched versions, you can use Ctrl+A|(pipe) to split vertically. Then use Ctrl+ATab (or equivalently on some systems, Ctrl+ACtrl+I which may be easier to type) to switch between the windows. There are other commands to change the size and arrangement of the windows.
Or a less advanced use of screen is just to open multiple full-screen windows and toggle between them. This is what I normally do, I only use the split screen feature occasionally.
The GNU Screen Survival Guide question has a number of good tips if you're unfamiliar with its use.
The way that I get around this is:
pause Vim with Ctrl + Z,
play in the terminal,
then return to exactly where you left with Vim by just typing the command fg.
If enabled in your version of Vim, a terminal can be started with the :term command.
Terminal window support was added to Vim 8. It is an optional feature that can be enabled when compiling Vim with the +terminal feature. If your version of Vim has terminal support, :echo has('terminal') will output "1".
Entering :term will place you in Terminal-Job mode, where you can use the terminal as expected.
Within Terminal-Job mode, pressing Ctrl-W N or Ctrl-\ Ctrl-N switches the mode to Terminal-Normal, which allows the cursor to be moved and commands to be ran similarly to Vim's Normal mode. To switch back to Terminal-Job mode, press i.
Other answers mention similar functionality in Neovim.
:sh then Ctrl+D to get back in (bash)
Update:
You could map Ctrl+D in vim to run :sh, which allows you to toggle between bash and vim quickly.
noremap <C-d> :sh<cr>
The main new feature of Vim 8.1 is support for running a terminal in a Vim window.
:term will open the terminal in another window inside Vim.
:term
Added in Vim 8.1.
Keep in mind that whenever a terminal window is active, most keystrokes will simply be passed to the terminal instead of having their usual functions. Ctrl-W and its subcommands are the main exception. To send a literal ^W input to the terminal, press Ctrl-W .. You can also open the Vim : command line by pressing Ctrl-W :. The other Ctrl-W commands work as normal, so managing windows works the same no matter what type of window is currently selected.
Eventually a native :terminal command was added to vim in 2017.
Here is an excerpt from the :terminal readme:
This feature is for running a terminal emulator in a Vim window. A
job can be started connected to the terminal emulator. For example, to
run a shell:
:term bash
Or to run build command:
:term make myprogram
The job runs asynchronously from Vim, the window will be updated to
show output from the job, also while editing in another window.
This question is rather old, but for those finding it, there's a new possible solution: Neovim contains a full-fledged, first-class terminal emulator, which does exactly what ConqueTerm tried to. Simply run :term <your command here>.
<C-\><C-n> will exit term mode back to normal-mode. If you're like me and prefer that escape still exit term mode, you can add this to your nvimrc:
tnoremap <ESC><ESC> <C-\><C-N>
And then hitting ESC twice will exit terminal mode back to normal-mode, so you can manipulate the buffer that the still-running command is writing to.
Though keep in mind, as nvim is under heavy development at the time I'm posting this answer, another way to exit terminal mode may be added. As Ctrl+\Ctrl+n switches to normal mode from almost any mode, I don't expect that this answer will become wrong, but be aware that if it doesn't work, this answer might be out of date.
https://github.com/neovim/neovim
I know that I'm not directly answering the question, but I think it's a
good approach. Nobody has mentioned tmux (or at least not as a
standalone answer). Tmux is a terminal multiplexor like screen. Most
stuff can be made in both multiplexors, but afaik tmux it's more easily
to configure. Also tmux right now is being more actively developed than
screen and there's quite a big ecosystem around it, like tools that help
the configuration, ecc.
Also for vim, there's another plugin: ViMUX, that helps a lot in
the interaction between both tools. You can call commands with:
:call VimuxRunCommand("ls")
That command creates a small horizontal split below the current pane vim
is in.
It can also let you run from a prompt in case you don't want to run the
whole command:
<Leader>vp :VimuxPromptCommand<CR>
As it weren't enought, there are at least 6 'platform specific plugins':
vim-vroom: runner for rspec, cucumber and test/unit; vimux support via g:vroom_use_vimux
vimux-ruby-test: a set of commands to easily run ruby tests
vimux-cucumber: run Cucumber Features through Vimux
vim-turbux: Turbo Ruby testing with tmux
vimux-pyutils: A set of functions for vimux that allow to run code blocks in ipython
vimux-nose-test: Run nose tests in vimux
Here is a nice "use case": Tests on demand using Vimux and Turbux with Spork and Guard
Someone already suggested https://github.com/Shougo/vimshell.vim, but they didn't mention why. Consequently, when I came away from this question I wasted a lot of other time trying the other (much higher ranked) options.
Shougo/vimshell is the answer. Here's why:
In addition to being a terminal emulator, VimShell allows you to navigate through terminal output in normal and visual mode. Thus, if a command you run results in output that you'd like to copy and paste using the keyboard only...VimShell covers this.
None of the other options mentioned, including the :terminal command in NeoVim do this. Neovim's :terminal comes close, but falls short in at least the following ways as of 2/18/2017:
Moves the cursor to the end of the buffer, instead of at the last keeping it in the same spot like VimShell does. Huge waste of time.
Doesn't support modifiable = 1 see a discussion on this at Github, so helpful plugins like vim-easymotion can't be used.
Doesn't support the display of line numbers like Vimshell does.
Don't waste time on the other options, including Neovim's :terminal. Go with VimShell.
It's possible to open a new tab with a terminal in vim since 2017 as #fjardon said:
Just type: :terminal. It will open a tab by default above your current tab.
If you want it to open in another place you can try the following options:
:below terminal : open the terminal below current tab.
:below vertical terminal : open the terminal always vertically to the right.
You can play with these until you find what you like. After this you can set a map in your .vimrc configuration file, for me, I use:
nmap <leader>tt :below vertical terminal<CR>
This way I can type <space>tt (space my leader key) to open it quickly.
As a side note:
You can switch between your tabs (terminal and other buffers) with Ctrl+W Ctrl+W.
You can enter an editable mode in your terminal if you want to copy your commands with Ctrl+W N and go to normal terminal mode with i or a.
Cheers!
You might want to take a look at the :sh command (see :help sh in Vim).
Various commands
No, you cannot:
http://vimdoc.sourceforge.net/htmldoc/tips.html#shell-window
By far, I have tried a lot of solutions mentioned here, what I really wanted is to keep the terminal open while coding a similar experience in VsCode. Then I came across this solution which is working perfectly for me.
Before Installing:
I am using Nvim 0.5 but I think it can work for any version and checked also on vim
I am using macOS Catalina Version 10.15.7
Setup your integrated terminal
Step -1-
Create a script with the name myQuickTerminal.vim or whatever name you want.
Put the following script
"==============================================================================
"
" ▒█▀▀█ █░░█ ░▀░ █▀▀ █░█   ▀▀█▀▀ █▀▀ █▀▀█ █▀▄▀█ ░▀░ █▀▀▄ █▀▀█ █░░
" ▒█░▒█ █░░█ ▀█▀ █░░ █▀▄   ░▒█░░ █▀▀ █▄▄▀ █░▀░█ ▀█▀ █░░█ █▄▄█ █░░
" ░▀▀█▄ ░▀▀▀ ▀▀▀ ▀▀▀ ▀░▀   ░▒█░░ ▀▀▀ ▀░▀▀ ▀░░░▀ ▀▀▀ ▀░░▀ ▀░░▀ ▀▀▀
"
"==============================================================================
" " This is a script that will trigger a terminal quickly than the FloatTerminal
" open new split panes to right and below
"link: https://betterprogramming.pub/setting-up-neovim-for-web-development-in-2020-d800de3efacd
"==============================================================================
set splitright
set splitbelow
" turn terminal to normal mode with escape
tnoremap <Esc> <C-\><C-n>
" start terminal in insert mode
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
" open terminal on ctrl+n
function! OpenTerminal()
split term://zsh
resize 10
endfunction
nnoremap <leader> n :call OpenTerminal()<CR>
NOTE: if you want to run bash instead of zsh for a particular reason then replace zsh with bash.
Step -2-
Lets source it, put this in init.vim for neovim or `.vimrc' for vim
source $HOME/.config/nvim/modules/mySpecialScripts/myQuickTerminal.vim
This will be preloaded ahead as you save and resource it, you can use source $MYVIMRC for quick reloading the init.vim file.
Step -3-
I mapped as you can see in the script n to open a terminal in a new pane, my is the (Space bar) and once I click (space + n) a terminal will be triggered and I will enjoy writing my code while the terminal is opened.
To quit insert mode in the terminal, press Esc.
Now, to switch to the code editor pane, use CTRL+w w. This shortcut can get annoying once you have more than two panels open, so I added the following shortcuts too.
I mapped these too for quick jumping among opened panes, use these
" Better window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
Optional
If you want your terminal to exit the current buffer with key. you can use
tnoremap <Esc> <C-\><C-n>:q!<CR>
But since I want to switch in between several buffers I use without close the terminal I use instead:
tnoremap <Leader><Esc> <C-\><C-n>:q!<CR>
Final results
Reference:
https://betterprogramming.pub/setting-up-neovim-for-web-development-in-2020-d800de3efacd
Only way I know of is by using vim-shell, a third-party patch.
I use this now, you may can try. VimShell
Split the screen and run command term ++curwin to run the terminal inside the Vim buffer. Following command does both and worked for me:
:bo 10sp | term ++curwin
If you are interested in quick answer, here is it: :vert term. It will split your screen vertically and open up terminal.
Try vterm, which is a pretty much full feature shell inside vim. It is slightly buggy with its history and clear functions, and still in development, but it still is pretty good
Assuming your version of vim supports +term command first, set shell for vim to use in one command (e.g. set=/usr/bin/zsh), and then run the command +term (i.e. bo 15vs +term). you may have to do some additional maneuvering of your windows (i.e. deleting one and rotating), but you'll have your terminal.
With vim 8.1.3741, just type :terminal to start a terminal inside of vim.
Try map :nnoremap ]t :terminal<CR> to do that quicker!
I acknowledge that I am not strictly answering your question, but what has worked better for me when using Vim and Terminals in the same window is Tmux (which is kind of a "run in the background software" like, similar to screen, although this one works better with splits and tabs).
This post will help you to understand how they work together: 'Tmux and Vim — even better together'.
This way we can convert Vim into a powerful IDE

Resources