Python neovim.command() Examples

The following are 26 code examples of neovim.command(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module neovim , or try the search function .
Example #1
Source File: __init__.py    From aerojump.nvim with MIT License 6 votes vote down vote up
def AerojumpExit(self, args, range):
        """ Exit aerojump without moving the selection

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.nvim.command('stopinsert')
        self.nvim.current.buffer = self.og_buf
        self.nvim.command('bwipeout %s' % self.aerojump_buf_num)
        self.nvim.command('bwipeout %s' % self.filt_buf_num)
        if self.uses_tabs:
            self.nvim.command('tabclose')
        # Restore original position
        self.nvim.current.window.cursor = self.top_pos
        self.nvim.command('normal! zt')
        self.nvim.current.window.cursor = self.og_pos 
Example #2
Source File: __init__.py    From aerojump.nvim with MIT License 6 votes vote down vote up
def AerojumpSelPrev(self, args, range):
        """ Select the previous match

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_match_prev()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
Example #3
Source File: __init__.py    From aerojump.nvim with MIT License 6 votes vote down vote up
def AerojumpSelNext(self, args, range):
        """ Select the next match

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_match_next()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
Example #4
Source File: __init__.py    From aerojump.nvim with MIT License 6 votes vote down vote up
def AerojumpDown(self, args, range):
        """ Go down one line of matches

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_line_down()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
Example #5
Source File: __init__.py    From aerojump.nvim with MIT License 6 votes vote down vote up
def AerojumpUp(self, args, range):
        """ Go up one line of matches

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.aj.cursor_line_up()
        # TODO: [Performance] Incremental update of highlights?
        self.__update_highlights(self.aj.get_highlights())
        self.main_win.cursor = self.aj.get_cursor()

        self.nvim.command('startinsert')
        self.nvim.command('normal! $') 
Example #6
Source File: vim_pudb.py    From pudb.vim with MIT License 6 votes vote down vote up
def place_sign(self, buffname, lineno):
        """place_sign
        Places a new sign on the buffer and registers it as a breakpoint with
        pudb
        :param buffname:
        :param lineno:
        """
        # do nothing without a line number
        if not lineno:
            return None
        # don't place it if it has already been placed
        if self.has_breakpoint(buffname, lineno):
            return self.pudbbp(buffname, lineno)
        signcmd = "sign place {} line={} name={} file={}".format(
            signid(buffname, lineno),
            lineno,
            self.sgnname(),
            buffname)
        __logger__.debug(signcmd)
        self.nvim.command(signcmd)
        if buffname in self._bps_placed:
            self._bps_placed[buffname].append(signid(buffname, lineno))
        else:
            self._bps_placed[buffname] = [signid(buffname, lineno)]
        return self.pudbbp(buffname, lineno) 
Example #7
Source File: vim_pudb.py    From pudb.vim with MIT License 6 votes vote down vote up
def remove_sign(self, buffname, lineno):
        """remove_sign
        removes the sign from the buffer and the breakpoint from pudb
        :param buffname:
        :param bpt:
        """
        if not self.has_breakpoint(buffname, lineno):
            return
        __logger__.info(
            'removing sign %d at line: %d',
            signid(buffname, lineno),
            lineno)
        vimmsg = 'sign unplace {} file={}'.format(
            signid(buffname, lineno),
            buffname)
        __logger__.debug(vimmsg)
        self.nvim.command(vimmsg)
        self._bps_placed[buffname].pop(
            self._bps_placed[buffname].index(
                signid(buffname, lineno))) 
Example #8
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def update_breakpoints_cmd(self, buffname=None):
        '''update_breakpoints_cmd
        expose the UpdateBreakPoints command
        :param buffname:
        '''
        if not buffname:
            buffname = self.cbname()
        __logger__.debug('refreshing breakpoints for file: %s', (buffname))
        # remove existing signs if any
        self.update_buffer(buffname)

    # set sync so that the current buffer can't change until we are done 
Example #9
Source File: __init__.py    From aerojump.nvim with MIT License 5 votes vote down vote up
def AerojumpShowLog(self, args, range):
        """ Show the aerojump log

        Parameters:
            n/a

        Returns:
            n/a
        """
        self.nvim.command('e Aerojump_log')
        self.nvim.command('setlocal buftype=nofile')
        self.nvim.command('setlocal filetype=aerojump_log')
        self.nvim.current.buffer.append(self.logstr)
        self.nvim.current.buffer.append('== Aerojump log ==')
        self.nvim.current.buffer.extend(self.aj.get_log()) 
Example #10
Source File: __init__.py    From aerojump.nvim with MIT License 5 votes vote down vote up
def __create_keymap(self):
        keymaps = self.default_keymaps.copy()
        keymaps.update(self.nvim.vars.get("aerojump_keymaps", {}))
        for k in keymaps:
            self.nvim.command(f"inoremap <buffer> {k} <ESC>:{keymaps[k]}<CR>") 
Example #11
Source File: __init__.py    From aerojump.nvim with MIT License 5 votes vote down vote up
def __set_top_pos(self, top_pos):
        old_win = self.nvim.current.window
        self.nvim.current.window = self.main_win
        self.nvim.current.window.cursor = top_pos
        self.nvim.command('normal! zt')
        self.nvim.current.window = old_win 
Example #12
Source File: __init__.py    From aerojump.nvim with MIT License 5 votes vote down vote up
def __open_aerojump_filter_buf(self, filter_string=''):
        if self.uses_tabs:
            self.nvim.command('tabedit AerojumpFilter')
        else:
            self.nvim.command('edit AerojumpFilter')
        self.nvim.command('setlocal buftype=nofile')
        self.nvim.command('setlocal filetype=AerojumpFilter')
        if filter_string != '':
            # TODO Idea: Maybe add some special characters
            # like regexp to enforce whole matches only?
            self.nvim.current.buffer[0] = filter_string
        self.filt_buf_num = self.nvim.current.buffer.number 
Example #13
Source File: __init__.py    From aerojump.nvim with MIT License 5 votes vote down vote up
def __open_aerojump_buf(self):
        self.nvim.command('silent split Aerojump')
        self.nvim.command('silent setlocal buftype=nofile')
        self.nvim.command('silent setlocal filetype=aerojump')
        # Fix filetype in order to keep old syntax
        self.nvim.command('silent set filetype='+self.ft+'.aerojump')
        self.aerojump_buf_num = self.nvim.current.buffer.number 
Example #14
Source File: __init__.py    From aerojump.nvim with MIT License 5 votes vote down vote up
def get_output_of_vim_cmd(nvim, cmd):
    """ Utility function to get the current output
        of a vim command

    Parameters:
        nvim: Neovim instance
        cmd: Command to fetch output from

    Returns:
        n/a
    """
    nvim.command('redir @a')
    nvim.command(cmd)
    nvim.command('redir END')
    return nvim.eval('@a').strip('\n') 
Example #15
Source File: ensime.py    From ensime-vim with MIT License 5 votes vote down vote up
def au_buf_enter(self, *args, **kwargs):
        # Workaround for issue #388
        # TODO: remove it once the Neovim fix has landed in a stable release
        # (Github issue to do that: #390)
        self._vim.command('call EnTick()')
        super(NeovimEnsime, self).au_buf_enter(*args, **kwargs) 
Example #16
Source File: tandem_neovim.py    From tandem with Apache License 2.0 5 votes vote down vote up
def session(self, args):
        if not plugin.is_active:
            self._vim.async_call(
                lambda: self._vim.command('echom "No instance running."'),
            )
            return
        self._vim.async_call(
            lambda: self._vim.command('echom "Session ID: {}"'
                                      .format(self._session_id)),
        ) 
Example #17
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def launchdebugtab(self):
        # if necessary, get the virtual env setup
        # autocmd FileType python nnoremap <silent> <leader>td :tabnew
        # term://source ${HOME}/.virtualenvs/$(cat .dbve)/bin/activate
        # && python -mpudb %<CR>:startinsert<CR>
        new_term_tab_cmd = 'tabnew term://{} -m pudb.run {}'.format(
            self.launcher(),
            self.entrypoint())
        __logger__.info('Starting debug tab with command:\n    {}'.format(
            new_term_tab_cmd))
        self.nvim.command(new_term_tab_cmd)
        # we have to wait for the terminal to be opened...
        self.nvim.command('startinsert') 
Example #18
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def clear_all_bps(self, buffname=None):
        """clear_all_bps
        removes all signs from the buffer and all breakpoints from pudb
        :param buffname:
        """
        if not buffname:
            buffname = self.cbname()
        self.nvim.command('sign unplace * file={}'.format(buffname))
        self._bps_placed[buffname] = []
        __logger__.debug(
            'there should be no signs for this buffer:\n    %s',
            pprint.pformat(self._bps_placed[buffname]))
        self.update_pudb_breakpoints(buffname) 
Example #19
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def set_entrypoint(self, entrypoint):
        self.nvim.command("let g:pudb_entry_point='{}'".format(entrypoint))

    # @property 
Example #20
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def set_launcher(self, launcher):
        self.nvim.command("let g:pudb_python_launcher='{}'".format(launcher))

    # @property 
Example #21
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def set_lgroup(self, hlgroup):
        self.nvim.command("let g:pudb_highlight_group='{}'".format(hlgroup))

    # @property 
Example #22
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def set_bpsymbol(self, bpsymbol):
        self.nvim.command("let g:pudb_breakpoint_symbol='{}'".format(bpsymbol))

    # @property 
Example #23
Source File: vim_pudb.py    From pudb.vim with MIT License 5 votes vote down vote up
def set_sgnname(self, sgnname):
        self.nvim.command("let g:pudb_sign_name='{}'".format(sgnname))

    # @property 
Example #24
Source File: __init__.py    From vim-matlab with Mozilla Public License 2.0 5 votes vote down vote up
def fix_name(self, args):
        curr_file = vim_helper.get_current_file_path()
        modified = os.path.getmtime(curr_file)
        changed = os.path.getctime(curr_file)
        head_lines = self.vim.current.buffer[:100]
        head_string = '\n'.join(head_lines)

        def get_basename_ext(path):
            filename = os.path.basename(path)
            return os.path.splitext(filename)

        def rename_function(name):
            new_head = self.function_name_pattern.sub(
                r"\1{}\3".format(name), head_string).split('\n')
            for i, line in enumerate(new_head):
                if line != head_lines[i]:
                    self.vim.current.buffer[i] = line

        basename, ext = get_basename_ext(curr_file)

        if len(args) > 0:
            new_name, new_ext = get_basename_ext(args[0])
            new_ext = new_ext if len(new_ext) > 0 else ext
            rename_function(new_name)
            self.vim.command("Rename {}{}".format(new_name, new_ext))
            return

        if vim_helper.is_current_buffer_modified() or changed != modified:
            match = self.function_name_pattern.search(head_string)
            if match is None:
                return
            function_name = match.group(2)
            self.vim.command("Rename {}{}".format(function_name, ext))
        else:
            rename_function(basename) 
Example #25
Source File: __init__.py    From vim-matlab with Mozilla Public License 2.0 5 votes vote down vote up
def open_temp_matlab_script(self, args):
        dirname = os.path.join(os.path.expanduser('~'), '.vim-matlab/scratch/')
        if not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except OSError as ex:
                # In case of a race condition
                if ex.errno != errno.EEXIST:
                    raise
        timestamp = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
        if len(args) > 0:
            filename = "{}_{}.m".format(timestamp, args[0])
        else:
            filename = "{}.m".format(timestamp)
        self.vim.command('edit {}'.format(os.path.join(dirname, filename))) 
Example #26
Source File: tandem_neovim.py    From tandem with Apache License 2.0 5 votes vote down vote up
def _handle_message(self, message):
        if isinstance(message, m.WriteRequest):
            self._message = message
            self._text_applied.clear()
            self._vim.async_call(
                lambda: self._vim.funcs.TandemHandleWriteRequest(async=True),
            )
            self._text_applied.wait()
        elif isinstance(message, m.SessionInfo):
            self._session_id = message.session_id
            self._vim.async_call(
                lambda: self._vim.command('echom "Session ID: {}"'
                                          .format(message.session_id)),
            )